i'm hacking on pfsync(4) at the moment, and i wasted way too much time
wondering how i broke the pfsync ioctls after i didn't the pfsync_status
output. turns out if you don't have a sync interface set, it skips
output.

i think it's useful to show that the sync interface is not set, so i
came up with this.

an unconfigured pfsync interface looks like this with my diff:

pfsync0: flags=0<> mtu 1500
        index 5 priority 0 llprio 3
        pfsync: syncdev none maxupd 128 defer off
        groups: carp pfsync

Index: ifconfig.c
===================================================================
RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.457
diff -u -p -r1.457 ifconfig.c
--- ifconfig.c  26 Oct 2022 17:06:31 -0000      1.457
+++ ifconfig.c  8 Nov 2022 14:06:01 -0000
@@ -5086,22 +5086,23 @@ setpfsync_defer(const char *val, int d)
 void
 pfsync_status(void)
 {
-       struct pfsyncreq preq;
+       struct pfsyncreq pfsyncr;
+       const char *syncif = "none";
 
-       bzero(&preq, sizeof(struct pfsyncreq));
-       ifr.ifr_data = (caddr_t)&preq;
+       bzero(&pfsyncr, sizeof(pfsyncr));
+       ifr.ifr_data = (caddr_t)&pfsyncr;
 
        if (ioctl(sock, SIOCGETPFSYNC, (caddr_t)&ifr) == -1)
                return;
 
-       if (preq.pfsyncr_syncdev[0] != '\0') {
-               printf("\tpfsync: syncdev: %s ", preq.pfsyncr_syncdev);
-               if (preq.pfsyncr_syncpeer.s_addr != htonl(INADDR_PFSYNC_GROUP))
-                       printf("syncpeer: %s ",
-                           inet_ntoa(preq.pfsyncr_syncpeer));
-               printf("maxupd: %d ", preq.pfsyncr_maxupdates);
-               printf("defer: %s\n", preq.pfsyncr_defer ? "on" : "off");
-       }
+       if (pfsyncr.pfsyncr_syncdev[0] != '\0')
+               syncif = pfsyncr.pfsyncr_syncdev;
+
+       printf("\tpfsync: syncdev %s ", syncif);
+       if (pfsyncr.pfsyncr_syncpeer.s_addr != htonl(INADDR_PFSYNC_GROUP))
+               printf("syncpeer %s ", inet_ntoa(pfsyncr.pfsyncr_syncpeer));
+       printf("maxupd %d ", pfsyncr.pfsyncr_maxupdates);
+       printf("defer %s\n", pfsyncr.pfsyncr_defer ? "on" : "off");
 }
 
 void

Reply via email to