Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/netinet inet: Add support for IPv4 /31 prefixes, as desc...



details:   https://anonhg.NetBSD.org/src/rev/094ee408f726
branches:  trunk
changeset: 847313:094ee408f726
user:      roy <roy%NetBSD.org@localhost>
date:      Wed Dec 18 00:49:15 2019 +0000

description:
inet: Add support for IPv4 /31 prefixes, as described in RFC 3021.

To run a /31 network, participating hosts MUST drop support
for directed broadcasts, and treat the first and last addresses
on subnet as unicast. The broadcast address for the prefix
should be the link local broadcast address, INADDR_BROADCAST.

Taken from FreeBSD, r226402.
Fixes PR kern/51388.

diffstat:

 sys/netinet/in.c |  21 ++++++++++++++-------
 sys/netinet/in.h |   4 +++-
 2 files changed, 17 insertions(+), 8 deletions(-)

diffs (68 lines):

diff -r 3e964724f9c6 -r 094ee408f726 sys/netinet/in.c
--- a/sys/netinet/in.c  Tue Dec 17 19:12:50 2019 +0000
+++ b/sys/netinet/in.c  Wed Dec 18 00:49:15 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in.c,v 1.235 2019/09/25 09:53:38 ozaki-r Exp $ */
+/*     $NetBSD: in.c,v 1.236 2019/12/18 00:49:15 roy Exp $     */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.235 2019/09/25 09:53:38 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in.c,v 1.236 2019/12/18 00:49:15 roy Exp $");
 
 #include "arp.h"
 
@@ -1219,10 +1219,15 @@
 
        ia->ia_ifa.ifa_metric = ifp->if_metric;
        if (ifp->if_flags & IFF_BROADCAST) {
-               ia->ia_broadaddr.sin_addr.s_addr =
-                       ia->ia_subnet | ~ia->ia_subnetmask;
-               ia->ia_netbroadcast.s_addr =
-                       ia->ia_net | ~ia->ia_netmask;
+               if (ia->ia_subnetmask == IN_RFC3021_MASK) {
+                       ia->ia_broadaddr.sin_addr.s_addr = INADDR_BROADCAST;
+                       ia->ia_netbroadcast.s_addr = INADDR_BROADCAST;
+               } else {
+                       ia->ia_broadaddr.sin_addr.s_addr =
+                               ia->ia_subnet | ~ia->ia_subnetmask;
+                       ia->ia_netbroadcast.s_addr =
+                               ia->ia_net | ~ia->ia_netmask;
+               }
        } else if (ifp->if_flags & IFF_LOOPBACK) {
                ia->ia_dstaddr = ia->ia_addr;
                flags |= RTF_HOST;
@@ -1426,8 +1431,10 @@
                     in_hosteq(in, ia->ia_netbroadcast) ||
                     (hostzeroisbroadcast &&
                      /*
-                      * Check for old-style (host 0) broadcast.
+                      * Check for old-style (host 0) broadcast, but
+                      * taking into account that RFC 3021 obsoletes it.
                       */
+                     ia->ia_subnetmask != IN_RFC3021_MASK &&
                      (in.s_addr == ia->ia_subnet ||
                       in.s_addr == ia->ia_net)))) {
                        pserialize_read_exit(s);
diff -r 3e964724f9c6 -r 094ee408f726 sys/netinet/in.h
--- a/sys/netinet/in.h  Tue Dec 17 19:12:50 2019 +0000
+++ b/sys/netinet/in.h  Wed Dec 18 00:49:15 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in.h,v 1.108 2018/11/09 11:46:28 maya Exp $    */
+/*     $NetBSD: in.h,v 1.109 2019/12/18 00:49:16 roy Exp $     */
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993
@@ -235,6 +235,8 @@
 
 #define        IN_LOOPBACKNET          127                     /* official! */
 
+#define        IN_RFC3021_MASK         __IPADDR(0xfffffffe)
+
 /*
  * Socket address, internet style.
  */



Home | Main Index | Thread Index | Old Index