summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2017-01-25 00:15:39 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2017-01-25 00:15:39 +0000
commit70006cfdbb48d55071dbea8e4c8b1642d11dde62 (patch)
tree13641c2df28a47bd5919d5d1706066739d7ddedf
parent995538d2093d90c336c36e38a6d0f656f4bce2a2 (diff)
Switch rde_generate_update and rde_send_kroute to accept a struct rib instead
of the id. For this we move the rtableid into struct rib. Also move the update code in rib.c up to where the kroute code is. Makes more senses like that.
-rw-r--r--usr.sbin/bgpd/rde.c352
-rw-r--r--usr.sbin/bgpd/rde.h34
-rw-r--r--usr.sbin/bgpd/rde_decide.c6
-rw-r--r--usr.sbin/bgpd/rde_rib.c6
4 files changed, 199 insertions, 199 deletions
diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c
index 1c42fe2f557..1a1a19b41c5 100644
--- a/usr.sbin/bgpd/rde.c
+++ b/usr.sbin/bgpd/rde.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.c,v 1.359 2017/01/24 23:38:12 claudio Exp $ */
+/* $OpenBSD: rde.c,v 1.360 2017/01/25 00:15:38 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -724,7 +724,7 @@ rde_dispatch_imsg_parent(struct imsgbuf *ibuf)
rib = rib_find(rn.name);
if (rib == NULL)
rib = rib_new(rn.name, rn.rtableid, rn.flags);
- else if (rib->rtableid != rn.rtableid ||
+ else if (rib->rib.rtableid != rn.rtableid ||
(rib->rib.flags & F_RIB_HASNOFIB) !=
(rib->rib.flags & F_RIB_HASNOFIB)) {
struct filter_head *in_rules;
@@ -2461,7 +2461,7 @@ rde_rdomain_import(struct rde_aspath *asp, struct rdomain *rd)
}
void
-rde_send_kroute(struct prefix *new, struct prefix *old, u_int16_t ribid)
+rde_send_kroute(struct rib *rib, struct prefix *new, struct prefix *old)
{
struct kroute_full kr;
struct bgpd_addr addr;
@@ -2501,7 +2501,7 @@ rde_send_kroute(struct prefix *new, struct prefix *old, u_int16_t ribid)
switch (addr.aid) {
case AID_VPN_IPv4:
- if (ribid != 1)
+ if (rib->flags & F_RIB_LOCAL)
/* not Loc-RIB, no update for VPNs */
break;
@@ -2522,7 +2522,7 @@ rde_send_kroute(struct prefix *new, struct prefix *old, u_int16_t ribid)
}
break;
default:
- if (imsg_compose(ibuf_main, type, ribs[ribid].rtableid, 0, -1,
+ if (imsg_compose(ibuf_main, type, rib->rtableid, 0, -1,
&kr, sizeof(kr)) == -1)
fatal("%s %d imsg_compose error", __func__, __LINE__);
break;
@@ -2530,6 +2530,177 @@ rde_send_kroute(struct prefix *new, struct prefix *old, u_int16_t ribid)
}
/*
+ * update specific functions
+ */
+void
+rde_generate_updates(struct rib *rib, struct prefix *new, struct prefix *old)
+{
+ struct rde_peer *peer;
+
+ /*
+ * If old is != NULL we know it was active and should be removed.
+ * If new is != NULL we know it is reachable and then we should
+ * generate an update.
+ */
+ if (old == NULL && new == NULL)
+ return;
+
+ LIST_FOREACH(peer, &peerlist, peer_l) {
+ if (peer->conf.id == 0)
+ continue;
+ if (&peer->rib->rib != rib)
+ continue;
+ if (peer->state != PEER_UP)
+ continue;
+ up_generate_updates(out_rules, peer, new, old);
+ }
+}
+
+u_char queue_buf[4096];
+
+void
+rde_up_dump_upcall(struct rib_entry *re, void *ptr)
+{
+ struct rde_peer *peer = ptr;
+
+ if (re_rib(re) != &peer->rib->rib)
+ fatalx("King Bula: monstrous evil horror.");
+ if (re->active == NULL)
+ return;
+ up_generate_updates(out_rules, peer, re->active, NULL);
+}
+
+void
+rde_update_queue_runner(void)
+{
+ struct rde_peer *peer;
+ int r, sent, max = RDE_RUNNER_ROUNDS, eor = 0;
+ u_int16_t len, wd_len, wpos;
+
+ len = sizeof(queue_buf) - MSGSIZE_HEADER;
+ do {
+ sent = 0;
+ LIST_FOREACH(peer, &peerlist, peer_l) {
+ if (peer->conf.id == 0)
+ continue;
+ if (peer->state != PEER_UP)
+ continue;
+ /* first withdraws */
+ wpos = 2; /* reserve space for the length field */
+ r = up_dump_prefix(queue_buf + wpos, len - wpos - 2,
+ &peer->withdraws[AID_INET], peer);
+ wd_len = r;
+ /* write withdraws length filed */
+ wd_len = htons(wd_len);
+ memcpy(queue_buf, &wd_len, 2);
+ wpos += r;
+
+ /* now bgp path attributes */
+ r = up_dump_attrnlri(queue_buf + wpos, len - wpos,
+ peer);
+ switch (r) {
+ case -1:
+ eor = 1;
+ if (wd_len == 0) {
+ /* no withdraws queued just send EoR */
+ peer_send_eor(peer, AID_INET);
+ continue;
+ }
+ break;
+ case 2:
+ if (wd_len == 0) {
+ /*
+ * No packet to send. No withdraws and
+ * no path attributes. Skip.
+ */
+ continue;
+ }
+ /* FALLTHROUGH */
+ default:
+ wpos += r;
+ break;
+ }
+
+ /* finally send message to SE */
+ if (imsg_compose(ibuf_se, IMSG_UPDATE, peer->conf.id,
+ 0, -1, queue_buf, wpos) == -1)
+ fatal("%s %d imsg_compose error", __func__,
+ __LINE__);
+ sent++;
+ if (eor) {
+ eor = 0;
+ peer_send_eor(peer, AID_INET);
+ }
+ }
+ max -= sent;
+ } while (sent != 0 && max > 0);
+}
+
+void
+rde_update6_queue_runner(u_int8_t aid)
+{
+ struct rde_peer *peer;
+ u_char *b;
+ int r, sent, max = RDE_RUNNER_ROUNDS / 2;
+ u_int16_t len;
+
+ /* first withdraws ... */
+ do {
+ sent = 0;
+ LIST_FOREACH(peer, &peerlist, peer_l) {
+ if (peer->conf.id == 0)
+ continue;
+ if (peer->state != PEER_UP)
+ continue;
+ len = sizeof(queue_buf) - MSGSIZE_HEADER;
+ b = up_dump_mp_unreach(queue_buf, &len, peer, aid);
+
+ if (b == NULL)
+ continue;
+ /* finally send message to SE */
+ if (imsg_compose(ibuf_se, IMSG_UPDATE, peer->conf.id,
+ 0, -1, b, len) == -1)
+ fatal("%s %d imsg_compose error", __func__,
+ __LINE__);
+ sent++;
+ }
+ max -= sent;
+ } while (sent != 0 && max > 0);
+
+ /* ... then updates */
+ max = RDE_RUNNER_ROUNDS / 2;
+ do {
+ sent = 0;
+ LIST_FOREACH(peer, &peerlist, peer_l) {
+ if (peer->conf.id == 0)
+ continue;
+ if (peer->state != PEER_UP)
+ continue;
+ len = sizeof(queue_buf) - MSGSIZE_HEADER;
+ r = up_dump_mp_reach(queue_buf, &len, peer, aid);
+ switch (r) {
+ case -2:
+ continue;
+ case -1:
+ peer_send_eor(peer, aid);
+ continue;
+ default:
+ b = queue_buf + r;
+ break;
+ }
+
+ /* finally send message to SE */
+ if (imsg_compose(ibuf_se, IMSG_UPDATE, peer->conf.id,
+ 0, -1, b, len) == -1)
+ fatal("%s %d imsg_compose error", __func__,
+ __LINE__);
+ sent++;
+ }
+ max -= sent;
+ } while (sent != 0 && max > 0);
+}
+
+/*
* pf table specific functions
*/
void
@@ -2861,177 +3032,6 @@ done:
}
/*
- * update specific functions
- */
-u_char queue_buf[4096];
-
-void
-rde_up_dump_upcall(struct rib_entry *re, void *ptr)
-{
- struct rde_peer *peer = ptr;
-
- if (re_rib(re) != &peer->rib->rib)
- fatalx("King Bula: monstrous evil horror.");
- if (re->active == NULL)
- return;
- up_generate_updates(out_rules, peer, re->active, NULL);
-}
-
-void
-rde_generate_updates(u_int16_t ribid, struct prefix *new, struct prefix *old)
-{
- struct rde_peer *peer;
-
- /*
- * If old is != NULL we know it was active and should be removed.
- * If new is != NULL we know it is reachable and then we should
- * generate an update.
- */
- if (old == NULL && new == NULL)
- return;
-
- LIST_FOREACH(peer, &peerlist, peer_l) {
- if (peer->conf.id == 0)
- continue;
- if (peer->rib->rib.id != ribid)
- continue;
- if (peer->state != PEER_UP)
- continue;
- up_generate_updates(out_rules, peer, new, old);
- }
-}
-
-void
-rde_update_queue_runner(void)
-{
- struct rde_peer *peer;
- int r, sent, max = RDE_RUNNER_ROUNDS, eor = 0;
- u_int16_t len, wd_len, wpos;
-
- len = sizeof(queue_buf) - MSGSIZE_HEADER;
- do {
- sent = 0;
- LIST_FOREACH(peer, &peerlist, peer_l) {
- if (peer->conf.id == 0)
- continue;
- if (peer->state != PEER_UP)
- continue;
- /* first withdraws */
- wpos = 2; /* reserve space for the length field */
- r = up_dump_prefix(queue_buf + wpos, len - wpos - 2,
- &peer->withdraws[AID_INET], peer);
- wd_len = r;
- /* write withdraws length filed */
- wd_len = htons(wd_len);
- memcpy(queue_buf, &wd_len, 2);
- wpos += r;
-
- /* now bgp path attributes */
- r = up_dump_attrnlri(queue_buf + wpos, len - wpos,
- peer);
- switch (r) {
- case -1:
- eor = 1;
- if (wd_len == 0) {
- /* no withdraws queued just send EoR */
- peer_send_eor(peer, AID_INET);
- continue;
- }
- break;
- case 2:
- if (wd_len == 0) {
- /*
- * No packet to send. No withdraws and
- * no path attributes. Skip.
- */
- continue;
- }
- /* FALLTHROUGH */
- default:
- wpos += r;
- break;
- }
-
- /* finally send message to SE */
- if (imsg_compose(ibuf_se, IMSG_UPDATE, peer->conf.id,
- 0, -1, queue_buf, wpos) == -1)
- fatal("%s %d imsg_compose error", __func__,
- __LINE__);
- sent++;
- if (eor) {
- eor = 0;
- peer_send_eor(peer, AID_INET);
- }
- }
- max -= sent;
- } while (sent != 0 && max > 0);
-}
-
-void
-rde_update6_queue_runner(u_int8_t aid)
-{
- struct rde_peer *peer;
- u_char *b;
- int r, sent, max = RDE_RUNNER_ROUNDS / 2;
- u_int16_t len;
-
- /* first withdraws ... */
- do {
- sent = 0;
- LIST_FOREACH(peer, &peerlist, peer_l) {
- if (peer->conf.id == 0)
- continue;
- if (peer->state != PEER_UP)
- continue;
- len = sizeof(queue_buf) - MSGSIZE_HEADER;
- b = up_dump_mp_unreach(queue_buf, &len, peer, aid);
-
- if (b == NULL)
- continue;
- /* finally send message to SE */
- if (imsg_compose(ibuf_se, IMSG_UPDATE, peer->conf.id,
- 0, -1, b, len) == -1)
- fatal("%s %d imsg_compose error", __func__,
- __LINE__);
- sent++;
- }
- max -= sent;
- } while (sent != 0 && max > 0);
-
- /* ... then updates */
- max = RDE_RUNNER_ROUNDS / 2;
- do {
- sent = 0;
- LIST_FOREACH(peer, &peerlist, peer_l) {
- if (peer->conf.id == 0)
- continue;
- if (peer->state != PEER_UP)
- continue;
- len = sizeof(queue_buf) - MSGSIZE_HEADER;
- r = up_dump_mp_reach(queue_buf, &len, peer, aid);
- switch (r) {
- case -2:
- continue;
- case -1:
- peer_send_eor(peer, aid);
- continue;
- default:
- b = queue_buf + r;
- break;
- }
-
- /* finally send message to SE */
- if (imsg_compose(ibuf_se, IMSG_UPDATE, peer->conf.id,
- 0, -1, b, len) == -1)
- fatal("%s %d imsg_compose error", __func__,
- __LINE__);
- sent++;
- }
- max -= sent;
- } while (sent != 0 && max > 0);
-}
-
-/*
* generic helper function
*/
u_int32_t
diff --git a/usr.sbin/bgpd/rde.h b/usr.sbin/bgpd/rde.h
index d2228b6808a..a51637cebd0 100644
--- a/usr.sbin/bgpd/rde.h
+++ b/usr.sbin/bgpd/rde.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.h,v 1.158 2017/01/24 23:38:12 claudio Exp $ */
+/* $OpenBSD: rde.h,v 1.159 2017/01/25 00:15:38 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> and
@@ -288,6 +288,7 @@ struct rib_entry {
struct rib {
struct rib_tree tree;
+ u_int rtableid;
u_int16_t flags;
u_int16_t id;
};
@@ -297,7 +298,6 @@ struct rib_desc {
struct rib rib;
struct filter_head *in_rules;
struct filter_head *in_rules_tmp;
- u_int rtableid;
enum reconf_action state;
};
@@ -313,24 +313,24 @@ extern struct rde_memstats rdemem;
/* prototypes */
/* mrt.c */
-int mrt_dump_v2_hdr(struct mrt *, struct bgpd_config *,
+int mrt_dump_v2_hdr(struct mrt *, struct bgpd_config *,
struct rde_peer_head *);
-void mrt_dump_upcall(struct rib_entry *, void *);
-void mrt_done(void *);
+void mrt_dump_upcall(struct rib_entry *, void *);
+void mrt_done(void *);
/* rde.c */
-void rde_send_kroute(struct prefix *, struct prefix *, u_int16_t);
-void rde_send_nexthop(struct bgpd_addr *, int);
-void rde_send_pftable(u_int16_t, struct bgpd_addr *,
- u_int8_t, int);
-void rde_send_pftable_commit(void);
-
-void rde_generate_updates(u_int16_t, struct prefix *,
- struct prefix *);
-u_int32_t rde_local_as(void);
-int rde_noevaluate(void);
-int rde_decisionflags(void);
-int rde_as4byte(struct rde_peer *);
+void rde_send_kroute(struct rib *, struct prefix *, struct prefix *);
+void rde_send_nexthop(struct bgpd_addr *, int);
+void rde_send_pftable(u_int16_t, struct bgpd_addr *,
+ u_int8_t, int);
+void rde_send_pftable_commit(void);
+
+void rde_generate_updates(struct rib *, struct prefix *,
+ struct prefix *);
+u_int32_t rde_local_as(void);
+int rde_noevaluate(void);
+int rde_decisionflags(void);
+int rde_as4byte(struct rde_peer *);
/* rde_attr.c */
int attr_write(void *, u_int16_t, u_int8_t, u_int8_t, void *,
diff --git a/usr.sbin/bgpd/rde_decide.c b/usr.sbin/bgpd/rde_decide.c
index 84d11c55c92..2e5c2ab884d 100644
--- a/usr.sbin/bgpd/rde_decide.c
+++ b/usr.sbin/bgpd/rde_decide.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde_decide.c,v 1.65 2017/01/24 23:38:12 claudio Exp $ */
+/* $OpenBSD: rde_decide.c,v 1.66 2017/01/25 00:15:38 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
@@ -288,9 +288,9 @@ prefix_evaluate(struct prefix *p, struct rib_entry *re)
* but remember that xp may be NULL aka ineligible.
* Additional decision may be made by the called functions.
*/
- rde_generate_updates(re_rib(re)->id, xp, re->active);
+ rde_generate_updates(re_rib(re), xp, re->active);
if ((re_rib(re)->flags & F_RIB_NOFIB) == 0)
- rde_send_kroute(xp, re->active, re_rib(re)->id);
+ rde_send_kroute(re_rib(re), xp, re->active);
re->active = xp;
if (xp != NULL)
diff --git a/usr.sbin/bgpd/rde_rib.c b/usr.sbin/bgpd/rde_rib.c
index 54d3dfde91d..85d66398a2a 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.151 2017/01/24 23:38:12 claudio Exp $ */
+/* $OpenBSD: rde_rib.c,v 1.152 2017/01/25 00:15:38 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
@@ -101,7 +101,7 @@ rib_new(char *name, u_int rtableid, u_int16_t flags)
ribs[id].state = RECONF_REINIT;
ribs[id].rib.id = id;
ribs[id].rib.flags = flags;
- ribs[id].rtableid = rtableid;
+ ribs[id].rib.rtableid = rtableid;
ribs[id].in_rules = calloc(1, sizeof(struct filter_head));
if (ribs[id].in_rules == NULL)
@@ -934,7 +934,7 @@ prefix_updateall(struct rde_aspath *asp, enum nexthop_state state,
*/
if ((re_rib(p->re)->flags & F_RIB_NOFIB) == 0 &&
p == p->re->active)
- rde_send_kroute(p, NULL, re_rib(p->re)->id);
+ rde_send_kroute(re_rib(p->re), p, NULL);
continue;
}