Re: bgpd move struct kif to kroute.c

2022-06-23 Thread Theo Buehler
On Thu, Jun 23, 2022 at 12:10:36PM +0200, Claudio Jeker wrote:
> 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.

ok tb



bgpd move struct kif to kroute.c

2022-06-23 Thread Claudio Jeker
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 -  1.247
+++ bgpd.c  23 Jun 2022 10:05:13 -
@@ -935,11 +935,11 @@ dispatch_imsg(struct imsgbuf *ibuf, int 
else
kr_show_route();
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 -  1.436
+++ bgpd.h  23 Jun 2022 10:05:13 -
@@ -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_intrdomain;
-   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.c23 Jun 2022 09:54:31 -  1.266
+++ kroute.c23 Jun 2022 10:05:14 -
@@ -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_intrdomain;
+   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, , sizeof(sdon));
+}
+   
 void
 kr_ifinfo(char *ifname)
 {
@@ -1209,8 +1231,7 @@ kr_ifinfo(char *ifname)
 
RB_FOREACH(kif, kif_tree, )
if (!strcmp(ifname, kif->k.ifname)) {
-   send_imsg_session(IMSG_IFINFO, 0,
-   >k, sizeof(kif->k));
+   kr_send_dependon(>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(>k);
 
-   send_imsg_session(IMSG_IFINFO, 0, >k, sizeof(kif->k));
+   kr_send_dependon(>k);
 
if ((reachable = kif_validate(>k)) == kif->k.nh_reachable)
return; /* nothing changed wrt nexthop validity */
Index: session.c
===
RCS file: