struct kif is internal to the kroute code with the exception of the
'depend on' tracking message. So create an extra object for this message
and move struct kif to kroute.c.

I renamed the IMSG just to make it clear what this is about and to make
sure I did not miss something.

After that struct kif_node will follow struct kroute_node.
-- 
:wq Claudio

Index: bgpd.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.c,v
retrieving revision 1.247
diff -u -p -r1.247 bgpd.c
--- bgpd.c      22 Jun 2022 14:56:11 -0000      1.247
+++ bgpd.c      23 Jun 2022 10:05:13 -0000
@@ -935,11 +935,11 @@ dispatch_imsg(struct imsgbuf *ibuf, int 
                        else
                                kr_show_route(&imsg);
                        break;
-               case IMSG_IFINFO:
+               case IMSG_SESSION_DEPENDON:
                        if (idx != PFD_PIPE_SESSION)
-                               log_warnx("IFINFO request not from SE");
+                               log_warnx("DEPENDON request not from SE");
                        else if (imsg.hdr.len != IMSG_HEADER_SIZE + IFNAMSIZ)
-                               log_warnx("IFINFO request with wrong len");
+                               log_warnx("DEPENDON request with wrong len");
                        else
                                kr_ifinfo(imsg.data);
                        break;
Index: bgpd.h
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
retrieving revision 1.436
diff -u -p -r1.436 bgpd.h
--- bgpd.h      23 Jun 2022 07:43:37 -0000      1.436
+++ bgpd.h      23 Jun 2022 10:05:13 -0000
@@ -572,6 +572,7 @@ enum imsg_type {
        IMSG_SESSION_STALE,
        IMSG_SESSION_FLUSH,
        IMSG_SESSION_RESTARTED,
+       IMSG_SESSION_DEPENDON,
        IMSG_PFKEY_RELOAD,
        IMSG_MRT_OPEN,
        IMSG_MRT_REOPEN,
@@ -586,7 +587,6 @@ enum imsg_type {
        IMSG_PFTABLE_REMOVE,
        IMSG_PFTABLE_COMMIT,
        IMSG_REFRESH,
-       IMSG_IFINFO,
        IMSG_DEMOTE,
        IMSG_XON,
        IMSG_XOFF
@@ -699,15 +699,8 @@ struct kroute_nexthop {
        uint8_t                 netlen;
 };
 
-struct kif {
+struct session_dependon {
        char                     ifname[IFNAMSIZ];
-       uint64_t                 baudrate;
-       u_int                    rdomain;
-       int                      flags;
-       u_short                  ifindex;
-       uint8_t                  if_type;
-       uint8_t                  link_state;
-       uint8_t                  nh_reachable;  /* for nexthop verification */
        uint8_t                  depend_state;  /* for session depend on */
 };
 
Index: kroute.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/kroute.c,v
retrieving revision 1.266
diff -u -p -r1.266 kroute.c
--- kroute.c    23 Jun 2022 09:54:31 -0000      1.266
+++ kroute.c    23 Jun 2022 10:05:14 -0000
@@ -107,6 +107,18 @@ struct kif_kr6 {
 LIST_HEAD(kif_kr_head, kif_kr);
 LIST_HEAD(kif_kr6_head, kif_kr6);
 
+struct kif {
+       char                     ifname[IFNAMSIZ];
+       uint64_t                 baudrate;
+       u_int                    rdomain;
+       int                      flags;
+       u_short                  ifindex;
+       uint8_t                  if_type;
+       uint8_t                  link_state;
+       uint8_t                  nh_reachable;  /* for nexthop verification */
+       uint8_t                  depend_state;  /* for session depend on */
+};
+
 struct kif_node {
        RB_ENTRY(kif_node)       entry;
        struct kif               k;
@@ -1202,6 +1214,16 @@ kr_show_route(struct imsg *imsg)
        send_imsg_session(IMSG_CTL_END, imsg->hdr.pid, NULL, 0);
 }
 
+static void
+kr_send_dependon(struct kif *kif)
+{
+       struct session_dependon sdon = { 0 };
+
+       strlcpy(sdon.ifname, kif->ifname, sizeof(sdon.ifname));
+       sdon.depend_state = kif->depend_state;
+       send_imsg_session(IMSG_SESSION_DEPENDON, 0, &sdon, sizeof(sdon));
+}
+       
 void
 kr_ifinfo(char *ifname)
 {
@@ -1209,8 +1231,7 @@ kr_ifinfo(char *ifname)
 
        RB_FOREACH(kif, kif_tree, &kit)
                if (!strcmp(ifname, kif->k.ifname)) {
-                       send_imsg_session(IMSG_IFINFO, 0,
-                           &kif->k, sizeof(kif->k));
+                       kr_send_dependon(&kif->k);
                        return;
                }
 }
@@ -2736,7 +2757,7 @@ if_change(u_short ifindex, int flags, st
        kif->k.baudrate = ifd->ifi_baudrate;
        kif->k.depend_state = kif_depend_state(&kif->k);
 
-       send_imsg_session(IMSG_IFINFO, 0, &kif->k, sizeof(kif->k));
+       kr_send_dependon(&kif->k);
 
        if ((reachable = kif_validate(&kif->k)) == kif->k.nh_reachable)
                return;         /* nothing changed wrt nexthop validity */
Index: session.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/session.c,v
retrieving revision 1.428
diff -u -p -r1.428 session.c
--- session.c   19 Jun 2022 10:30:10 -0000      1.428
+++ session.c   23 Jun 2022 10:05:14 -0000
@@ -569,7 +569,7 @@ init_peer(struct peer *p)
        p->fd = p->wbuf.fd = -1;
 
        if (p->conf.if_depend[0])
-               imsg_compose(ibuf_main, IMSG_IFINFO, 0, 0, -1,
+               imsg_compose(ibuf_main, IMSG_SESSION_DEPENDON, 0, 0, -1,
                    p->conf.if_depend, sizeof(p->conf.if_depend));
        else
                p->depend_ok = 1;
@@ -2823,7 +2823,7 @@ session_dispatch_imsg(struct imsgbuf *ib
        struct imsgbuf          *i;
        struct peer             *p;
        struct listen_addr      *la, *nla;
-       struct kif              *kif;
+       struct session_dependon *sdon;
        u_char                  *data;
        int                      n, fd, depend_ok, restricted;
        uint16_t                 t;
@@ -2928,7 +2928,7 @@ session_dispatch_imsg(struct imsgbuf *ib
                                fatalx("reconf request not from parent");
                        if (imsg.hdr.len != IMSG_HEADER_SIZE +
                            sizeof(restricted))
-                               fatalx("IFINFO imsg with wrong len");
+                               fatalx("RECONF_CTRL imsg with wrong len");
                        memcpy(&restricted, imsg.data, sizeof(restricted));
                        if (imsg.fd == -1) {
                                log_warnx("expected to receive fd for control "
@@ -3000,17 +3000,17 @@ session_dispatch_imsg(struct imsgbuf *ib
                         * the peer config sent in merge_peers().
                         */
                        break;
-               case IMSG_IFINFO:
+               case IMSG_SESSION_DEPENDON:
                        if (idx != PFD_PIPE_MAIN)
                                fatalx("IFINFO message not from parent");
                        if (imsg.hdr.len != IMSG_HEADER_SIZE +
-                           sizeof(struct kif))
-                               fatalx("IFINFO imsg with wrong len");
-                       kif = imsg.data;
-                       depend_ok = kif->depend_state;
+                           sizeof(struct session_dependon))
+                               fatalx("DEPENDON imsg with wrong len");
+                       sdon = imsg.data;
+                       depend_ok = sdon->depend_state;
 
                        RB_FOREACH(p, peer_head, &conf->peers)
-                               if (!strcmp(p->conf.if_depend, kif->ifname)) {
+                               if (!strcmp(p->conf.if_depend, sdon->ifname)) {
                                        if (depend_ok && !p->depend_ok) {
                                                p->depend_ok = depend_ok;
                                                bgp_fsm(p, EVNT_START);

Reply via email to