diff options
author | 2016-10-05 07:38:06 +0000 | |
---|---|---|
committer | 2016-10-05 07:38:06 +0000 | |
commit | f6296dcf3752d5bd046a872a08822a6beceac175 (patch) | |
tree | 42bedcd56ba176568a4c9d1c19bfeb2ad2b0083d | |
parent | Introduce a global function pointer to reset the CPU akin to amd64 and (diff) | |
download | wireguard-openbsd-f6296dcf3752d5bd046a872a08822a6beceac175.tar.xz wireguard-openbsd-f6296dcf3752d5bd046a872a08822a6beceac175.zip |
Let bgpd announce routes based on a route-label.
OK henning@ benno@
-rw-r--r-- | usr.sbin/bgpd/bgpd.conf.5 | 14 | ||||
-rw-r--r-- | usr.sbin/bgpd/bgpd.h | 6 | ||||
-rw-r--r-- | usr.sbin/bgpd/kroute.c | 31 | ||||
-rw-r--r-- | usr.sbin/bgpd/parse.y | 21 | ||||
-rw-r--r-- | usr.sbin/bgpd/printconf.c | 6 |
5 files changed, 72 insertions, 6 deletions
diff --git a/usr.sbin/bgpd/bgpd.conf.5 b/usr.sbin/bgpd/bgpd.conf.5 index f1e8535d6c6..a4b9613951c 100644 --- a/usr.sbin/bgpd/bgpd.conf.5 +++ b/usr.sbin/bgpd/bgpd.conf.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: bgpd.conf.5,v 1.146 2016/08/17 08:14:40 phessler Exp $ +.\" $OpenBSD: bgpd.conf.5,v 1.147 2016/10/05 07:38:06 phessler Exp $ .\" .\" Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org> .\" Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -16,7 +16,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: August 17 2016 $ +.Dd $Mdocdate: October 5 2016 $ .Dt BGPD.CONF 5 .Os .Sh NAME @@ -268,6 +268,11 @@ Log received and sent updates. .Pq Ic inet Ns | Ns Ic inet6 .Ic connected Op Ic set ...\& .Xc +.It Xo +.Ic network +.Pq Ic inet Ns | Ns Ic inet6 +.Ic rtlabel Ar label Op Ic set ...\& +.Xc Announce the specified network as belonging to our AS. If set to .Ic connected , @@ -275,6 +280,11 @@ routes to directly attached networks will be announced. If set to .Ic static , all static routes will be announced. +If set to +.Ic rtlabel , +routes with the specified +.Ar label +will be announced. .Bd -literal -offset indent network 192.168.7.0/24 .Ed diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index 6bd19c19c55..1531dac3bd9 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.295 2016/09/02 14:00:29 benno Exp $ */ +/* $OpenBSD: bgpd.h,v 1.296 2016/10/05 07:38:06 phessler Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -85,6 +85,7 @@ #define F_CTL_ADJ_IN 0x2000 #define F_CTL_ADJ_OUT 0x4000 #define F_CTL_ACTIVE 0x8000 +#define F_RTLABEL 0x10000 /* * Limit the number of control messages generated by the RDE and queued in @@ -334,6 +335,7 @@ enum network_type { NETWORK_DEFAULT, NETWORK_STATIC, NETWORK_CONNECTED, + NETWORK_RTLABEL, NETWORK_MRTCLONE }; @@ -342,6 +344,7 @@ struct network_config { struct filter_set_head attrset; struct rde_aspath *asp; u_int rtableid; + u_int16_t rtlabel; enum network_type type; u_int8_t prefixlen; u_int8_t old; /* used for reloading */ @@ -507,6 +510,7 @@ struct kroute_full { struct bgpd_addr prefix; struct bgpd_addr nexthop; char label[RTLABEL_LEN]; + u_int16_t labelid; u_int16_t flags; u_short ifindex; u_int8_t prefixlen; diff --git a/usr.sbin/bgpd/kroute.c b/usr.sbin/bgpd/kroute.c index 0441219d51b..90dbe6506df 100644 --- a/usr.sbin/bgpd/kroute.c +++ b/usr.sbin/bgpd/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.209 2016/04/08 12:27:05 phessler Exp $ */ +/* $OpenBSD: kroute.c,v 1.210 2016/10/05 07:38:06 phessler Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -1111,6 +1111,10 @@ kr_net_match(struct ktable *kt, struct kroute *kr) if (kr->flags & F_CONNECTED) return (xn); break; + case NETWORK_RTLABEL: + if (kr->labelid == xn->net.rtlabel) + return (xn); + break; case NETWORK_MRTCLONE: /* can not happen */ break; @@ -1143,6 +1147,10 @@ kr_net_match6(struct ktable *kt, struct kroute6 *kr6) if (kr6->flags & F_CONNECTED) return (xn); break; + case NETWORK_RTLABEL: + if (kr6->labelid == xn->net.rtlabel) + return (xn); + break; case NETWORK_MRTCLONE: /* can not happen */ break; @@ -1269,6 +1277,7 @@ sendit: net.prefix.aid = AID_INET; net.prefix.v4.s_addr = kr->prefix.s_addr; net.prefixlen = kr->prefixlen; + net.rtlabel = kr->labelid; net.rtableid = kt->rtableid; return (send_network(type, &net, match ? &match->net.attrset : NULL)); @@ -1337,6 +1346,7 @@ sendit: net.prefix.aid = AID_INET6; memcpy(&net.prefix.v6, &kr6->prefix, sizeof(struct in6_addr)); net.prefixlen = kr6->prefixlen; + net.rtlabel = kr6->labelid; net.rtableid = kt->rtableid; return (send_network(type, &net, match ? &match->net.attrset : NULL)); @@ -1392,6 +1402,7 @@ kr_tofull(struct kroute *kr) 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.labelid = kr->labelid; kf.flags = kr->flags; kf.ifindex = kr->ifindex; kf.prefixlen = kr->prefixlen; @@ -1412,6 +1423,7 @@ kr6_tofull(struct kroute6 *kr6) 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.labelid = kr6->labelid; kf.flags = kr6->flags; kf.ifindex = kr6->ifindex; kf.prefixlen = kr6->prefixlen; @@ -2780,6 +2792,7 @@ fetchtable(struct ktable *kt, u_int8_t fib_prio) struct sockaddr *sa, *gw, *rti_info[RTAX_MAX]; struct sockaddr_in *sa_in; struct sockaddr_in6 *sa_in6; + struct sockaddr_rtlabel *label; struct kroute_node *kr = NULL; struct kroute6_node *kr6 = NULL; @@ -2858,6 +2871,14 @@ fetchtable(struct ktable *kt, u_int8_t fib_prio) else kr->r.prefixlen = prefixlen_classful(kr->r.prefix.s_addr); + rtlabel_unref(kr->r.labelid); + kr->r.labelid = 0; + if ((label = (struct sockaddr_rtlabel *) + rti_info[RTAX_LABEL]) != NULL) { + kr->r.flags |= F_RTLABEL; + kr->r.labelid = + rtlabel_name2id(label->sr_label); + } break; case AF_INET6: if ((kr6 = calloc(1, sizeof(struct kroute6_node))) == @@ -2891,6 +2912,14 @@ fetchtable(struct ktable *kt, u_int8_t fib_prio) kr6->r.prefixlen = 128; else fatalx("INET6 route without netmask"); + rtlabel_unref(kr6->r.labelid); + kr6->r.labelid = 0; + if ((label = (struct sockaddr_rtlabel *) + rti_info[RTAX_LABEL]) != NULL) { + kr6->r.flags |= F_RTLABEL; + kr6->r.labelid = + rtlabel_name2id(label->sr_label); + } break; default: continue; diff --git a/usr.sbin/bgpd/parse.y b/usr.sbin/bgpd/parse.y index 44edc3102fc..524ec1fa07a 100644 --- a/usr.sbin/bgpd/parse.y +++ b/usr.sbin/bgpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.288 2016/06/21 21:35:24 benno Exp $ */ +/* $OpenBSD: parse.y,v 1.289 2016/10/05 07:38:06 phessler Exp $ */ /* * Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -674,6 +674,25 @@ network : NETWORK prefix filter_set { TAILQ_INSERT_TAIL(netconf, n, entry); } + | NETWORK family RTLABEL STRING filter_set { + struct network *n; + + if ((n = calloc(1, sizeof(struct network))) == NULL) + fatal("new_network"); + if (afi2aid($2, SAFI_UNICAST, &n->net.prefix.aid) == + -1) { + yyerror("unknown family"); + filterset_free($5); + free($5); + YYERROR; + } + n->net.type = NETWORK_RTLABEL; + n->net.rtlabel = rtlabel_name2id($4); + filterset_move($5, &n->net.attrset); + free($5); + + TAILQ_INSERT_TAIL(netconf, n, entry); + } | NETWORK family nettype filter_set { struct network *n; diff --git a/usr.sbin/bgpd/printconf.c b/usr.sbin/bgpd/printconf.c index c2e9d4452cc..a5f9d15443f 100644 --- a/usr.sbin/bgpd/printconf.c +++ b/usr.sbin/bgpd/printconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: printconf.c,v 1.97 2016/07/13 20:07:38 benno Exp $ */ +/* $OpenBSD: printconf.c,v 1.98 2016/10/05 07:38:06 phessler Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -336,6 +336,10 @@ print_network(struct network_config *n, const char *c) case NETWORK_CONNECTED: printf("%snetwork %s connected", c, print_af(n->prefix.aid)); break; + case NETWORK_RTLABEL: + printf("%snetwork %s rtlabel \"%s\"", c, + print_af(n->prefix.aid), rtlabel_id2name(n->rtlabel)); + break; default: printf("%snetwork %s/%u", c, log_addr(&n->prefix), n->prefixlen); |