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 -0000       1.226
+++ bgpd.c      1 Oct 2019 14:55:29 -0000
@@ -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(&p->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 -0000       1.394
+++ session.c   1 Oct 2019 14:53:52 -0000
@@ -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(&p->conf, "removed");
-                                       RB_REMOVE(peer_head, &conf->peers, p);
                                        timer_remove_all(p);
                                        tcp_md5_del_listener(conf, p);
+                                       log_peer_warnx(&p->conf, "removed");
+                                       RB_REMOVE(peer_head, &conf->peers, p);
                                        free(p);
                                        peer_cnt--;
                                        continue;

Reply via email to