minor bgpd cleanup
There is no need to limit the number of chars printed by log_reason(). log_reason() returns a strnvis cleaned buffer and so %s is good enough. While there wrap a long line. -- :wq Claudio Index: bgpd.c === RCS file: /cvs/src/usr.sbin/bgpd/bgpd.c,v retrieving revision 1.228 diff -u -p -r1.228 bgpd.c --- bgpd.c 10 May 2020 13:38:46 - 1.228 +++ bgpd.c 11 May 2020 07:58:02 - @@ -829,10 +829,10 @@ dispatch_imsg(struct imsgbuf *ibuf, int else { reconfig = 1; reconfpid = imsg.hdr.pid; - if (imsg.hdr.len == IMSG_HEADER_SIZE + REASON_LEN && - ((char *)imsg.data)[0]) - log_info("reload due to: %.*s", - REASON_LEN, log_reason(imsg.data)); + if (imsg.hdr.len == IMSG_HEADER_SIZE + + REASON_LEN && ((char *)imsg.data)[0]) + log_info("reload due to: %s", + log_reason(imsg.data)); } break; case IMSG_CTL_FIB_COUPLE:
Re: minor bgpd cleanup
ok Claudio Jeker(cje...@diehard.n-r-g.com) on 2020.02.14 14:06:37 +0100: > Move and rename copy_filterset to rde_filter.c as filterset_copy. > This way it matches the other filterset_* functions. > > OK? > -- > :wq Claudio > > Index: bgpd.h > === > RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v > retrieving revision 1.400 > diff -u -p -r1.400 bgpd.h > --- bgpd.h12 Feb 2020 10:33:56 - 1.400 > +++ bgpd.h14 Feb 2020 12:16:43 - > @@ -1182,8 +1182,6 @@ voidfree_prefixtree(struct prefixset_t > void filterlist_free(struct filter_head *); > int host(const char *, struct bgpd_addr *, u_int8_t *); > u_int32_tget_bgpid(void); > -void copy_filterset(struct filter_set_head *, > - struct filter_set_head *); > void expand_networks(struct bgpd_config *); > int prefixset_cmp(struct prefixset_item *, struct prefixset_item *); > RB_PROTOTYPE(prefixset_tree, prefixset_item, entry, prefixset_cmp); > @@ -1261,10 +1259,10 @@ int pftable_addr_remove(struct pftable_m > int pftable_commit(void); > > /* rde_filter.c */ > -void filterset_free(struct filter_set_head *); > -int filterset_cmp(struct filter_set *, struct filter_set *); > -void filterset_move(struct filter_set_head *, > - struct filter_set_head *); > +void filterset_free(struct filter_set_head *); > +int filterset_cmp(struct filter_set *, struct filter_set *); > +void filterset_move(struct filter_set_head *, struct filter_set_head *); > +void filterset_copy(struct filter_set_head *, struct filter_set_head *); > const char *filterset_name(enum action_types); > > /* rde_sets.c */ > Index: config.c > === > RCS file: /cvs/src/usr.sbin/bgpd/config.c,v > retrieving revision 1.94 > diff -u -p -r1.94 config.c > --- config.c 28 Jan 2020 15:45:46 - 1.94 > +++ config.c 14 Feb 2020 12:21:44 - > @@ -496,22 +496,6 @@ prepare_listeners(struct bgpd_config *co > } > > void > -copy_filterset(struct filter_set_head *source, struct filter_set_head *dest) > -{ > - struct filter_set *s, *t; > - > - if (source == NULL) > - return; > - > - TAILQ_FOREACH(s, source, entry) { > - if ((t = malloc(sizeof(struct filter_set))) == NULL) > - fatal(NULL); > - memcpy(t, s, sizeof(struct filter_set)); > - TAILQ_INSERT_TAIL(dest, t, entry); > - } > -} > - > -void > expand_networks(struct bgpd_config *c) > { > struct network *n, *m, *tmp; > @@ -533,8 +517,7 @@ expand_networks(struct bgpd_config *c) > memcpy(>net.prefix, >p.addr, > sizeof(m->net.prefix)); > m->net.prefixlen = psi->p.len; > - TAILQ_INIT(>net.attrset); > - copy_filterset(>net.attrset, > + filterset_copy(>net.attrset, > >net.attrset); > TAILQ_INSERT_TAIL(nw, m, entry); > } > Index: parse.y > === > RCS file: /cvs/src/usr.sbin/bgpd/parse.y,v > retrieving revision 1.403 > diff -u -p -r1.403 parse.y > --- parse.y 24 Jan 2020 05:44:05 - 1.403 > +++ parse.y 14 Feb 2020 12:21:59 - > @@ -4076,8 +4076,7 @@ expand_rule(struct filter_rule *rule, st > memcpy(r, rule, sizeof(struct > filter_rule)); > memcpy(>match, match, > sizeof(struct filter_match)); > - TAILQ_INIT(>set); > - copy_filterset(set, >set); > + filterset_copy(set, >set); > > if (rb != NULL) > strlcpy(r->rib, rb->name, > Index: rde_filter.c > === > RCS file: /cvs/src/usr.sbin/bgpd/rde_filter.c,v > retrieving revision 1.122 > diff -u -p -r1.122 rde_filter.c > --- rde_filter.c 13 Aug 2019 12:16:20 - 1.122 > +++ rde_filter.c 14 Feb 2020 12:21:28 - > @@ -502,6 +502,10 @@ filterset_cmp(struct filter_set *a, stru > return (0); > } > > +/* > + * move filterset from source to dest. dest will be initialized first. > + * After the move source is an empty list. > + */ > void > filterset_move(struct filter_set_head *source, struct filter_set_head *dest) > { > @@ -509,6 +513,26 @@ filterset_move(struct filter_set_head *s > if (source == NULL) > return; > TAILQ_CONCAT(dest, source, entry); > +} > + > +/* > + * copy filterset from source
minor bgpd cleanup
Move and rename copy_filterset to rde_filter.c as filterset_copy. This way it matches the other filterset_* functions. OK? -- :wq Claudio Index: bgpd.h === RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v retrieving revision 1.400 diff -u -p -r1.400 bgpd.h --- bgpd.h 12 Feb 2020 10:33:56 - 1.400 +++ bgpd.h 14 Feb 2020 12:16:43 - @@ -1182,8 +1182,6 @@ void free_prefixtree(struct prefixset_t void filterlist_free(struct filter_head *); inthost(const char *, struct bgpd_addr *, u_int8_t *); u_int32_t get_bgpid(void); -void copy_filterset(struct filter_set_head *, - struct filter_set_head *); void expand_networks(struct bgpd_config *); intprefixset_cmp(struct prefixset_item *, struct prefixset_item *); RB_PROTOTYPE(prefixset_tree, prefixset_item, entry, prefixset_cmp); @@ -1261,10 +1259,10 @@ int pftable_addr_remove(struct pftable_m intpftable_commit(void); /* rde_filter.c */ -voidfilterset_free(struct filter_set_head *); -int filterset_cmp(struct filter_set *, struct filter_set *); -voidfilterset_move(struct filter_set_head *, - struct filter_set_head *); +void filterset_free(struct filter_set_head *); +intfilterset_cmp(struct filter_set *, struct filter_set *); +void filterset_move(struct filter_set_head *, struct filter_set_head *); +void filterset_copy(struct filter_set_head *, struct filter_set_head *); const char *filterset_name(enum action_types); /* rde_sets.c */ Index: config.c === RCS file: /cvs/src/usr.sbin/bgpd/config.c,v retrieving revision 1.94 diff -u -p -r1.94 config.c --- config.c28 Jan 2020 15:45:46 - 1.94 +++ config.c14 Feb 2020 12:21:44 - @@ -496,22 +496,6 @@ prepare_listeners(struct bgpd_config *co } void -copy_filterset(struct filter_set_head *source, struct filter_set_head *dest) -{ - struct filter_set *s, *t; - - if (source == NULL) - return; - - TAILQ_FOREACH(s, source, entry) { - if ((t = malloc(sizeof(struct filter_set))) == NULL) - fatal(NULL); - memcpy(t, s, sizeof(struct filter_set)); - TAILQ_INSERT_TAIL(dest, t, entry); - } -} - -void expand_networks(struct bgpd_config *c) { struct network *n, *m, *tmp; @@ -533,8 +517,7 @@ expand_networks(struct bgpd_config *c) memcpy(>net.prefix, >p.addr, sizeof(m->net.prefix)); m->net.prefixlen = psi->p.len; - TAILQ_INIT(>net.attrset); - copy_filterset(>net.attrset, + filterset_copy(>net.attrset, >net.attrset); TAILQ_INSERT_TAIL(nw, m, entry); } Index: parse.y === RCS file: /cvs/src/usr.sbin/bgpd/parse.y,v retrieving revision 1.403 diff -u -p -r1.403 parse.y --- parse.y 24 Jan 2020 05:44:05 - 1.403 +++ parse.y 14 Feb 2020 12:21:59 - @@ -4076,8 +4076,7 @@ expand_rule(struct filter_rule *rule, st memcpy(r, rule, sizeof(struct filter_rule)); memcpy(>match, match, sizeof(struct filter_match)); - TAILQ_INIT(>set); - copy_filterset(set, >set); + filterset_copy(set, >set); if (rb != NULL) strlcpy(r->rib, rb->name, Index: rde_filter.c === RCS file: /cvs/src/usr.sbin/bgpd/rde_filter.c,v retrieving revision 1.122 diff -u -p -r1.122 rde_filter.c --- rde_filter.c13 Aug 2019 12:16:20 - 1.122 +++ rde_filter.c14 Feb 2020 12:21:28 - @@ -502,6 +502,10 @@ filterset_cmp(struct filter_set *a, stru return (0); } +/* + * move filterset from source to dest. dest will be initialized first. + * After the move source is an empty list. + */ void filterset_move(struct filter_set_head *source, struct filter_set_head *dest) { @@ -509,6 +513,26 @@ filterset_move(struct filter_set_head *s if (source == NULL) return; TAILQ_CONCAT(dest, source, entry); +} + +/* + * copy filterset from source to dest. dest will be initialized first. + */ +void +filterset_copy(struct filter_set_head *source, struct filter_set_head *dest) +{ + struct filter_set *s, *t; + + TAILQ_INIT(dest);
minor bgpd cleanup
When removing a peer currently there is a ugly warning: pfkey reload: no such peer: id=3 Because the peer removal happens late in the SE the parent already removed it and so the last IMSG_PFKEY_RELOAD call when stopping the session before removal has no peer to match against. So silence the warning and ignore it. Additionally reorder the peer removal in the SE to do the log and RB_REMOVE right before the free() call. OK? -- :wq Claudio Index: bgpd.c === RCS file: /cvs/src/usr.sbin/bgpd/bgpd.c,v retrieving revision 1.226 diff -u -p -r1.226 bgpd.c --- bgpd.c 1 Oct 2019 08:57:47 - 1.226 +++ bgpd.c 1 Oct 2019 14:55:29 - @@ -812,13 +812,12 @@ dispatch_imsg(struct imsgbuf *ibuf, int rv = -1; break; case IMSG_PFKEY_RELOAD: - if (idx != PFD_PIPE_SESSION) + if (idx != PFD_PIPE_SESSION) { log_warnx("pfkey reload request not from SE"); - else if ((p = getpeerbyid(conf, imsg.hdr.peerid)) == - NULL) - log_warnx("pfkey reload: no such peer: id=%u", - imsg.hdr.peerid); - else { + break; + } + p = getpeerbyid(conf, imsg.hdr.peerid); + if (p != NULL) { if (pfkey_establish(p) == -1) log_peer_warnx(>conf, "pfkey setup failed"); Index: session.c === RCS file: /cvs/src/usr.sbin/bgpd/session.c,v retrieving revision 1.394 diff -u -p -r1.394 session.c --- session.c 1 Oct 2019 11:05:30 - 1.394 +++ session.c 1 Oct 2019 14:53:52 - @@ -273,10 +273,10 @@ session_main(int debug, int verbose) session_demote(p, -1); p->conf.demote_group[0] = 0; session_stop(p, ERR_CEASE_PEER_UNCONF); - log_peer_warnx(>conf, "removed"); - RB_REMOVE(peer_head, >peers, p); timer_remove_all(p); tcp_md5_del_listener(conf, p); + log_peer_warnx(>conf, "removed"); + RB_REMOVE(peer_head, >peers, p); free(p); peer_cnt--; continue;