diff mbox series

net: Allow class-e address assignment via ifconfig ioctl

Message ID 20190214122244.25796-1-linus.walleij@linaro.org
State Superseded
Headers show
Series net: Allow class-e address assignment via ifconfig ioctl | expand

Commit Message

Linus Walleij Feb. 14, 2019, 12:22 p.m. UTC
From: Dave Taht <dave.taht@gmail.com>


commit 65cab850f0eeaa9180bd2e10a231964f33743edf upstream.

While most distributions long ago switched to the iproute2 suite
of utilities, which allow class-e (240.0.0.0/4) address assignment,
distributions relying on busybox, toybox and other forms of
ifconfig cannot assign class-e addresses without this kernel patch.

While CIDR has been obsolete for 2 decades, and a survey of all the
open source code in the world shows the IN_whatever macros are also
obsolete... rather than obsolete CIDR from this ioctl entirely, this
patch merely enables class-e assignment, sanely.

Signed-off-by: Dave Taht <dave.taht@gmail.com>

Signed-off-by: David S. Miller <davem@davemloft.net>

---
- This commit is upstream in v4.20
- This should ve applied for stable v4.19.y, v4.14.y and v4.9.y
---
 include/uapi/linux/in.h | 10 +++++++---
 net/ipv4/devinet.c      |  5 +++--
 net/ipv4/ipconfig.c     |  2 ++
 3 files changed, 12 insertions(+), 5 deletions(-)

-- 
2.20.1

Comments

Kevin 'ldir' Darbyshire-Bryant Feb. 14, 2019, 3:12 p.m. UTC | #1
Hi Linus,

FYI this was backported to the Openwrt patch tree by yours truly in https://git.openwrt.org/?p=openwrt/openwrt.git;a=commit;h=2574c86ce66c4032e5905d46601106ccc0c69676

and the follow up fix in https://git.openwrt.org/?p=openwrt/openwrt.git;a=commit;h=1fdb4a7907e0290c7fe5ca3346d40782002dec7b

I await the opportunity to remove the patches for 4.9/4.14/4.19 courtesy delivery from upstream :-)

Cheers,

Kevin

> On 14 Feb 2019, at 12:22, Linus Walleij <linus.walleij@linaro.org> wrote:

> 

> From: Dave Taht <dave.taht@gmail.com>

> 

> commit 65cab850f0eeaa9180bd2e10a231964f33743edf upstream.

> 

> While most distributions long ago switched to the iproute2 suite

> of utilities, which allow class-e (240.0.0.0/4) address assignment,

> distributions relying on busybox, toybox and other forms of

> ifconfig cannot assign class-e addresses without this kernel patch.

> 

> While CIDR has been obsolete for 2 decades, and a survey of all the

> open source code in the world shows the IN_whatever macros are also

> obsolete... rather than obsolete CIDR from this ioctl entirely, this

> patch merely enables class-e assignment, sanely.

> 

> Signed-off-by: Dave Taht <dave.taht@gmail.com>

> Signed-off-by: David S. Miller <davem@davemloft.net>

> ---

> - This commit is upstream in v4.20

> - This should ve applied for stable v4.19.y, v4.14.y and v4.9.y

> ---

> include/uapi/linux/in.h | 10 +++++++---

> net/ipv4/devinet.c      |  5 +++--

> net/ipv4/ipconfig.c     |  2 ++

> 3 files changed, 12 insertions(+), 5 deletions(-)

> 

> diff --git a/include/uapi/linux/in.h b/include/uapi/linux/in.h

> index 48e8a225b985..f6052e70bf40 100644

> --- a/include/uapi/linux/in.h

> +++ b/include/uapi/linux/in.h

> @@ -266,10 +266,14 @@ struct sockaddr_in {

> 

> #define	IN_CLASSD(a)		((((long int) (a)) & 0xf0000000) == 0xe0000000)

> #define	IN_MULTICAST(a)		IN_CLASSD(a)

> -#define IN_MULTICAST_NET	0xF0000000

> +#define	IN_MULTICAST_NET	0xe0000000

> 

> -#define	IN_EXPERIMENTAL(a)	((((long int) (a)) & 0xf0000000) == 0xf0000000)

> -#define	IN_BADCLASS(a)		IN_EXPERIMENTAL((a))

> +#define	IN_BADCLASS(a)		((((long int) (a) ) == 0xffffffff)

> +#define	IN_EXPERIMENTAL(a)	IN_BADCLASS((a))

> +

> +#define	IN_CLASSE(a)		((((long int) (a)) & 0xf0000000) == 0xf0000000)

> +#define	IN_CLASSE_NET		0xffffffff

> +#define	IN_CLASSE_NSHIFT	0

> 

> /* Address to accept any incoming messages. */

> #define	INADDR_ANY		((unsigned long int) 0x00000000)

> diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c

> index ea4bd8a52422..e38042933a27 100644

> --- a/net/ipv4/devinet.c

> +++ b/net/ipv4/devinet.c

> @@ -941,17 +941,18 @@ static int inet_abc_len(__be32 addr)

> {

> 	int rc = -1;	/* Something else, probably a multicast. */

> 

> -	if (ipv4_is_zeronet(addr))

> +	if (ipv4_is_zeronet(addr) || ipv4_is_lbcast(addr))

> 		rc = 0;

> 	else {

> 		__u32 haddr = ntohl(addr);

> -

> 		if (IN_CLASSA(haddr))

> 			rc = 8;

> 		else if (IN_CLASSB(haddr))

> 			rc = 16;

> 		else if (IN_CLASSC(haddr))

> 			rc = 24;

> +		else if (IN_CLASSE(haddr))

> +			rc = 32;

> 	}

> 

> 	return rc;

> diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c

> index 88212615bf4c..2393e5c106bf 100644

> --- a/net/ipv4/ipconfig.c

> +++ b/net/ipv4/ipconfig.c

> @@ -429,6 +429,8 @@ static int __init ic_defaults(void)

> 			ic_netmask = htonl(IN_CLASSB_NET);

> 		else if (IN_CLASSC(ntohl(ic_myaddr)))

> 			ic_netmask = htonl(IN_CLASSC_NET);

> +		else if (IN_CLASSE(ntohl(ic_myaddr)))

> +			ic_netmask = htonl(IN_CLASSE_NET);

> 		else {

> 			pr_err("IP-Config: Unable to guess netmask for address %pI4\n",

> 			       &ic_myaddr);

> -- 

> 2.20.1

> 

> 

> _______________________________________________

> openwrt-devel mailing list

> openwrt-devel@lists.openwrt.org

> https://lists.openwrt.org/mailman/listinfo/openwrt-devel



Cheers,

Kevin D-B

012C ACB2 28C6 C53E 9775  9123 B3A2 389B 9DE2 334A
diff mbox series

Patch

diff --git a/include/uapi/linux/in.h b/include/uapi/linux/in.h
index 48e8a225b985..f6052e70bf40 100644
--- a/include/uapi/linux/in.h
+++ b/include/uapi/linux/in.h
@@ -266,10 +266,14 @@  struct sockaddr_in {
 
 #define	IN_CLASSD(a)		((((long int) (a)) & 0xf0000000) == 0xe0000000)
 #define	IN_MULTICAST(a)		IN_CLASSD(a)
-#define IN_MULTICAST_NET	0xF0000000
+#define	IN_MULTICAST_NET	0xe0000000
 
-#define	IN_EXPERIMENTAL(a)	((((long int) (a)) & 0xf0000000) == 0xf0000000)
-#define	IN_BADCLASS(a)		IN_EXPERIMENTAL((a))
+#define	IN_BADCLASS(a)		((((long int) (a) ) == 0xffffffff)
+#define	IN_EXPERIMENTAL(a)	IN_BADCLASS((a))
+
+#define	IN_CLASSE(a)		((((long int) (a)) & 0xf0000000) == 0xf0000000)
+#define	IN_CLASSE_NET		0xffffffff
+#define	IN_CLASSE_NSHIFT	0
 
 /* Address to accept any incoming messages. */
 #define	INADDR_ANY		((unsigned long int) 0x00000000)
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index ea4bd8a52422..e38042933a27 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -941,17 +941,18 @@  static int inet_abc_len(__be32 addr)
 {
 	int rc = -1;	/* Something else, probably a multicast. */
 
-	if (ipv4_is_zeronet(addr))
+	if (ipv4_is_zeronet(addr) || ipv4_is_lbcast(addr))
 		rc = 0;
 	else {
 		__u32 haddr = ntohl(addr);
-
 		if (IN_CLASSA(haddr))
 			rc = 8;
 		else if (IN_CLASSB(haddr))
 			rc = 16;
 		else if (IN_CLASSC(haddr))
 			rc = 24;
+		else if (IN_CLASSE(haddr))
+			rc = 32;
 	}
 
 	return rc;
diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
index 88212615bf4c..2393e5c106bf 100644
--- a/net/ipv4/ipconfig.c
+++ b/net/ipv4/ipconfig.c
@@ -429,6 +429,8 @@  static int __init ic_defaults(void)
 			ic_netmask = htonl(IN_CLASSB_NET);
 		else if (IN_CLASSC(ntohl(ic_myaddr)))
 			ic_netmask = htonl(IN_CLASSC_NET);
+		else if (IN_CLASSE(ntohl(ic_myaddr)))
+			ic_netmask = htonl(IN_CLASSE_NET);
 		else {
 			pr_err("IP-Config: Unable to guess netmask for address %pI4\n",
 			       &ic_myaddr);