From 398ee7061d3892945928c85d3dd28d62203edd8f Mon Sep 17 00:00:00 2001 From: Claudio Jeker Date: Tue, 6 Apr 2010 13:25:09 +0000 Subject: Switch to a more address family independent nexthop imsg. Instead of passing struct kroute or kroute6 pack the needed info into a struct bgpd_addr. No flames comming out of my and sthen@'s bgpd routers. --- usr.sbin/bgpd/bgpd.h | 8 +++----- usr.sbin/bgpd/kroute.c | 40 +++++++++++++++++++++++++++++----------- usr.sbin/bgpd/rde_rib.c | 20 ++++---------------- 3 files changed, 36 insertions(+), 32 deletions(-) (limited to 'usr.sbin/bgpd') diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index b260974eed6..3f7cc674292 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.254 2010/03/29 09:04:43 claudio Exp $ */ +/* $OpenBSD: bgpd.h,v 1.255 2010/04/06 13:25:08 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -454,14 +454,12 @@ struct kroute6 { }; struct kroute_nexthop { - union { - struct kroute kr4; - struct kroute6 kr6; - } kr; struct bgpd_addr nexthop; struct bgpd_addr gateway; + struct bgpd_addr net; u_int8_t valid; u_int8_t connected; + u_int8_t netlen; }; struct kif { diff --git a/usr.sbin/bgpd/kroute.c b/usr.sbin/bgpd/kroute.c index 1cb0281bb0b..08cb8e8933f 100644 --- a/usr.sbin/bgpd/kroute.c +++ b/usr.sbin/bgpd/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.175 2010/02/26 15:50:20 claudio Exp $ */ +/* $OpenBSD: kroute.c,v 1.176 2010/04/06 13:25:08 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -471,7 +471,9 @@ kr_nexthop_add(struct bgpd_addr *addr) nh.gateway.v4.s_addr = k->r.nexthop.s_addr; } - memcpy(&nh.kr.kr4, &k->r, sizeof(nh.kr.kr4)); + nh.net.aid = AID_INET; + nh.net.v4.s_addr = k->r.prefix.s_addr; + nh.netlen = k->r.prefixlen; } else if (h->kroute != NULL && addr->aid == AID_INET6) { k6 = h->kroute; nh.connected = k6->r.flags & F_CONNECTED; @@ -481,7 +483,10 @@ kr_nexthop_add(struct bgpd_addr *addr) memcpy(&nh.gateway.v6, &k6->r.nexthop, sizeof(struct in6_addr)); } - memcpy(&nh.kr.kr6, &k6->r, sizeof(nh.kr.kr6)); + nh.net.aid = AID_INET6; + memcpy(&nh.net.v6, &k6->r.nexthop, + sizeof(struct in6_addr)); + nh.netlen = k6->r.prefixlen; } send_nexthop_update(&nh); @@ -1510,7 +1515,9 @@ knexthop_validate(struct knexthop_node *kn) if ((n.gateway.v4.s_addr = kr->r.nexthop.s_addr) != 0) n.gateway.aid = AID_INET; - memcpy(&n.kr.kr4, &kr->r, sizeof(n.kr.kr4)); + n.net.aid = AID_INET; + n.net.v4.s_addr = kr->r.prefix.s_addr; + n.netlen = kr->r.prefixlen; send_nexthop_update(&n); } else /* down */ if (was_valid) @@ -1534,7 +1541,10 @@ knexthop_validate(struct knexthop_node *kn) memcpy(&n.gateway.v6, &kr6->r.nexthop, sizeof(struct in6_addr)); } - memcpy(&n.kr.kr6, &kr6->r, sizeof(n.kr.kr6)); + n.net.aid = AID_INET6; + memcpy(&n.net.v6, &kr6->r.nexthop, + sizeof(struct in6_addr)); + n.netlen = kr6->r.prefixlen; send_nexthop_update(&n); } else /* down */ if (was_valid) @@ -1568,7 +1578,9 @@ knexthop_track(void *krn) if ((n.gateway.v4.s_addr = kr->r.nexthop.s_addr) != 0) n.gateway.aid = AID_INET; - memcpy(&n.kr.kr4, &kr->r, sizeof(n.kr.kr4)); + n.net.aid = AID_INET; + n.net.v4.s_addr = kr->r.prefix.s_addr; + n.netlen = kr->r.prefixlen; break; case AID_INET6: kr6 = krn; @@ -1580,7 +1592,10 @@ knexthop_track(void *krn) memcpy(&n.gateway.v6, &kr6->r.nexthop, sizeof(struct in6_addr)); } - memcpy(&n.kr.kr6, &kr6->r, sizeof(n.kr.kr6)); + n.net.aid = AID_INET6; + memcpy(&n.net.v6, &kr6->r.nexthop, + sizeof(struct in6_addr)); + n.netlen = kr6->r.prefixlen; break; } send_nexthop_update(&n); @@ -1860,8 +1875,9 @@ if_change(u_short ifindex, int flags, struct if_data *ifd) kkr->kr->r.nexthop.s_addr) != 0) nh.gateway.aid = AID_INET; } - memcpy(&nh.kr.kr4, &kkr->kr->r, - sizeof(nh.kr.kr4)); + nh.net.aid = AID_INET; + nh.net.v4.s_addr = kkr->kr->r.prefix.s_addr; + nh.netlen = kkr->kr->r.prefixlen; send_nexthop_update(&nh); } } @@ -1888,8 +1904,10 @@ if_change(u_short ifindex, int flags, struct if_data *ifd) sizeof(struct in6_addr)); } } - memcpy(&nh.kr.kr6, &kkr6->kr->r, - sizeof(nh.kr.kr6)); + nh.net.aid = AID_INET6; + memcpy(&nh.net.v6, &kkr6->kr->r.nexthop, + sizeof(struct in6_addr)); + nh.netlen = kkr6->kr->r.prefixlen; send_nexthop_update(&nh); } } diff --git a/usr.sbin/bgpd/rde_rib.c b/usr.sbin/bgpd/rde_rib.c index e53ab08b56c..26f18dce418 100644 --- a/usr.sbin/bgpd/rde_rib.c +++ b/usr.sbin/bgpd/rde_rib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_rib.c,v 1.123 2010/03/29 09:06:56 claudio Exp $ */ +/* $OpenBSD: rde_rib.c,v 1.124 2010/04/06 13:25:08 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker @@ -1124,21 +1124,9 @@ nexthop_update(struct kroute_nexthop *msg) memcpy(&nh->true_nexthop, &msg->gateway, sizeof(nh->true_nexthop)); - switch (msg->nexthop.aid) { - case AID_INET: - nh->nexthop_netlen = msg->kr.kr4.prefixlen; - nh->nexthop_net.aid = AID_INET; - nh->nexthop_net.v4.s_addr = msg->kr.kr4.prefix.s_addr; - break; - case AID_INET6: - nh->nexthop_netlen = msg->kr.kr6.prefixlen; - nh->nexthop_net.aid = AID_INET6; - memcpy(&nh->nexthop_net.v6, &msg->kr.kr6.prefix, - sizeof(struct in6_addr)); - break; - default: - fatalx("nexthop_update: unknown af"); - } + memcpy(&nh->nexthop_net, &msg->net, + sizeof(nh->nexthop_net)); + nh->nexthop_netlen = msg->netlen; if (rde_noevaluate()) /* -- cgit v1.2.3