Like umb(4), sppp(4) natively learns DNS information. Among the
differences between these two devices is that umb prints this
information from ifconfig(8) and sppp does not. I would like to equalize
this behaviour, and add the necessary bits to sppp(4) and ifconfig(8).

Diff below is largely based on a diff from Peter J. Philipp [0].

Comments/OK?

[0] https://marc.info/?l=openbsd-tech&m=159405677416423&w=2


diff --git sbin/ifconfig/ifconfig.c sbin/ifconfig/ifconfig.c
index e02c0550b4f..976cc9a0241 100644
--- sbin/ifconfig/ifconfig.c
+++ sbin/ifconfig/ifconfig.c
@@ -718,6 +718,7 @@ u_int       getwpacipher(const char *);
 void   print_cipherset(u_int32_t);
 
 void   spppauthinfo(struct sauthreq *, int);
+void   spppdnsinfo(struct sdnsreq *);
 
 /* Known address families */
 const struct afswtch {
@@ -5454,6 +5455,17 @@ spppauthinfo(struct sauthreq *spa, int d)
                err(1, "SIOCGSPPPPARAMS(SPPPIOGXAUTH)");
 }
 
+void
+spppdnsinfo(struct sdnsreq *spd)
+{
+       memset(spd, 0, sizeof(*spd));
+
+       ifr.ifr_data = (caddr_t)spd;
+       spd->cmd = SPPPIOGDNS;
+       if (ioctl(sock, SIOCGSPPPPARAMS, &ifr) == -1)
+               err(1, "SIOCGSPPPPARAMS(SPPPIOGDNS)");
+}
+
 void
 setspppproto(const char *val, int d)
 {
@@ -5588,6 +5600,9 @@ sppp_status(void)
 {
        struct spppreq spr;
        struct sauthreq spa;
+       struct sdnsreq spd;
+       char astr[INET_ADDRSTRLEN];
+       int i, n;
 
        bzero(&spr, sizeof(spr));
 
@@ -5627,6 +5642,16 @@ sppp_status(void)
        if (spa.flags & AUTHFLAG_NORECHALLENGE)
                printf("norechallenge ");
        putchar('\n');
+
+       spppdnsinfo(&spd);
+       for (i = 0, n = 0; i < IPCP_MAX_DNSSRV; i++) {
+               if (spd.dns[i].s_addr == INADDR_ANY)
+                       break;
+               printf("%s %s", n++ ? "" : "\tdns:",
+                   inet_ntop(AF_INET, &spd.dns[i], astr, sizeof(astr)));
+       }
+       if (n)
+               printf("\n");
 }
 
 void
diff --git sys/net/if_sppp.h sys/net/if_sppp.h
index 6b5e7d41a4a..af11526ee0a 100644
--- sys/net/if_sppp.h
+++ sys/net/if_sppp.h
@@ -82,12 +82,21 @@ struct spppreq {
        enum ppp_phase phase;   /* phase we're currently in */
 };
 
+#include <netinet/in.h>
+
+#define IPCP_MAX_DNSSRV        2
+struct sdnsreq {
+       int cmd;
+       struct in_addr dns[IPCP_MAX_DNSSRV];
+};
+
 #define SPPPIOGDEFS  ((int)(('S' << 24) + (1 << 16) + sizeof(struct spppreq)))
 #define SPPPIOSDEFS  ((int)(('S' << 24) + (2 << 16) + sizeof(struct spppreq)))
 #define SPPPIOGMAUTH ((int)(('S' << 24) + (3 << 16) + sizeof(struct sauthreq)))
 #define SPPPIOSMAUTH ((int)(('S' << 24) + (4 << 16) + sizeof(struct sauthreq)))
 #define SPPPIOGHAUTH ((int)(('S' << 24) + (5 << 16) + sizeof(struct sauthreq)))
 #define SPPPIOSHAUTH ((int)(('S' << 24) + (6 << 16) + sizeof(struct sauthreq)))
+#define SPPPIOGDNS   ((int)(('S' << 24) + (7 << 16) + sizeof(struct sdnsreq)))
 
 
 #ifdef _KERNEL
@@ -96,7 +105,6 @@ struct spppreq {
 #include <sys/task.h>
 
 #ifdef INET6
-#include <netinet/in.h>
 #include <netinet6/in6_var.h>
 #endif
 
@@ -132,7 +140,6 @@ struct sipcp {
                                  * original one here, in network byte order */
        u_int32_t req_hisaddr;  /* remote address requested (IPv4) */
        u_int32_t req_myaddr;   /* local address requested (IPv4) */
-#define IPCP_MAX_DNSSRV        2
        struct in_addr dns[IPCP_MAX_DNSSRV]; /* IPv4 DNS servers (RFC 1877) */
 #ifdef INET6
        struct in6_aliasreq req_ifid;   /* local ifid requested (IPv6) */
diff --git sys/net/if_spppsubr.c sys/net/if_spppsubr.c
index 759370e7be7..37be7ccd722 100644
--- sys/net/if_spppsubr.c
+++ sys/net/if_spppsubr.c
@@ -4561,6 +4561,23 @@ sppp_get_params(struct sppp *sp, struct ifreq *ifr)
                free(spa, M_DEVBUF, sizeof(*spa));
                break;
        }
+       case SPPPIOGDNS:
+       {
+               struct sdnsreq *spd;
+
+               spd = malloc(sizeof(*spd), M_DEVBUF, M_WAITOK);
+
+               spd->cmd = cmd;
+               memcpy(spd->dns, sp->ipcp.dns, sizeof(spd->dns));
+
+               if (copyout(spd, (caddr_t)ifr->ifr_data, sizeof(*spd)) != 0) {
+                       free(spd, M_DEVBUF, 0);
+                       return EFAULT;
+               }
+
+               free(spd, M_DEVBUF, sizeof(*spd));
+               break;
+       }
        default:
                return EINVAL;
        }

Reply via email to