|
| 1 | +From 46bf067870156abd61fe24d14c2486d15b8b502c Mon Sep 17 00:00:00 2001 |
| 2 | +From: Dave Taht <dave@taht.net> |
| 3 | +Date: Fri, 14 Dec 2018 18:38:40 +0000 |
| 4 | +Subject: [PATCH 1/1] Allow class-e address assignment in ifconfig and early |
| 5 | + boot |
| 6 | + |
| 7 | +While the linux kernel became mostly "class-e clean" a decade ago, |
| 8 | +and most distributions long ago switched to the iproute2 suite |
| 9 | +of utilities, which allow class-e (240.0.0.0/4) address assignment, |
| 10 | +distributions relying on busybox, toybox and other forms of |
| 11 | +ifconfig cannot assign class-e addresses without this kernel patch. |
| 12 | + |
| 13 | +With this patch, also, a boot command line on these addresses is feasible: |
| 14 | +(ip=248.0.1.2::248.0.1.1:255.255.255.0). |
| 15 | + |
| 16 | +While CIDR has been obsolete for 2 decades, and a survey of all the |
| 17 | +userspace open source code in the world shows most IN_whatever macros |
| 18 | +are also obsolete... rather than obsolete CIDR from this ioctl entirely, |
| 19 | +this patch merely enables class-e assignment, sanely. |
| 20 | + |
| 21 | +H/T to Vince Fuller and his original patch here: |
| 22 | + https://lkml.org/lkml/2008/1/7/370 |
| 23 | + |
| 24 | +Signed-off-by: Dave Taht <dave.taht@gmail.com> |
| 25 | +Reviewed-by: John Gilmore <gnu@toad.com> |
| 26 | +--- |
| 27 | + include/uapi/linux/in.h | 8 ++++++-- |
| 28 | + net/ipv4/devinet.c | 4 +++- |
| 29 | + net/ipv4/ipconfig.c | 2 ++ |
| 30 | + 3 files changed, 11 insertions(+), 3 deletions(-) |
| 31 | + |
| 32 | +diff --git a/include/uapi/linux/in.h b/include/uapi/linux/in.h |
| 33 | +index 48e8a225b985..b27269a2bc95 100644 |
| 34 | +--- a/include/uapi/linux/in.h |
| 35 | ++++ b/include/uapi/linux/in.h |
| 36 | +@@ -268,8 +268,12 @@ struct sockaddr_in { |
| 37 | + #define IN_MULTICAST(a) IN_CLASSD(a) |
| 38 | + #define IN_MULTICAST_NET 0xF0000000 |
| 39 | + |
| 40 | +-#define IN_EXPERIMENTAL(a) ((((long int) (a)) & 0xf0000000) == 0xf0000000) |
| 41 | +-#define IN_BADCLASS(a) IN_EXPERIMENTAL((a)) |
| 42 | ++#define IN_BADCLASS(a) ((((long int) (a) ) == 0xffffffff) |
| 43 | ++#define IN_EXPERIMENTAL(a) IN_BADCLASS((a)) |
| 44 | ++ |
| 45 | ++#define IN_CLASSE(a) ((((long int) (a)) & 0xf0000000) == 0xf0000000) |
| 46 | ++#define IN_CLASSE_NET 0xffffffff |
| 47 | ++#define IN_CLASSE_NSHIFT 0 |
| 48 | + |
| 49 | + /* Address to accept any incoming messages. */ |
| 50 | + #define INADDR_ANY ((unsigned long int) 0x00000000) |
| 51 | +diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c |
| 52 | +index 5b9b6d497f71..36dac0afcba5 100644 |
| 53 | +--- a/net/ipv4/devinet.c |
| 54 | ++++ b/net/ipv4/devinet.c |
| 55 | +@@ -952,7 +952,7 @@ static int inet_abc_len(__be32 addr) |
| 56 | + { |
| 57 | + int rc = -1; /* Something else, probably a multicast. */ |
| 58 | + |
| 59 | +- if (ipv4_is_zeronet(addr)) |
| 60 | ++ if (ipv4_is_zeronet(addr) || ipv4_is_lbcast(addr)) |
| 61 | + rc = 0; |
| 62 | + else { |
| 63 | + __u32 haddr = ntohl(addr); |
| 64 | +@@ -963,6 +963,8 @@ static int inet_abc_len(__be32 addr) |
| 65 | + rc = 16; |
| 66 | + else if (IN_CLASSC(haddr)) |
| 67 | + rc = 24; |
| 68 | ++ else if (IN_CLASSE(haddr)) |
| 69 | ++ rc = 32; |
| 70 | + } |
| 71 | + |
| 72 | + return rc; |
| 73 | +diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c |
| 74 | +index 55757764c381..86820bcc1b6a 100644 |
| 75 | +--- a/net/ipv4/ipconfig.c |
| 76 | ++++ b/net/ipv4/ipconfig.c |
| 77 | +@@ -429,6 +429,8 @@ static int __init ic_defaults(void) |
| 78 | + ic_netmask = htonl(IN_CLASSB_NET); |
| 79 | + else if (IN_CLASSC(ntohl(ic_myaddr))) |
| 80 | + ic_netmask = htonl(IN_CLASSC_NET); |
| 81 | ++ else if (IN_CLASSE(ntohl(ic_myaddr))) |
| 82 | ++ ic_netmask = htonl(IN_CLASSE_NET); |
| 83 | + else { |
| 84 | + pr_err("IP-Config: Unable to guess netmask for address %pI4\n", |
| 85 | + &ic_myaddr); |
| 86 | +-- |
| 87 | +2.17.1 |
| 88 | + |
0 commit comments