Move struct kif from bgpd.h to kroute.c
authorclaudio <claudio@openbsd.org>
Thu, 23 Jun 2022 13:09:03 +0000 (13:09 +0000)
committerclaudio <claudio@openbsd.org>
Thu, 23 Jun 2022 13:09:03 +0000 (13:09 +0000)
The only user of struct kif was the session engine for the 'depend on'
feature. Switch the imsg exchange to a new struct session_dependon and
rename the IMSG as well.
OK tb@

usr.sbin/bgpd/bgpd.c
usr.sbin/bgpd/bgpd.h
usr.sbin/bgpd/kroute.c
usr.sbin/bgpd/session.c

index 68d393e..2d97a7a 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: bgpd.c,v 1.247 2022/06/22 14:56:11 claudio Exp $ */
+/*     $OpenBSD: bgpd.c,v 1.248 2022/06/23 13:09:03 claudio Exp $ */
 
 /*
  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -935,11 +935,11 @@ dispatch_imsg(struct imsgbuf *ibuf, int idx, struct bgpd_config *conf)
                        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 55cdd56..db9f354 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: bgpd.h,v 1.436 2022/06/23 07:43:37 claudio Exp $ */
+/*     $OpenBSD: bgpd.h,v 1.437 2022/06/23 13:09:03 claudio Exp $ */
 
 /*
  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -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 0a32afa..6579a50 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kroute.c,v 1.267 2022/06/23 10:22:23 claudio Exp $ */
+/*     $OpenBSD: kroute.c,v 1.268 2022/06/23 13:09:03 claudio Exp $ */
 
 /*
  * Copyright (c) 2022 Claudio Jeker <claudio@openbsd.org>
@@ -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, struct if_data *ifd)
        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 1bb784a..258ff19 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: session.c,v 1.428 2022/06/19 10:30:10 claudio Exp $ */
+/*     $OpenBSD: session.c,v 1.429 2022/06/23 13:09:03 claudio Exp $ */
 
 /*
  * Copyright (c) 2003, 2004, 2005 Henning Brauer <henning@openbsd.org>
@@ -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 *ibuf, int idx, u_int *listener_cnt)
        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 *ibuf, int idx, u_int *listener_cnt)
                                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 *ibuf, int idx, u_int *listener_cnt)
                         * 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);