Hi,

route(8) should provide the storage for struct sockaddr_dl to the
kernel when creating an IFP address.  Instead it uses inet/inet6
autodetection also for the link address type.

Currently nothing bad happens as the kernel uses only the field
sdl_index which is within the size of a sockaddr_in.

ok?

bluhm

Index: sbin/route/route.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sbin/route/route.c,v
retrieving revision 1.230
diff -u -p -r1.230 route.c
--- sbin/route/route.c  31 Mar 2019 11:30:35 -0000      1.230
+++ sbin/route/route.c  28 Aug 2019 22:01:00 -0000
@@ -579,7 +579,7 @@ newroute(int argc, char **argv)
                        case K_IFP:
                                if (!--argc)
                                        usage(1+*argv);
-                               getaddr(RTA_IFP, af, *++argv, NULL);
+                               getaddr(RTA_IFP, AF_LINK, *++argv, NULL);
                                break;
                        case K_GATEWAY:
                                if (!--argc)
@@ -798,7 +798,7 @@ getaddr(int which, int af, char *s, stru
 {
        sup su = NULL;
        struct hostent *hp;
-       int afamily, bits;
+       int aflength, afamily, bits;

        if (af == AF_UNSPEC) {
                if (strchr(s, ':') != NULL) {
@@ -809,7 +809,9 @@ getaddr(int which, int af, char *s, stru
                        aflen = sizeof(struct sockaddr_in);
                }
        }
-       afamily = af;   /* local copy of af so we can change it */
+       /* local copy of len and af so we can change it */
+       aflength = aflen;
+       afamily = af;

        rtm_addrs |= which;
        switch (which) {
@@ -824,6 +826,7 @@ getaddr(int which, int af, char *s, stru
                break;
        case RTA_IFP:
                su = &so_ifp;
+               aflength = sizeof(struct sockaddr_dl);
                afamily = AF_LINK;
                break;
        case RTA_IFA:
@@ -833,7 +836,7 @@ getaddr(int which, int af, char *s, stru
                errx(1, "internal error");
                /* NOTREACHED */
        }
-       su->sa.sa_len = aflen;
+       su->sa.sa_len = aflength;
        su->sa.sa_family = afamily;

        if (strcmp(s, "default") == 0) {

Reply via email to