]> git.proxmox.com Git - mirror_frr.git/commitdiff
zebra: identify MPLS FTNs by route type and instance
authorRenato Westphal <renato@opensourcerouting.org>
Thu, 8 Aug 2019 16:56:39 +0000 (13:56 -0300)
committerRenato Westphal <renato@opensourcerouting.org>
Sat, 7 Sep 2019 00:06:11 +0000 (21:06 -0300)
Use the route type and instance instead of the route distance
to identify MPLS FTNs. This is a more robust approach since the
routing daemons can modify the distance of their announced routes
via configuration, which can cause inconsistencies.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
13 files changed:
ldpd/l2vpn.c
ldpd/lde.c
ldpd/lde.h
ldpd/lde_lib.c
ldpd/ldp_zebra.c
ldpd/ldpd.h
lib/zclient.c
lib/zclient.h
ospfd/ospf_sr.c
ospfd/ospf_sr.h
zebra/zapi_msg.c
zebra/zebra_mpls.c
zebra/zebra_mpls.h

index 7f2e396a7f5c849f9e41bf51133eac3bbcd076a0..b234e3ebe34f1ba3f78c8de03fd957fca911a031 100644 (file)
@@ -249,7 +249,7 @@ l2vpn_pw_init(struct l2vpn_pw *pw)
 
        l2vpn_pw_fec(pw, &fec);
        lde_kernel_insert(&fec, AF_INET, (union ldpd_addr*)&pw->lsr_id, 0, 0,
-           0, (void *)pw);
+           0, 0, (void *)pw);
        lde_kernel_update(&fec);
 }
 
@@ -260,7 +260,7 @@ l2vpn_pw_exit(struct l2vpn_pw *pw)
        struct zapi_pw   zpw;
 
        l2vpn_pw_fec(pw, &fec);
-       lde_kernel_remove(&fec, AF_INET, (union ldpd_addr*)&pw->lsr_id, 0, 0);
+       lde_kernel_remove(&fec, AF_INET, (union ldpd_addr*)&pw->lsr_id, 0, 0, 0);
        lde_kernel_update(&fec);
 
        pw2zpw(pw, &zpw);
@@ -433,7 +433,7 @@ l2vpn_recv_pw_status(struct lde_nbr *ln, struct notify_msg *nm)
        if (pw == NULL)
                return;
 
-       fnh = fec_nh_find(fn, AF_INET, (union ldpd_addr *)&ln->id, 0, 0);
+       fnh = fec_nh_find(fn, AF_INET, (union ldpd_addr *)&ln->id, 0, 0, 0);
        if (fnh == NULL)
                return;
 
@@ -482,7 +482,7 @@ l2vpn_recv_pw_status_wcard(struct lde_nbr *ln, struct notify_msg *nm)
                }
 
                fnh = fec_nh_find(fn, AF_INET, (union ldpd_addr *)&ln->id,
-                   0, 0);
+                   0, 0, 0);
                if (fnh == NULL)
                        continue;
 
index ac680b47a93230b1a7d88fffc2195a2c12dbe7ec..006d27f6abb873fbd6a1afee0c001b1b8bc0af77 100644 (file)
@@ -520,7 +520,8 @@ lde_dispatch_parent(struct thread *thread)
                        switch (imsg.hdr.type) {
                        case IMSG_NETWORK_ADD:
                                lde_kernel_insert(&fec, kr->af, &kr->nexthop,
-                                   kr->ifindex, kr->priority,
+                                   kr->ifindex, kr->route_type,
+                                   kr->route_instance,
                                    kr->flags & F_CONNECTED, NULL);
                                break;
                        case IMSG_NETWORK_UPDATE:
@@ -747,7 +748,8 @@ lde_send_change_klabel(struct fec_node *fn, struct fec_nh *fnh)
                kr.ifindex = fnh->ifindex;
                kr.local_label = fn->local_label;
                kr.remote_label = fnh->remote_label;
-               kr.priority = fnh->priority;
+               kr.route_type = fnh->route_type;
+               kr.route_instance = fnh->route_instance;
 
                lde_imsg_compose_parent(IMSG_KLABEL_CHANGE, 0, &kr,
                    sizeof(kr));
@@ -761,7 +763,8 @@ lde_send_change_klabel(struct fec_node *fn, struct fec_nh *fnh)
                kr.ifindex = fnh->ifindex;
                kr.local_label = fn->local_label;
                kr.remote_label = fnh->remote_label;
-               kr.priority = fnh->priority;
+               kr.route_type = fnh->route_type;
+               kr.route_instance = fnh->route_instance;
 
                lde_imsg_compose_parent(IMSG_KLABEL_CHANGE, 0, &kr,
                    sizeof(kr));
@@ -798,7 +801,8 @@ lde_send_delete_klabel(struct fec_node *fn, struct fec_nh *fnh)
                kr.ifindex = fnh->ifindex;
                kr.local_label = fn->local_label;
                kr.remote_label = fnh->remote_label;
-               kr.priority = fnh->priority;
+               kr.route_type = fnh->route_type;
+               kr.route_instance = fnh->route_instance;
 
                lde_imsg_compose_parent(IMSG_KLABEL_DELETE, 0, &kr,
                    sizeof(kr));
@@ -812,7 +816,8 @@ lde_send_delete_klabel(struct fec_node *fn, struct fec_nh *fnh)
                kr.ifindex = fnh->ifindex;
                kr.local_label = fn->local_label;
                kr.remote_label = fnh->remote_label;
-               kr.priority = fnh->priority;
+               kr.route_type = fnh->route_type;
+               kr.route_instance = fnh->route_instance;
 
                lde_imsg_compose_parent(IMSG_KLABEL_DELETE, 0, &kr,
                    sizeof(kr));
index 0a7d0a58fe4a1b62f1ac7f886bf75f198e70db00..ce466c16b9cd2266c70a87a15e63595f1bab9857 100644 (file)
@@ -108,7 +108,8 @@ struct fec_nh {
        union ldpd_addr          nexthop;
        ifindex_t                ifindex;
        uint32_t                 remote_label;
-       uint8_t                  priority;
+       uint8_t                  route_type;
+       unsigned short           route_instance;
        uint8_t                  flags;
 };
 #define F_FEC_NH_NEW           0x01
@@ -193,11 +194,11 @@ void               rt_dump(pid_t);
 void            fec_snap(struct lde_nbr *);
 void            fec_tree_clear(void);
 struct fec_nh  *fec_nh_find(struct fec_node *, int, union ldpd_addr *,
-                   ifindex_t, uint8_t);
+                   ifindex_t, uint8_t, unsigned short);
 void            lde_kernel_insert(struct fec *, int, union ldpd_addr *,
-                   ifindex_t, uint8_t, int, void *);
+                   ifindex_t, uint8_t, unsigned short, int, void *);
 void            lde_kernel_remove(struct fec *, int, union ldpd_addr *,
-                   ifindex_t, uint8_t);
+                   ifindex_t, uint8_t, unsigned short);
 void            lde_kernel_update(struct fec *);
 void            lde_check_mapping(struct map *, struct lde_nbr *);
 void            lde_check_request(struct map *, struct lde_nbr *);
index 0957a5455e3dfc99db93c59eba0c48a9154c1de9..eb1a6d94349bb0c42de9148945c67ad9d2091866 100644 (file)
@@ -31,7 +31,7 @@ static int             lde_nbr_is_nexthop(struct fec_node *,
 static void             fec_free(void *);
 static struct fec_node *fec_add(struct fec *fec);
 static struct fec_nh   *fec_nh_add(struct fec_node *, int, union ldpd_addr *,
-                           ifindex_t, uint8_t);
+                           ifindex_t, uint8_t, unsigned short);
 static void             fec_nh_del(struct fec_nh *);
 
 RB_GENERATE(fec_tree, fec, entry, fec_compare)
@@ -275,7 +275,7 @@ fec_add(struct fec *fec)
 
 struct fec_nh *
 fec_nh_find(struct fec_node *fn, int af, union ldpd_addr *nexthop,
-    ifindex_t ifindex, uint8_t priority)
+    ifindex_t ifindex, uint8_t route_type, unsigned short route_instance)
 {
        struct fec_nh   *fnh;
 
@@ -283,7 +283,8 @@ fec_nh_find(struct fec_node *fn, int af, union ldpd_addr *nexthop,
                if (fnh->af == af &&
                    ldp_addrcmp(af, &fnh->nexthop, nexthop) == 0 &&
                    fnh->ifindex == ifindex &&
-                   fnh->priority == priority)
+                   fnh->route_type == route_type &&
+                   fnh->route_instance == route_instance)
                        return (fnh);
 
        return (NULL);
@@ -291,7 +292,7 @@ fec_nh_find(struct fec_node *fn, int af, union ldpd_addr *nexthop,
 
 static struct fec_nh *
 fec_nh_add(struct fec_node *fn, int af, union ldpd_addr *nexthop,
-    ifindex_t ifindex, uint8_t priority)
+    ifindex_t ifindex, uint8_t route_type, unsigned short route_instance)
 {
        struct fec_nh   *fnh;
 
@@ -303,7 +304,8 @@ fec_nh_add(struct fec_node *fn, int af, union ldpd_addr *nexthop,
        fnh->nexthop = *nexthop;
        fnh->ifindex = ifindex;
        fnh->remote_label = NO_LABEL;
-       fnh->priority = priority;
+       fnh->route_type = route_type;
+       fnh->route_instance = route_instance;
        LIST_INSERT_HEAD(&fn->nexthops, fnh, entry);
 
        return (fnh);
@@ -318,7 +320,8 @@ fec_nh_del(struct fec_nh *fnh)
 
 void
 lde_kernel_insert(struct fec *fec, int af, union ldpd_addr *nexthop,
-    ifindex_t ifindex, uint8_t priority, int connected, void *data)
+    ifindex_t ifindex, uint8_t route_type, unsigned short route_instance,
+    int connected, void *data)
 {
        struct fec_node         *fn;
        struct fec_nh           *fnh;
@@ -329,9 +332,10 @@ lde_kernel_insert(struct fec *fec, int af, union ldpd_addr *nexthop,
        if (data)
                fn->data = data;
 
-       fnh = fec_nh_find(fn, af, nexthop, ifindex, priority);
+       fnh = fec_nh_find(fn, af, nexthop, ifindex, route_type, route_instance);
        if (fnh == NULL)
-               fnh = fec_nh_add(fn, af, nexthop, ifindex, priority);
+               fnh = fec_nh_add(fn, af, nexthop, ifindex, route_type,
+                   route_instance);
        fnh->flags |= F_FEC_NH_NEW;
        if (connected)
                fnh->flags |= F_FEC_NH_CONNECTED;
@@ -339,7 +343,7 @@ lde_kernel_insert(struct fec *fec, int af, union ldpd_addr *nexthop,
 
 void
 lde_kernel_remove(struct fec *fec, int af, union ldpd_addr *nexthop,
-    ifindex_t ifindex, uint8_t priority)
+    ifindex_t ifindex, uint8_t route_type, unsigned short route_instance)
 {
        struct fec_node         *fn;
        struct fec_nh           *fnh;
@@ -348,7 +352,7 @@ lde_kernel_remove(struct fec *fec, int af, union ldpd_addr *nexthop,
        if (fn == NULL)
                /* route lost */
                return;
-       fnh = fec_nh_find(fn, af, nexthop, ifindex, priority);
+       fnh = fec_nh_find(fn, af, nexthop, ifindex, route_type, route_instance);
        if (fnh == NULL)
                /* route lost */
                return;
index 04e21e8026bd7d5e86e7109d3f455cc23fb28448..be94a7e2bdf0ae09852e257e93c8acb3afa910a9 100644 (file)
@@ -136,7 +136,8 @@ ldp_zebra_send_mpls_labels(int cmd, struct kroute *kr)
                fatalx("kr_change: unknown af");
        }
        zl.ifindex = kr->ifindex;
-       zl.distance = kr->priority;
+       zl.route_type = kr->route_type;
+       zl.route_instance = kr->route_instance;
        zl.local_label = kr->local_label;
        zl.remote_label = kr->remote_label;
 
@@ -398,7 +399,8 @@ ldp_zebra_read_route(ZAPI_CALLBACK_ARGS)
                break;
        }
        kr.prefixlen = api.prefix.prefixlen;
-       kr.priority = api.distance;
+       kr.route_type = api.type;
+       kr.route_instance = api.instance;
 
        switch (api.type) {
        case ZEBRA_ROUTE_CONNECT:
index 91135055817fa1cb8b477383b554bfe2ef1c1888..bd7562e5ad5b16b070a778a2165615d59eb1e4b0 100644 (file)
@@ -543,7 +543,8 @@ struct kroute {
        uint32_t                 local_label;
        uint32_t                 remote_label;
        unsigned short           ifindex;
-       uint8_t                  priority;
+       uint8_t                  route_type;
+       uint8_t                  route_instance;
        uint16_t                 flags;
 };
 
index 81f0b81f62b3c40c1b37aae736df8a4ee41c8f19..3e2c0b24d71214e799761e90d9a924ae7b4ba1f1 100644 (file)
@@ -2479,7 +2479,8 @@ int zapi_labels_encode(struct stream *s, int cmd, struct zapi_labels *zl)
                return -1;
        }
        stream_putl(s, zl->ifindex);
-       stream_putc(s, zl->distance);
+       stream_putc(s, zl->route_type);
+       stream_putw(s, zl->route_instance);
        stream_putl(s, zl->local_label);
        stream_putl(s, zl->remote_label);
 
@@ -2528,7 +2529,8 @@ int zapi_labels_decode(struct stream *s, struct zapi_labels *zl)
                return -1;
        }
        STREAM_GETL(s, zl->ifindex);
-       STREAM_GETC(s, zl->distance);
+       STREAM_GETC(s, zl->route_type);
+       STREAM_GETW(s, zl->route_instance);
        STREAM_GETL(s, zl->local_label);
        STREAM_GETL(s, zl->remote_label);
 
index e665635a8a332326fa159be2c70c827a42c20f2e..a3238a91617190925e30a2501e42de13f6ad165a 100644 (file)
@@ -400,7 +400,8 @@ struct zapi_labels {
        struct prefix prefix;
        union g_addr nexthop;
        ifindex_t ifindex;
-       uint8_t distance;
+       uint8_t route_type;
+       unsigned short route_instance;
        mpls_label_t local_label;
        mpls_label_t remote_label;
 };
index a361d17817b2d6a95cd5db16d31364e82e4dc679..9029eca2b2de5f777f4eee3d1ee3312a10414162 100644 (file)
@@ -623,7 +623,8 @@ static int ospf_zebra_send_mpls_labels(int cmd, struct sr_nhlfe nhlfe)
        zl.prefix.u.prefix4 = nhlfe.prefv4.prefix;
        zl.nexthop.ipv4 = nhlfe.nexthop;
        zl.ifindex = nhlfe.ifindex;
-       zl.distance = OSPF_SR_PRIORITY_DEFAULT;
+       zl.route_type = ZEBRA_ROUTE_OSPF;
+       zl.route_instance = 0;
        zl.local_label = nhlfe.label_in;
        zl.remote_label = nhlfe.label_out;
 
index 4d3f5f441a902c0587d6f639e29c14bd9a461532..df923e970fa1ffc8a196bbc942cb0318ee2f9c25 100644 (file)
@@ -27,9 +27,6 @@
 #ifndef _FRR_OSPF_SR_H
 #define _FRR_OSPF_SR_H
 
-/* Default Route priority for OSPF Segment Routing */
-#define OSPF_SR_PRIORITY_DEFAULT       10
-
 /* macros and constants for segment routing */
 #define SET_RANGE_SIZE_MASK             0xffffff00
 #define GET_RANGE_SIZE_MASK             0x00ffffff
index 6915d84c0d2ac7ff2b696dddd8d4eeb3db0c35bd..15ff4a8b97ccfd7db73ecdbd6b12da4e5149d9ec 100644 (file)
@@ -1788,14 +1788,14 @@ static void zread_mpls_labels(ZAPI_HANDLER_ARGS)
                mpls_lsp_install(zvrf, zl.type, zl.local_label, zl.remote_label,
                                 gtype, &zl.nexthop, zl.ifindex);
                mpls_ftn_update(1, zvrf, zl.type, &zl.prefix, gtype,
-                               &zl.nexthop, zl.ifindex, zl.distance,
-                               zl.remote_label);
+                               &zl.nexthop, zl.ifindex, zl.route_type,
+                               zl.route_instance, zl.remote_label);
        } else if (hdr->command == ZEBRA_MPLS_LABELS_DELETE) {
                mpls_lsp_uninstall(zvrf, zl.type, zl.local_label, gtype,
                                   &zl.nexthop, zl.ifindex);
                mpls_ftn_update(0, zvrf, zl.type, &zl.prefix, gtype,
-                               &zl.nexthop, zl.ifindex, zl.distance,
-                               zl.remote_label);
+                               &zl.nexthop, zl.ifindex, zl.route_type,
+                               zl.route_instance, zl.remote_label);
        }
 }
 
index 5214f1f22d26cb8a7613bdc6b4caa3f4ad8b5204..897c525949dbf0338af74279c20b43088b1ba409 100644 (file)
@@ -2542,8 +2542,8 @@ static bool mpls_ftn_update_nexthop(int add, struct nexthop *nexthop,
  */
 int mpls_ftn_update(int add, struct zebra_vrf *zvrf, enum lsp_types_t type,
                    struct prefix *prefix, enum nexthop_types_t gtype,
-                   union g_addr *gate, ifindex_t ifindex, uint8_t distance,
-                   mpls_label_t out_label)
+                   union g_addr *gate, ifindex_t ifindex, uint8_t route_type,
+                   unsigned short route_instance, mpls_label_t out_label)
 {
        struct route_table *table;
        struct route_node *rn;
@@ -2562,7 +2562,7 @@ int mpls_ftn_update(int add, struct zebra_vrf *zvrf, enum lsp_types_t type,
        RNODE_FOREACH_RE (rn, re) {
                if (CHECK_FLAG(re->status, ROUTE_ENTRY_REMOVED))
                        continue;
-               if (re->distance == distance)
+               if (re->type == route_type && re->instance == route_instance)
                        break;
        }
 
index d983221cb533fbda2019132e8a0558aefd7adbcd..506b51a5360dea33816eb4f1c7070224a9023f7b 100644 (file)
@@ -269,8 +269,8 @@ void zebra_mpls_print_fec(struct vty *vty, struct zebra_vrf *zvrf,
  */
 int mpls_ftn_update(int add, struct zebra_vrf *zvrf, enum lsp_types_t type,
                    struct prefix *prefix, enum nexthop_types_t gtype,
-                   union g_addr *gate, ifindex_t ifindex, uint8_t distance,
-                   mpls_label_t out_label);
+                   union g_addr *gate, ifindex_t ifindex, uint8_t route_type,
+                   unsigned short route_instance, mpls_label_t out_label);
 
 /*
  * Install/update a NHLFE for an LSP in the forwarding table. This may be