From: Benjamin Cama Date: Wed, 17 Aug 2011 15:23:07 +0000 (+0200) Subject: Merge branch 'use-netlink' into fdn-mods X-Git-Tag: debian/2.2.1-1fdn2~2^2 X-Git-Url: http://git.sameswireless.fr/l2tpns.git/commitdiff_plain/ec7ce23c79c375acc6a8930fc03dcef76488ba7e?hp=--cc Merge branch 'use-netlink' into fdn-mods Signed-off-by: Benjamin Cama --- ec7ce23c79c375acc6a8930fc03dcef76488ba7e diff --cc bgp.c index 80a445e,f1d0ec2..4b8cb64 --- a/bgp.c +++ b/bgp.c @@@ -29,15 -29,11 +29,15 @@@ char const *cvs_id_bgp = "$Id: bgp.c,v static void bgp_clear(struct bgp_peer *peer); static void bgp_set_retry(struct bgp_peer *peer); - static void bgp_cidr(in_addr_t ip, in_addr_t mask, struct bgp_ip_prefix *pfx); + static void bgp_cidr(in_addr_t ip, int prefixlen, struct bgp_ip_prefix *pfx); static struct bgp_route_list *bgp_insert_route(struct bgp_route_list *head, struct bgp_route_list *new); +static struct bgp_route6_list *bgp_insert_route6(struct bgp_route6_list *head, + struct bgp_route6_list *new); +static void bgp_process_timers(struct bgp_peer *peer); static void bgp_free_routes(struct bgp_route_list *routes); +static void bgp_free_routes6(struct bgp_route6_list *routes); static char const *bgp_msg_type_str(uint8_t type); static int bgp_connect(struct bgp_peer *peer); static int bgp_handle_connect(struct bgp_peer *peer); @@@ -520,61 -407,8 +501,61 @@@ int bgp_add_route(in_addr_t ip, int pre return 1; } +/* add route to list for peers */ +/* + * Note: same provisions as above + */ +int bgp_add_route6(struct in6_addr ip, int prefixlen) +{ + struct bgp_route6_list *r = bgp_routes6; + struct bgp_route6_list add; + int i; + char ipv6addr[INET6_ADDRSTRLEN]; + + memcpy(&add.dest.prefix, &ip.s6_addr, 16); + add.dest.len = prefixlen; + add.next = 0; + + /* check for duplicate */ + while (r) + { + i = memcmp(&r->dest, &add.dest, sizeof(r->dest)); + if (!i) + return 1; /* already covered */ + + if (i > 0) + break; + + r = r->next; + } + + /* insert into route list; sorted */ + if (!(r = malloc(sizeof(*r)))) + { + LOG(0, 0, 0, "Can't allocate route for %s/%d (%s)\n", + inet_ntop(AF_INET6, &ip, ipv6addr, INET6_ADDRSTRLEN), add.dest.len, + strerror(errno)); + + return 0; + } + + memcpy(r, &add, sizeof(*r)); + bgp_routes6 = bgp_insert_route6(bgp_routes6, r); + + /* flag established peers for update */ + for (i = 0; i < BGP_NUM_PEERS; i++) + if (bgp_peers[i].state == Established + && bgp_peers[i].mp_handling == HandleIPv6Routes) + bgp_peers[i].update_routes6 = 1; + + LOG(4, 0, 0, "Registered BGP route %s/%d\n", + inet_ntop(AF_INET6, &ip, ipv6addr, INET6_ADDRSTRLEN), add.dest.len); + + return 1; +} + /* remove route from list for peers */ - int bgp_del_route(in_addr_t ip, in_addr_t mask) + int bgp_del_route(in_addr_t ip, int prefixlen) { struct bgp_route_list *r = bgp_routes; struct bgp_route_list *e = 0; diff --cc bgp.h index 44bad0d,f8b52d6..bc5a0e9 --- a/bgp.h +++ b/bgp.h @@@ -271,10 -193,8 +271,10 @@@ int bgp_start(struct bgp_peer *peer, ch void bgp_stop(struct bgp_peer *peer); void bgp_halt(struct bgp_peer *peer); int bgp_restart(struct bgp_peer *peer); - int bgp_add_route(in_addr_t ip, in_addr_t mask); + int bgp_add_route(in_addr_t ip, int prefixlen); +int bgp_add_route6(struct in6_addr ip, int prefixlen); - int bgp_del_route(in_addr_t ip, in_addr_t mask); + int bgp_del_route(in_addr_t ip, int prefixlen); +int bgp_del_route6(struct in6_addr ip, int prefixlen); void bgp_enable_routing(int enable); int bgp_set_poll(void); int bgp_process(uint32_t events[]); diff --cc l2tpns.c index f2a60c9,c34dc63..581198d --- a/l2tpns.c +++ b/l2tpns.c @@@ -69,8 -69,10 +69,10 @@@ int rand_fd = -1; // Random data sourc int cluster_sockfd = -1; // Intra-cluster communications socket. int epollfd = -1; // event polling time_t basetime = 0; // base clock -char hostname[1000] = ""; // us. +char hostname[MAXHOSTNAME] = ""; // us. static int tunidx; // ifr_ifindex of tun device + int nlseqnum = 0; // netlink sequence number + int min_initok_nlseqnum = 0; // minimun seq number for messages after init is ok static int syslog_log = 0; // are we logging to syslog static FILE *log_stream = 0; // file handle for direct logging (i.e. direct into file, not via syslog). uint32_t last_id = 0; // Unique ID for radius accounting @@@ -499,16 -539,10 +541,15 @@@ void route6set(sessionidt s, struct in6 inet_ntop(AF_INET6, &ip, ipv6addr, INET6_ADDRSTRLEN), prefixlen); - if (ioctl(ifr6fd, add ? SIOCADDRT : SIOCDELRT, (void *) &rt) < 0) - LOG(0, 0, 0, "route6set() error in ioctl: %s\n", - strerror(errno)); + if (netlink_send(&req.nh) < 0) + LOG(0, 0, 0, "route6set() error in sending netlink message: %s\n", strerror(errno)); - // FIXME: need to add BGP routing (RFC2858) +#ifdef BGP + if (add) + bgp_add_route6(ip, prefixlen); + else + bgp_del_route6(ip, prefixlen); +#endif /* BGP */ if (s) {