From owner-freebsd-net Fri Oct 19 16:24:57 2001 Delivered-To: freebsd-net@freebsd.org Received: from flood.ping.uio.no (flood.ping.uio.no [129.240.78.31]) by hub.freebsd.org (Postfix) with ESMTP id 177CB37B403 for ; Fri, 19 Oct 2001 16:24:42 -0700 (PDT) Received: by flood.ping.uio.no (Postfix, from userid 2602) id 4348314C2E; Sat, 20 Oct 2001 01:24:40 +0200 (CEST) X-URL: http://www.ofug.org/~des/ X-Disclaimer: The views expressed in this message do not necessarily coincide with those of any organisation or company with which I am or have been affiliated. To: net@freebsd.org Subject: Small tweak to in_control() From: Dag-Erling Smorgrav Date: 20 Oct 2001 01:24:39 +0200 Message-ID: Lines: 22 User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org --=-=-= The attached patch makes sure that the address family on an in_ifaddr's netmask sockaddr is set to AF_INET. Apparently none of our kernel or userland code cares about this, but certain binaries from That Other OS, and possibly also applicatins ported from other OSes, expect the sockaddr returned by SIOCGIFNETMASK to have a valid address family. As far as I can determine, these changes are sufficient to ensure that ia_sockmask.sa_family is always AF_INET, but I'm not 100% certain, so I've added a KASSERT that checks this before returning from in_control(). I also don't know if similar changes are required in the IPv6 code. Comments? Objections? DES -- Dag-Erling Smorgrav - des@ofug.org --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=sockmask.diff Index: sys/netinet/in.c =================================================================== RCS file: /home/ncvs/src/sys/netinet/in.c,v retrieving revision 1.59 diff -u -r1.59 in.c --- sys/netinet/in.c 1 Oct 2001 18:07:08 -0000 1.59 +++ sys/netinet/in.c 19 Oct 2001 23:15:31 -0000 @@ -198,7 +198,6 @@ struct in_aliasreq *ifra = (struct in_aliasreq *)data; struct sockaddr_in oldaddr; int error, hostIsNew, maskIsNew, s; - u_long i; switch (cmd) { case SIOCALIFADDR: @@ -286,6 +285,7 @@ ifa->ifa_dstaddr = (struct sockaddr *)&ia->ia_dstaddr; ifa->ifa_netmask = (struct sockaddr *)&ia->ia_sockmask; ia->ia_sockmask.sin_len = 8; + ia->ia_sockmask.sin_family = AF_INET; if (ifp->if_flags & IFF_BROADCAST) { ia->ia_broadaddr.sin_len = sizeof(ia->ia_addr); ia->ia_broadaddr.sin_family = AF_INET; @@ -362,8 +362,8 @@ (struct sockaddr_in *) &ifr->ifr_addr, 1)); case SIOCSIFNETMASK: - i = ifra->ifra_addr.sin_addr.s_addr; - ia->ia_subnetmask = ntohl(ia->ia_sockmask.sin_addr.s_addr = i); + ia->ia_sockmask.sin_addr = ifra->ifra_addr.sin_addr; + ia->ia_subnetmask = ntohl(ia->ia_sockmask.sin_addr.s_addr); break; case SIOCAIFADDR: @@ -381,6 +381,7 @@ if (ifra->ifra_mask.sin_len) { in_ifscrub(ifp, ia); ia->ia_sockmask = ifra->ifra_mask; + ia->ia_sockmask.sin_family = AF_INET; ia->ia_subnetmask = ntohl(ia->ia_sockmask.sin_addr.s_addr); maskIsNew = 1; @@ -439,6 +440,10 @@ return (EOPNOTSUPP); return ((*ifp->if_ioctl)(ifp, cmd, data)); } + + KASSERT(ia == NULL || ia->ia_sockmask.sin_family == AF_INET, + (__FUNCTION__ "(): ia_sockmask is not AF_INET")); + return (0); } --=-=-=-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message