38ae0766785bc26bf524d697f4e97d8b46715e19
[librecmc/librecmc.git] / target / linux / generic / backport-4.9 / 095-Allow-class-e-address-assignment-via-ifconfig-ioctl.patch
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 --- a/include/uapi/linux/in.h
33 +++ b/include/uapi/linux/in.h
34 @@ -266,8 +266,12 @@ struct sockaddr_in {
35  #define        IN_MULTICAST(a)         IN_CLASSD(a)
36  #define IN_MULTICAST_NET       0xF0000000
37  
38 -#define        IN_EXPERIMENTAL(a)      ((((long int) (a)) & 0xf0000000) == 0xf0000000)
39 -#define        IN_BADCLASS(a)          IN_EXPERIMENTAL((a))
40 +#define        IN_BADCLASS(a)          (((long int) (a) ) == (long int)0xffffffff)
41 +#define        IN_EXPERIMENTAL(a)      IN_BADCLASS((a))
42 +
43 +#define        IN_CLASSE(a)            ((((long int) (a)) & 0xf0000000) == 0xf0000000)
44 +#define        IN_CLASSE_NET           0xffffffff
45 +#define        IN_CLASSE_NSHIFT        0
46  
47  /* Address to accept any incoming messages. */
48  #define        INADDR_ANY              ((unsigned long int) 0x00000000)
49 --- a/net/ipv4/devinet.c
50 +++ b/net/ipv4/devinet.c
51 @@ -898,7 +898,7 @@ static int inet_abc_len(__be32 addr)
52  {
53         int rc = -1;    /* Something else, probably a multicast. */
54  
55 -       if (ipv4_is_zeronet(addr))
56 +       if (ipv4_is_zeronet(addr) || ipv4_is_lbcast(addr))
57                 rc = 0;
58         else {
59                 __u32 haddr = ntohl(addr);
60 @@ -909,6 +909,8 @@ static int inet_abc_len(__be32 addr)
61                         rc = 16;
62                 else if (IN_CLASSC(haddr))
63                         rc = 24;
64 +               else if (IN_CLASSE(haddr))
65 +                       rc = 32;
66         }
67  
68         return rc;
69 --- a/net/ipv4/ipconfig.c
70 +++ b/net/ipv4/ipconfig.c
71 @@ -455,6 +455,8 @@ static int __init ic_defaults(void)
72                         ic_netmask = htonl(IN_CLASSB_NET);
73                 else if (IN_CLASSC(ntohl(ic_myaddr)))
74                         ic_netmask = htonl(IN_CLASSC_NET);
75 +               else if (IN_CLASSE(ntohl(ic_myaddr)))
76 +                       ic_netmask = htonl(IN_CLASSE_NET);
77                 else {
78                         pr_err("IP-Config: Unable to guess netmask for address %pI4\n",
79                                &ic_myaddr);