095-Allow-class-e-address-assignment-via-ifconfig-ioctl.patch 2.7 KB

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