summaryrefslogtreecommitdiff
path: root/usr.sbin/bgpd
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2010-04-13 09:09:49 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2010-04-13 09:09:49 +0000
commit3f91acda7ecb874041498a8f9f9e0935c1128d3d (patch)
tree04ac90e2593e6c623035bf5e3114efb18c8ad4c7 /usr.sbin/bgpd
parent2ac8d40159b6ffdd0eecdfdecd16750830dbfbfc (diff)
Instead of passing AF specific struct kroutes over imsgs use a struct
kroute_full structure that is AF independent and has all information in it. Simplifies the communication between processes and reduces the number of imsg types. This is another step to add FIB support to BGP MPLS VPNs.
Diffstat (limited to 'usr.sbin/bgpd')
-rw-r--r--usr.sbin/bgpd/bgpd.c40
-rw-r--r--usr.sbin/bgpd/bgpd.h32
-rw-r--r--usr.sbin/bgpd/kroute.c270
-rw-r--r--usr.sbin/bgpd/rde.c109
-rw-r--r--usr.sbin/bgpd/session.c4
5 files changed, 233 insertions, 222 deletions
diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c
index 36468cbf7e7..9e91dfa9a6b 100644
--- a/usr.sbin/bgpd/bgpd.c
+++ b/usr.sbin/bgpd/bgpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpd.c,v 1.156 2010/03/29 09:09:25 claudio Exp $ */
+/* $OpenBSD: bgpd.c,v 1.157 2010/04/13 09:09:48 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -547,46 +547,38 @@ dispatch_imsg(struct imsgbuf *ibuf, int idx)
case IMSG_KROUTE_CHANGE:
if (idx != PFD_PIPE_ROUTE)
log_warnx("route request not from RDE");
+ else if (imsg.hdr.len != IMSG_HEADER_SIZE +
+ sizeof(struct kroute_full))
+ log_warnx("wrong imsg len");
else if (kr_change(imsg.data))
rv = -1;
break;
case IMSG_KROUTE_DELETE:
if (idx != PFD_PIPE_ROUTE)
log_warnx("route request not from RDE");
+ else if (imsg.hdr.len != IMSG_HEADER_SIZE +
+ sizeof(struct kroute_full))
+ log_warnx("wrong imsg len");
else if (kr_delete(imsg.data))
rv = -1;
break;
- case IMSG_KROUTE6_CHANGE:
- if (idx != PFD_PIPE_ROUTE)
- log_warnx("route request not from RDE");
- else if (kr6_change(imsg.data))
- rv = -1;
- break;
- case IMSG_KROUTE6_DELETE:
- if (idx != PFD_PIPE_ROUTE)
- log_warnx("route request not from RDE");
- else if (kr6_delete(imsg.data))
- rv = -1;
- break;
case IMSG_NEXTHOP_ADD:
if (idx != PFD_PIPE_ROUTE)
log_warnx("nexthop request not from RDE");
- else
- if (imsg.hdr.len != IMSG_HEADER_SIZE +
- sizeof(struct bgpd_addr))
- log_warnx("wrong imsg len");
- else if (kr_nexthop_add(imsg.data) == -1)
- rv = -1;
+ else if (imsg.hdr.len != IMSG_HEADER_SIZE +
+ sizeof(struct bgpd_addr))
+ log_warnx("wrong imsg len");
+ else if (kr_nexthop_add(imsg.data) == -1)
+ rv = -1;
break;
case IMSG_NEXTHOP_REMOVE:
if (idx != PFD_PIPE_ROUTE)
log_warnx("nexthop request not from RDE");
+ else if (imsg.hdr.len != IMSG_HEADER_SIZE +
+ sizeof(struct bgpd_addr))
+ log_warnx("wrong imsg len");
else
- if (imsg.hdr.len != IMSG_HEADER_SIZE +
- sizeof(struct bgpd_addr))
- log_warnx("wrong imsg len");
- else
- kr_nexthop_delete(imsg.data);
+ kr_nexthop_delete(imsg.data);
break;
case IMSG_PFTABLE_ADD:
if (idx != PFD_PIPE_ROUTE)
diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h
index 3f7cc674292..f4b21de52d5 100644
--- a/usr.sbin/bgpd/bgpd.h
+++ b/usr.sbin/bgpd/bgpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpd.h,v 1.255 2010/04/06 13:25:08 claudio Exp $ */
+/* $OpenBSD: bgpd.h,v 1.256 2010/04/13 09:09:48 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -329,7 +329,6 @@ enum imsg_type {
IMSG_CTL_NEIGHBOR_CLEAR,
IMSG_CTL_NEIGHBOR_RREFRESH,
IMSG_CTL_KROUTE,
- IMSG_CTL_KROUTE6,
IMSG_CTL_KROUTE_ADDR,
IMSG_CTL_RESULT,
IMSG_CTL_SHOW_NEIGHBOR,
@@ -341,7 +340,6 @@ enum imsg_type {
IMSG_CTL_SHOW_RIB_ATTR,
IMSG_CTL_SHOW_RIB_COMMUNITY,
IMSG_CTL_SHOW_NETWORK,
- IMSG_CTL_SHOW_NETWORK6,
IMSG_CTL_SHOW_RIB_MEM,
IMSG_CTL_SHOW_TERSE,
IMSG_CTL_SHOW_TIMER,
@@ -367,8 +365,6 @@ enum imsg_type {
IMSG_MRT_CLOSE,
IMSG_KROUTE_CHANGE,
IMSG_KROUTE_DELETE,
- IMSG_KROUTE6_CHANGE,
- IMSG_KROUTE6_DELETE,
IMSG_NEXTHOP_ADD,
IMSG_NEXTHOP_REMOVE,
IMSG_NEXTHOP_UPDATE,
@@ -433,6 +429,16 @@ enum suberr_cease {
ERR_CEASE_RSRC_EXHAUST
};
+struct kroute_full {
+ struct bgpd_addr prefix;
+ struct bgpd_addr nexthop;
+ char label[RTLABEL_LEN];
+ u_int16_t flags;
+ u_short ifindex;
+ u_int8_t prefixlen;
+ u_int8_t priority;
+};
+
struct kroute {
struct in_addr prefix;
struct in_addr nexthop;
@@ -503,16 +509,6 @@ struct ctl_neighbor {
int show_timers;
};
-struct kroute_label {
- struct kroute kr;
- char label[RTLABEL_LEN];
-};
-
-struct kroute6_label {
- struct kroute6 kr;
- char label[RTLABEL_LEN];
-};
-
#define F_RIB_ELIGIBLE 0x01
#define F_RIB_ACTIVE 0x02
#define F_RIB_INTERNAL 0x04
@@ -817,10 +813,8 @@ int host(const char *, struct bgpd_addr *, u_int8_t *);
/* kroute.c */
int kr_init(int, u_int);
-int kr_change(struct kroute_label *);
-int kr_delete(struct kroute_label *);
-int kr6_change(struct kroute6_label *);
-int kr6_delete(struct kroute6_label *);
+int kr_change(struct kroute_full *);
+int kr_delete(struct kroute_full *);
void kr_shutdown(void);
void kr_fib_couple(void);
void kr_fib_decouple(void);
diff --git a/usr.sbin/bgpd/kroute.c b/usr.sbin/bgpd/kroute.c
index 08cb8e8933f..c2ec3c3847f 100644
--- a/usr.sbin/bgpd/kroute.c
+++ b/usr.sbin/bgpd/kroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kroute.c,v 1.176 2010/04/06 13:25:08 claudio Exp $ */
+/* $OpenBSD: kroute.c,v 1.177 2010/04/13 09:09:48 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -83,8 +83,14 @@ struct kif_node {
struct kif_kr6_head kroute6_l;
};
+int kr4_change(struct kroute_full *);
+int kr6_change(struct kroute_full *);
+int kr4_delete(struct kroute_full *);
+int kr6_delete(struct kroute_full *);
int kr_redistribute(int, struct kroute *);
int kr_redistribute6(int, struct kroute6 *);
+struct kroute_full *kr_tofull(struct kroute *);
+struct kroute_full *kr6_tofull(struct kroute6 *);
int kroute_compare(struct kroute_node *, struct kroute_node *);
int kroute6_compare(struct kroute6_node *, struct kroute6_node *);
int knexthop_compare(struct knexthop_node *, struct knexthop_node *);
@@ -222,168 +228,184 @@ kr_init(int fs, u_int rtableid)
}
int
-kr_change(struct kroute_label *kl)
+kr_change(struct kroute_full *kl)
+{
+ switch (kl->prefix.aid) {
+ case AID_INET:
+ return (kr4_change(kl));
+ case AID_INET6:
+ return (kr6_change(kl));
+ }
+ log_warnx("kr_change: not handled AID");
+ return (-1);
+}
+
+int
+kr4_change(struct kroute_full *kl)
{
struct kroute_node *kr;
int action = RTM_ADD;
+ u_int16_t labelid;
- if ((kr = kroute_find(kl->kr.prefix.s_addr, kl->kr.prefixlen, RTP_BGP))
- != NULL)
+ if ((kr = kroute_find(kl->prefix.v4.s_addr, kl->prefixlen,
+ RTP_BGP)) != NULL)
action = RTM_CHANGE;
/* nexthop within 127/8 -> ignore silently */
- if ((kl->kr.nexthop.s_addr & htonl(IN_CLASSA_NET)) ==
+ if ((kl->nexthop.v4.s_addr & htonl(IN_CLASSA_NET)) ==
htonl(INADDR_LOOPBACK & IN_CLASSA_NET))
return (0);
- if (kr)
- rtlabel_unref(kr->r.labelid);
- kl->kr.labelid = rtlabel_name2id(kl->label);
+ labelid = rtlabel_name2id(kl->label);
/* for blackhole and reject routes nexthop needs to be 127.0.0.1 */
- if (kl->kr.flags & (F_BLACKHOLE|F_REJECT))
- kl->kr.nexthop.s_addr = htonl(INADDR_LOOPBACK);
-
- if (send_rtmsg(kr_state.fd, action, &kl->kr) == -1)
- return (-1);
+ if (kl->flags & (F_BLACKHOLE|F_REJECT))
+ kl->nexthop.v4.s_addr = htonl(INADDR_LOOPBACK);
if (action == RTM_ADD) {
if ((kr = calloc(1, sizeof(struct kroute_node))) == NULL) {
log_warn("kr_change");
return (-1);
}
- kr->r.prefix.s_addr = kl->kr.prefix.s_addr;
- kr->r.prefixlen = kl->kr.prefixlen;
- kr->r.nexthop.s_addr = kl->kr.nexthop.s_addr;
- kr->r.flags = kl->kr.flags | F_BGPD_INSERTED;
+ kr->r.prefix.s_addr = kl->prefix.v4.s_addr;
+ kr->r.prefixlen = kl->prefixlen;
+ kr->r.nexthop.s_addr = kl->nexthop.v4.s_addr;
+ kr->r.flags = kl->flags | F_BGPD_INSERTED;
kr->r.priority = RTP_BGP;
- kr->r.labelid = kl->kr.labelid;
+ kr->r.labelid = labelid;
if (kroute_insert(kr) == -1)
free(kr);
} else {
- kr->r.nexthop.s_addr = kl->kr.nexthop.s_addr;
- kr->r.labelid = kl->kr.labelid;
- if (kl->kr.flags & F_BLACKHOLE)
+ kr->r.nexthop.s_addr = kl->nexthop.v4.s_addr;
+ rtlabel_unref(kr->r.labelid);
+ kr->r.labelid = labelid;
+ if (kl->flags & F_BLACKHOLE)
kr->r.flags |= F_BLACKHOLE;
else
kr->r.flags &= ~F_BLACKHOLE;
- if (kl->kr.flags & F_REJECT)
+ if (kl->flags & F_REJECT)
kr->r.flags |= F_REJECT;
else
kr->r.flags &= ~F_REJECT;
}
- return (0);
-}
-
-int
-kr_delete(struct kroute_label *kl)
-{
- struct kroute_node *kr;
-
- if ((kr = kroute_find(kl->kr.prefix.s_addr, kl->kr.prefixlen, RTP_BGP))
- == NULL)
- return (0);
-
- if (!(kr->r.flags & F_BGPD_INSERTED))
- return (0);
-
- /* nexthop within 127/8 -> ignore silently */
- if ((kl->kr.nexthop.s_addr & htonl(IN_CLASSA_NET)) ==
- htonl(INADDR_LOOPBACK & IN_CLASSA_NET))
- return (0);
-
- if (send_rtmsg(kr_state.fd, RTM_DELETE, &kl->kr) == -1)
- return (-1);
-
- rtlabel_unref(kl->kr.labelid);
-
- if (kroute_remove(kr) == -1)
+ if (send_rtmsg(kr_state.fd, action, &kr->r) == -1)
return (-1);
return (0);
}
int
-kr6_change(struct kroute6_label *kl)
+kr6_change(struct kroute_full *kl)
{
struct kroute6_node *kr6;
- int action = RTM_ADD;
struct in6_addr lo6 = IN6ADDR_LOOPBACK_INIT;
+ int action = RTM_ADD;
+ u_int16_t labelid;
- if ((kr6 = kroute6_find(&kl->kr.prefix, kl->kr.prefixlen, RTP_BGP))
- != NULL)
+ if ((kr6 = kroute6_find(&kl->prefix.v6, kl->prefixlen, RTP_BGP)) !=
+ NULL)
action = RTM_CHANGE;
/* nexthop to loopback -> ignore silently */
- if (IN6_IS_ADDR_LOOPBACK(&kl->kr.nexthop))
+ if (IN6_IS_ADDR_LOOPBACK(&kl->nexthop.v6))
return (0);
- if (kr6)
- rtlabel_unref(kr6->r.labelid);
- kl->kr.labelid = rtlabel_name2id(kl->label);
+ labelid = rtlabel_name2id(kl->label);
/* for blackhole and reject routes nexthop needs to be ::1 */
- if (kl->kr.flags & (F_BLACKHOLE|F_REJECT))
- bcopy(&lo6, &kl->kr.nexthop, sizeof(kl->kr.nexthop));
-
- if (send_rt6msg(kr_state.fd, action, &kl->kr) == -1)
- return (-1);
+ if (kl->flags & (F_BLACKHOLE|F_REJECT))
+ bcopy(&lo6, &kl->nexthop.v6, sizeof(kl->nexthop.v6));
if (action == RTM_ADD) {
if ((kr6 = calloc(1, sizeof(struct kroute6_node))) == NULL) {
log_warn("kr_change");
return (-1);
}
- memcpy(&kr6->r.prefix, &kl->kr.prefix,
+ memcpy(&kr6->r.prefix, &kl->prefix.v6, sizeof(struct in6_addr));
+ kr6->r.prefixlen = kl->prefixlen;
+ memcpy(&kr6->r.nexthop, &kl->nexthop.v6,
sizeof(struct in6_addr));
- kr6->r.prefixlen = kl->kr.prefixlen;
- memcpy(&kr6->r.nexthop, &kl->kr.nexthop,
- sizeof(struct in6_addr));
- kr6->r.flags = kl->kr.flags | F_BGPD_INSERTED;
+ kr6->r.flags = kl->flags | F_BGPD_INSERTED;
kr6->r.priority = RTP_BGP;
- kr6->r.labelid = kl->kr.labelid;
+ kr6->r.labelid = labelid;
if (kroute6_insert(kr6) == -1)
free(kr6);
} else {
- memcpy(&kr6->r.nexthop, &kl->kr.nexthop,
+ memcpy(&kr6->r.nexthop, &kl->nexthop.v6,
sizeof(struct in6_addr));
- kr6->r.labelid = kl->kr.labelid;
- if (kl->kr.flags & F_BLACKHOLE)
+ rtlabel_unref(kr6->r.labelid);
+ kr6->r.labelid = labelid;
+ if (kl->flags & F_BLACKHOLE)
kr6->r.flags |= F_BLACKHOLE;
else
kr6->r.flags &= ~F_BLACKHOLE;
- if (kl->kr.flags & F_REJECT)
+ if (kl->flags & F_REJECT)
kr6->r.flags |= F_REJECT;
else
kr6->r.flags &= ~F_REJECT;
}
+ if (send_rt6msg(kr_state.fd, action, &kr6->r) == -1)
+ return (-1);
+
return (0);
}
int
-kr6_delete(struct kroute6_label *kl)
+kr_delete(struct kroute_full *kl)
{
- struct kroute6_node *kr6;
+ switch (kl->prefix.aid) {
+ case AID_INET:
+ return (kr4_delete(kl));
+ case AID_INET6:
+ return (kr6_delete(kl));
+ }
+ log_warnx("kr_change: not handled AID");
+ return (-1);
+}
+
+int
+kr4_delete(struct kroute_full *kl)
+{
+ struct kroute_node *kr;
- if ((kr6 = kroute6_find(&kl->kr.prefix, kl->kr.prefixlen, RTP_BGP))
- == NULL)
+ if ((kr = kroute_find(kl->prefix.v4.s_addr, kl->prefixlen,
+ RTP_BGP)) == NULL)
return (0);
- if (!(kr6->r.flags & F_BGPD_INSERTED))
+ if (!(kr->r.flags & F_BGPD_INSERTED))
return (0);
- /* nexthop to loopback -> ignore silently */
- if (IN6_IS_ADDR_LOOPBACK(&kl->kr.nexthop))
+ if (send_rtmsg(kr_state.fd, RTM_DELETE, &kr->r) == -1)
+ return (-1);
+
+ rtlabel_unref(kr->r.labelid);
+
+ if (kroute_remove(kr) == -1)
+ return (-1);
+
+ return (0);
+}
+
+int
+kr6_delete(struct kroute_full *kl)
+{
+ struct kroute6_node *kr6;
+
+ if ((kr6 = kroute6_find(&kl->prefix.v6, kl->prefixlen, RTP_BGP)) ==
+ NULL)
return (0);
- if (send_rt6msg(kr_state.fd, RTM_DELETE, &kl->kr) == -1)
+ if (!(kr6->r.flags & F_BGPD_INSERTED))
+ return (0);
+
+ if (send_rt6msg(kr_state.fd, RTM_DELETE, &kr6->r) == -1)
return (-1);
- rtlabel_unref(kl->kr.labelid);
+ rtlabel_unref(kr6->r.labelid);
if (kroute6_remove(kr6) == -1)
return (-1);
@@ -538,27 +560,27 @@ kr_show_route(struct imsg *imsg)
memcpy(&flags, imsg->data, sizeof(flags));
memcpy(&af, (char *)imsg->data + sizeof(flags), sizeof(af));
if (!af || af == AF_INET)
- RB_FOREACH(kr, kroute_tree, &krt)
- if (!flags || kr->r.flags & flags) {
- kn = kr;
- do {
- send_imsg_session(
- IMSG_CTL_KROUTE,
- imsg->hdr.pid, &kn->r,
- sizeof(kn->r));
- } while ((kn = kn->next) != NULL);
- }
+ RB_FOREACH(kr, kroute_tree, &krt) {
+ if (flags && (kr->r.flags & flags) == 0)
+ continue;
+ kn = kr;
+ do {
+ send_imsg_session(IMSG_CTL_KROUTE,
+ imsg->hdr.pid, kr_tofull(&kn->r),
+ sizeof(struct kroute_full));
+ } while ((kn = kn->next) != NULL);
+ }
if (!af || af == AF_INET6)
- RB_FOREACH(kr6, kroute6_tree, &krt6)
- if (!flags || kr6->r.flags & flags) {
- kn6 = kr6;
- do {
- send_imsg_session(
- IMSG_CTL_KROUTE6,
- imsg->hdr.pid, &kn6->r,
- sizeof(kn6->r));
- } while ((kn6 = kn6->next) != NULL);
- }
+ RB_FOREACH(kr6, kroute6_tree, &krt6) {
+ if (flags && (kr6->r.flags & flags) == 0)
+ continue;
+ kn6 = kr6;
+ do {
+ send_imsg_session(IMSG_CTL_KROUTE,
+ imsg->hdr.pid, kr6_tofull(&kn6->r),
+ sizeof(struct kroute_full));
+ } while ((kn6 = kn6->next) != NULL);
+ }
break;
case IMSG_CTL_KROUTE_ADDR:
if (imsg->hdr.len != IMSG_HEADER_SIZE +
@@ -573,13 +595,15 @@ kr_show_route(struct imsg *imsg)
kr = kroute_match(addr->v4.s_addr, 1);
if (kr != NULL)
send_imsg_session(IMSG_CTL_KROUTE,
- imsg->hdr.pid, &kr->r, sizeof(kr->r));
+ imsg->hdr.pid, kr_tofull(&kr->r),
+ sizeof(struct kroute_full));
break;
case AID_INET6:
kr6 = kroute6_match(&addr->v6, 1);
if (kr6 != NULL)
- send_imsg_session(IMSG_CTL_KROUTE6,
- imsg->hdr.pid, &kr6->r, sizeof(kr6->r));
+ send_imsg_session(IMSG_CTL_KROUTE,
+ imsg->hdr.pid, kr6_tofull(&kr6->r),
+ sizeof(struct kroute_full));
break;
}
break;
@@ -801,6 +825,46 @@ kr_reload(void)
return (0);
}
+struct kroute_full *
+kr_tofull(struct kroute *kr)
+{
+ static struct kroute_full kf;
+
+ bzero(&kf, sizeof(kf));
+
+ kf.prefix.aid = AID_INET;
+ kf.prefix.v4.s_addr = kr->prefix.s_addr;
+ kf.nexthop.aid = AID_INET;
+ kf.nexthop.v4.s_addr = kr->nexthop.s_addr;
+ strlcpy(kf.label, rtlabel_id2name(kr->labelid), sizeof(kf.label));
+ kf.flags = kr->flags;
+ kf.ifindex = kr->ifindex;
+ kf.prefixlen = kr->prefixlen;
+ kf.priority = kr->priority;
+
+ return (&kf);
+}
+
+struct kroute_full *
+kr6_tofull(struct kroute6 *kr6)
+{
+ static struct kroute_full kf;
+
+ bzero(&kf, sizeof(kf));
+
+ kf.prefix.aid = AID_INET6;
+ memcpy(&kf.prefix.v6, &kr6->prefix, sizeof(struct in6_addr));
+ kf.nexthop.aid = AID_INET6;
+ memcpy(&kf.nexthop.v6, &kr6->nexthop, sizeof(struct in6_addr));
+ strlcpy(kf.label, rtlabel_id2name(kr6->labelid), sizeof(kf.label));
+ kf.flags = kr6->flags;
+ kf.ifindex = kr6->ifindex;
+ kf.prefixlen = kr6->prefixlen;
+ kf.priority = kr6->priority;
+
+ return (&kf);
+}
+
/*
* RB-tree compare functions
*/
diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c
index 635e909abec..4700050b225 100644
--- a/usr.sbin/bgpd/rde.c
+++ b/usr.sbin/bgpd/rde.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.c,v 1.290 2010/03/30 15:43:30 claudio Exp $ */
+/* $OpenBSD: rde.c,v 1.291 2010/04/13 09:09:48 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -2214,8 +2214,7 @@ rde_dump_mrt_new(struct mrt *mrt, pid_t pid, int fd)
void
rde_send_kroute(struct prefix *new, struct prefix *old)
{
- struct kroute_label kl;
- struct kroute6_label kl6;
+ struct kroute_full kr;
struct bgpd_addr addr;
struct prefix *p;
enum imsg_type type;
@@ -2237,50 +2236,22 @@ rde_send_kroute(struct prefix *new, struct prefix *old)
}
pt_getaddr(p->prefix, &addr);
- switch (addr.aid) {
- case AID_INET:
- bzero(&kl, sizeof(kl));
- kl.kr.prefix.s_addr = addr.v4.s_addr;
- kl.kr.prefixlen = p->prefix->prefixlen;
- if (p->aspath->flags & F_NEXTHOP_REJECT)
- kl.kr.flags |= F_REJECT;
- if (p->aspath->flags & F_NEXTHOP_BLACKHOLE)
- kl.kr.flags |= F_BLACKHOLE;
- if (type == IMSG_KROUTE_CHANGE)
- kl.kr.nexthop.s_addr =
- p->aspath->nexthop->true_nexthop.v4.s_addr;
- strlcpy(kl.label, rtlabel_id2name(p->aspath->rtlabelid),
- sizeof(kl.label));
- if (imsg_compose(ibuf_main, type, 0, 0, -1, &kl,
- sizeof(kl)) == -1)
- fatal("imsg_compose error");
- break;
- case AID_INET6:
- bzero(&kl6, sizeof(kl6));
- memcpy(&kl6.kr.prefix, &addr.v6, sizeof(struct in6_addr));
- kl6.kr.prefixlen = p->prefix->prefixlen;
- if (p->aspath->flags & F_NEXTHOP_REJECT)
- kl6.kr.flags |= F_REJECT;
- if (p->aspath->flags & F_NEXTHOP_BLACKHOLE)
- kl6.kr.flags |= F_BLACKHOLE;
- if (type == IMSG_KROUTE_CHANGE) {
- type = IMSG_KROUTE6_CHANGE;
- memcpy(&kl6.kr.nexthop,
- &p->aspath->nexthop->true_nexthop.v6,
- sizeof(struct in6_addr));
- } else
- type = IMSG_KROUTE6_DELETE;
- strlcpy(kl6.label, rtlabel_id2name(p->aspath->rtlabelid),
- sizeof(kl6.label));
- if (imsg_compose(ibuf_main, type, 0, 0, -1, &kl6,
- sizeof(kl6)) == -1)
- fatal("imsg_compose error");
- break;
- case AID_VPN_IPv4:
- break;
- default:
- fatal("rde_send_kroute: unhandled AID");
- }
+ bzero(&kr, sizeof(kr));
+ memcpy(&kr.prefix, &addr, sizeof(kr.prefix));
+ kr.prefixlen = p->prefix->prefixlen;
+ if (p->aspath->flags & F_NEXTHOP_REJECT)
+ kr.flags |= F_REJECT;
+ if (p->aspath->flags & F_NEXTHOP_BLACKHOLE)
+ kr.flags |= F_BLACKHOLE;
+ if (type == IMSG_KROUTE_CHANGE)
+ memcpy(&kr.nexthop, &p->aspath->nexthop->true_nexthop,
+ sizeof(kr.nexthop));
+ strlcpy(kr.label, rtlabel_id2name(p->aspath->rtlabelid),
+ sizeof(kr.label));
+
+ if (imsg_compose(ibuf_main, type, 0, 0, -1, &kr,
+ sizeof(kr)) == -1)
+ fatal("imsg_compose error");
}
/*
@@ -3034,8 +3005,7 @@ void
network_dump_upcall(struct rib_entry *re, void *ptr)
{
struct prefix *p;
- struct kroute k;
- struct kroute6 k6;
+ struct kroute_full k;
struct bgpd_addr addr;
struct rde_dump_ctx *ctx = ptr;
@@ -3043,30 +3013,23 @@ network_dump_upcall(struct rib_entry *re, void *ptr)
if (!(p->aspath->flags & F_PREFIX_ANNOUNCED))
continue;
pt_getaddr(p->prefix, &addr);
- switch (addr.aid) {
- case AID_INET:
- bzero(&k, sizeof(k));
- k.prefix.s_addr = addr.v4.s_addr;
- k.prefixlen = p->prefix->prefixlen;
- if (p->aspath->peer == peerself)
- k.flags = F_KERNEL;
- if (imsg_compose(ibuf_se_ctl, IMSG_CTL_SHOW_NETWORK, 0,
- ctx->req.pid, -1, &k, sizeof(k)) == -1)
- log_warnx("network_dump_upcall: "
- "imsg_compose error");
- break;
- case AID_INET6:
- bzero(&k6, sizeof(k6));
- memcpy(&k6.prefix, &addr.v6, sizeof(k6.prefix));
- k6.prefixlen = p->prefix->prefixlen;
- if (p->aspath->peer == peerself)
- k6.flags = F_KERNEL;
- if (imsg_compose(ibuf_se_ctl, IMSG_CTL_SHOW_NETWORK6, 0,
- ctx->req.pid, -1, &k6, sizeof(k6)) == -1)
- log_warnx("network_dump_upcall: "
- "imsg_compose error");
- break;
- }
+
+ bzero(&k, sizeof(k));
+ memcpy(&k.prefix, &addr, sizeof(k.prefix));
+ if (p->aspath->nexthop == NULL ||
+ p->aspath->nexthop->state != NEXTHOP_REACH)
+ k.nexthop.aid = k.prefix.aid;
+ else
+ memcpy(&k.nexthop, &p->aspath->nexthop->true_nexthop,
+ sizeof(k.nexthop));
+ k.prefixlen = p->prefix->prefixlen;
+ k.flags = F_KERNEL;
+ if ((p->aspath->flags & F_ANN_DYNAMIC) == 0)
+ k.flags = F_STATIC;
+ if (imsg_compose(ibuf_se_ctl, IMSG_CTL_SHOW_NETWORK, 0,
+ ctx->req.pid, -1, &k, sizeof(k)) == -1)
+ log_warnx("network_dump_upcall: "
+ "imsg_compose error");
}
}
diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c
index 7caa7dd4ffd..10f09c9f444 100644
--- a/usr.sbin/bgpd/session.c
+++ b/usr.sbin/bgpd/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.305 2010/02/11 22:05:59 claudio Exp $ */
+/* $OpenBSD: session.c,v 1.306 2010/04/13 09:09:48 claudio Exp $ */
/*
* Copyright (c) 2003, 2004, 2005 Henning Brauer <henning@openbsd.org>
@@ -2486,7 +2486,6 @@ session_dispatch_imsg(struct imsgbuf *ibuf, int idx, u_int *listener_cnt)
}
break;
case IMSG_CTL_KROUTE:
- case IMSG_CTL_KROUTE6:
case IMSG_CTL_KROUTE_ADDR:
case IMSG_CTL_SHOW_NEXTHOP:
case IMSG_CTL_SHOW_INTERFACE:
@@ -2499,7 +2498,6 @@ session_dispatch_imsg(struct imsgbuf *ibuf, int idx, u_int *listener_cnt)
case IMSG_CTL_SHOW_RIB_ATTR:
case IMSG_CTL_SHOW_RIB_MEM:
case IMSG_CTL_SHOW_NETWORK:
- case IMSG_CTL_SHOW_NETWORK6:
case IMSG_CTL_SHOW_NEIGHBOR:
if (idx != PFD_PIPE_ROUTE_CTL)
fatalx("ctl rib request not from RDE");