Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/ldpd * use a flag in label struct in order to deter...



details:   https://anonhg.NetBSD.org/src/rev/98a232f75b8f
branches:  trunk
changeset: 788852:98a232f75b8f
user:      kefren <kefren%NetBSD.org@localhost>
date:      Wed Jul 24 09:05:53 2013 +0000

description:
* use a flag in label struct in order to determine if we should treat the
  associated routes using RTF_HOST
* clean the mess in flush_mpls_routes that could result in accessing
  uninitialized memory

diffstat:

 usr.sbin/ldpd/label.c          |  12 +++++++-----
 usr.sbin/ldpd/label.h          |   6 ++++--
 usr.sbin/ldpd/mpls_interface.c |  23 ++++-------------------
 usr.sbin/ldpd/mpls_routes.c    |  31 ++++++++++++++++++++-----------
 4 files changed, 35 insertions(+), 37 deletions(-)

diffs (194 lines):

diff -r 6fc24cc7f39f -r 98a232f75b8f usr.sbin/ldpd/label.c
--- a/usr.sbin/ldpd/label.c     Wed Jul 24 07:00:16 2013 +0000
+++ b/usr.sbin/ldpd/label.c     Wed Jul 24 09:05:53 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: label.c,v 1.9 2013/07/18 11:45:36 kefren Exp $ */
+/* $NetBSD: label.c,v 1.10 2013/07/24 09:05:53 kefren Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -55,7 +55,7 @@
 struct label   *
 label_add(const union sockunion * so_dest, const union sockunion * so_pref,
          const union sockunion * so_gate, uint32_t binding,
-         const struct ldp_peer * p, uint32_t label)
+         const struct ldp_peer * p, uint32_t label, bool host)
 {
        struct label   *l;
        char    spreftmp[INET_ADDRSTRLEN];
@@ -83,6 +83,7 @@
                l->binding = get_free_local_label();
        l->p = p;
        l->label = label;
+       l->host = host;
 
        SLIST_INSERT_HEAD(&label_head, l, labels);
 
@@ -125,12 +126,13 @@
        if (readd == REATT_INET_CHANGE) {
                /* Delete the tagged route and re-add IPv4 route */
                delete_route(&l->so_dest,
-                   l->so_pref.sa.sa_len != 0 ? &l->so_pref : NULL, NO_FREESO);
+                   l->host ? NULL : &l->so_pref, NO_FREESO);
                add_route(&l->so_dest,
-                   l->so_pref.sa.sa_len != 0 ? &l->so_pref : NULL, &l->so_gate,
+                   l->host ? NULL : &l->so_pref, &l->so_gate,
                    NULL, NULL, NO_FREESO, RTM_READD);
        } else if (readd == REATT_INET_DEL)
-               delete_route(&l->so_dest, &l->so_pref, NO_FREESO);
+               delete_route(&l->so_dest, l->host ? NULL : &l->so_pref,
+                   NO_FREESO);
 
        /* Deletes the MPLS route */
        if (l->binding >= min_label)
diff -r 6fc24cc7f39f -r 98a232f75b8f usr.sbin/ldpd/label.h
--- a/usr.sbin/ldpd/label.h     Wed Jul 24 07:00:16 2013 +0000
+++ b/usr.sbin/ldpd/label.h     Wed Jul 24 09:05:53 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: label.h,v 1.6 2013/07/18 11:45:36 kefren Exp $ */
+/* $NetBSD: label.h,v 1.7 2013/07/24 09:05:53 kefren Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -51,6 +51,7 @@
 struct label {
        union sockunion so_dest, so_pref, so_gate;
        int binding, label;
+       bool host;      /* change routes using RTF_HOST */
        const struct ldp_peer *p;
        SLIST_ENTRY(label) labels;
 };
@@ -58,7 +59,8 @@
 
 void            label_init(void);
 struct label * label_add(const union sockunion *, const union sockunion *,
-         const union sockunion *, uint32_t, const struct ldp_peer *, uint32_t);
+         const union sockunion *, uint32_t, const struct ldp_peer *, uint32_t,
+         bool);
 void            label_del(struct label *);
 void            del_all_peer_labels(const struct ldp_peer*, int);
 void           label_reattach_all_peer_labels(const struct ldp_peer*, int);
diff -r 6fc24cc7f39f -r 98a232f75b8f usr.sbin/ldpd/mpls_interface.c
--- a/usr.sbin/ldpd/mpls_interface.c    Wed Jul 24 07:00:16 2013 +0000
+++ b/usr.sbin/ldpd/mpls_interface.c    Wed Jul 24 09:05:53 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mpls_interface.c,v 1.11 2013/07/18 11:45:36 kefren Exp $ */
+/* $NetBSD: mpls_interface.c,v 1.12 2013/07/24 09:05:53 kefren Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -138,24 +138,9 @@
                fatalp("Out of memory\n");
                return LDP_E_MEMORY;
        }
-/*
-       if (so_oldifa != NULL) {
-               so_ifa = malloc(sizeof(*so_ifa));
-               if (so_ifa == NULL) {
-                       free(so_dest);
-                       if (so_pref != NULL)
-                               free(so_pref);
-                       free(so_tag);
-                       free(so_nexthop);
-                       fatalp("Out of memory\n");
-                       return LDP_E_MEMORY;
-               }
-               memcpy(so_ifa, so_oldifa, so_oldifa->sa.sa_len);
-       } else
-               so_ifa = NULL;
-*/
-       if (add_route(&lab->so_dest, &lab->so_pref, &lab->so_gate, &so_ifa,
-           so_tag, NO_FREESO, RTM_CHANGE) != LDP_E_OK) {
+
+       if (add_route(&lab->so_dest, lab->host ? NULL : &lab->so_pref,
+           &lab->so_gate, &so_ifa, so_tag, NO_FREESO, RTM_CHANGE) != LDP_E_OK){
                free(so_tag);
                fatalp("[mpls_add_label]: INET route failure\n");
                return LDP_E_ROUTE_ERROR;
diff -r 6fc24cc7f39f -r 98a232f75b8f usr.sbin/ldpd/mpls_routes.c
--- a/usr.sbin/ldpd/mpls_routes.c       Wed Jul 24 07:00:16 2013 +0000
+++ b/usr.sbin/ldpd/mpls_routes.c       Wed Jul 24 09:05:53 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mpls_routes.c,v 1.19 2013/07/20 05:16:08 kefren Exp $ */
+/* $NetBSD: mpls_routes.c,v 1.20 2013/07/24 09:05:53 kefren Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -414,8 +414,10 @@
        rm.m_rtm.rtm_seq = ++rt_seq;
        if (so_pref)
                rm.m_rtm.rtm_addrs = RTA_DST | RTA_NETMASK;
-       else
+       else {
                rm.m_rtm.rtm_addrs = RTA_DST;
+               rm.m_rtm.rtm_flags |= RTF_HOST;
+       }
 
        /* destination, gateway, netmask, genmask, ifp, ifa */
 
@@ -656,7 +658,8 @@
                        /* Just add an IMPLNULL label */
                        if (so_gate == NULL)
                                label_add(so_dest, so_pref, NULL,
-                                       MPLS_LABEL_IMPLNULL, NULL, 0);
+                                       MPLS_LABEL_IMPLNULL, NULL, 0,
+                                       rg->m_rtm.rtm_flags & RTF_HOST);
                        else {
                                pm = ldp_test_mapping(&so_dest->sa,
                                         prefixlen, &so_gate->sa);
@@ -665,13 +668,15 @@
                                         * gets rewritten in mpls_add_label */
                                        lab = label_add(so_dest, so_pref,
                                            so_gate, MPLS_LABEL_IMPLNULL,
-                                           pm->peer, pm->lm->label);
+                                           pm->peer, pm->lm->label,
+                                           rg->m_rtm.rtm_flags & RTF_HOST);
                                        if (lab != NULL)
                                                mpls_add_label(lab);
                                        free(pm);
                                } else
                                        label_add(so_dest, so_pref, so_gate,
-                                           MPLS_LABEL_IMPLNULL, NULL, 0);
+                                           MPLS_LABEL_IMPLNULL, NULL, 0,
+                                           rg->m_rtm.rtm_flags & RTF_HOST);
                        }
                } else  /* We already know about this prefix */
                        fatalp("Binding already there for prefix %s/%d !\n",
@@ -885,7 +890,9 @@
                    (so_gate->sa.sa_family == AF_MPLS)) {
                        debugp("MPLS route to %s deleted.\n",
                            inet_ntoa(so_dst->sin.sin_addr));
-                       delete_route(so_dst, so_pref, NO_FREESO);
+                       delete_route(so_dst,
+                           rtmes->rtm_flags & RTF_HOST ? NULL : so_pref,
+                           NO_FREESO);
                        if (rtmes->rtm_flags & RTF_HOST)
                                free(so_pref);
                        continue;
@@ -896,7 +903,8 @@
 
                if (so_gate == NULL || so_gate->sa.sa_family == AF_INET)
                        label_add(so_dst, so_pref, so_gate,
-                           MPLS_LABEL_IMPLNULL, NULL, 0);
+                           MPLS_LABEL_IMPLNULL, NULL, 0,
+                           rtmes->rtm_flags & RTF_HOST);
 
                if (rtmes->rtm_flags & RTF_HOST)
                        free(so_pref);
@@ -955,11 +963,12 @@
                        continue;
                }
 
-               if (rtm->rtm_addrs & RTA_GATEWAY) {
-                       GETNEXT(so_gate, so_dst);
+               if ((rtm->rtm_addrs & RTA_GATEWAY) == 0)
+                       continue;
+               GETNEXT(so_gate, so_dst);
+
+               if ((rtm->rtm_flags & RTF_HOST) == 0)
                        GETNEXT(so_pref, so_gate);
-               } else
-                       GETNEXT(so_pref, so_dst);
 
                if (so_gate->sa.sa_family == AF_MPLS) {
                        if (so_dst->sa.sa_family == AF_INET)



Home | Main Index | Thread Index | Old Index