From: Benjamin Cama Date: Tue, 19 Jul 2011 22:49:28 +0000 (+0200) Subject: Move NEXT_HOP attribute so that we can exclude it. X-Git-Tag: debian/2.2.1-1fdn1~1^2^2~14 X-Git-Url: http://git.sameswireless.fr/l2tpns.git/commitdiff_plain/02611e54fc55643ec109b255707ce9832e005ddf?ds=inline;hp=f2e59e98817d4959af549abccf4e798e6184f6d4 Move NEXT_HOP attribute so that we can exclude it. We will need to do that when we will send IPv6 routes (RFC4760 says we SHOULD NOT carry this attribute when we will send UPDATE without NLRI). So, we save the length of all the attributes except NEXT_HOP for later memcpy(). Signed-off-by: Benjamin Cama --- diff --git a/bgp.c b/bgp.c index f12efb1..10f06a3 100644 --- a/bgp.c +++ b/bgp.c @@ -193,15 +193,6 @@ int bgp_start(struct bgp_peer *peer, char *name, int as, int keepalive, ADD_ATTRIBUTE(); - /* NEXT_HOP */ - a.flags = BGP_PATH_ATTR_FLAG_TRANS; - a.code = BGP_PATH_ATTR_CODE_NEXT_HOP; - ip = my_address; /* we're it */ - a.data.s.len = sizeof(ip); - memcpy(a.data.s.value, &ip, sizeof(ip)); - - ADD_ATTRIBUTE(); - /* MULTI_EXIT_DISC */ a.flags = BGP_PATH_ATTR_FLAG_OPTIONAL; a.code = BGP_PATH_ATTR_CODE_MULTI_EXIT_DISC; @@ -231,6 +222,18 @@ int bgp_start(struct bgp_peer *peer, char *name, int as, int keepalive, ADD_ATTRIBUTE(); + /* remember the len before adding NEXT_HOP */ + peer->path_attr_len_without_nexthop = peer->path_attr_len; + + /* NEXT_HOP */ + a.flags = BGP_PATH_ATTR_FLAG_TRANS; + a.code = BGP_PATH_ATTR_CODE_NEXT_HOP; + ip = my_address; /* we're it */ + a.data.s.len = sizeof(ip); + memcpy(a.data.s.value, &ip, sizeof(ip)); + + ADD_ATTRIBUTE(); + if (!(peer->path_attrs = malloc(peer->path_attr_len))) { LOG(0, 0, 0, "Can't allocate path_attrs for %s (%s)\n", diff --git a/bgp.h b/bgp.h index 91adb88..a791fc1 100644 --- a/bgp.h +++ b/bgp.h @@ -203,6 +203,7 @@ struct bgp_peer { int cli_flag; /* updates requested from CLI */ char *path_attrs; /* path attrs to send in UPDATE message */ int path_attr_len; /* length of path attrs */ + int path_attr_len_without_nexthop; /* length of path attrs without NEXT_HOP */ uint32_t events; /* events to poll */ struct event_data edata; /* poll data */ int handle_ipv6_routes; /* can handle IPv6 routes advertisements */