[PATCH] include/linux/socket.h: assign address families for local use

From: Federico Vaga
Date: Wed May 15 2013 - 06:32:03 EST


The patch assigns 4 address families for local use only. This is
useful because it allows to maintain an address family outside kernel
source without conflict. It is also useful during development until a
number is officially assigned.

This is the same kind of policy applied for major number
(Documentation/devices.text)

This patch also increases the number of maximum address (protocol)
families to 64. In this way for a while nobody need to increase this
value. The cost, in terms of memory, is tiny. I made an (very)
approximate calculation about the cost of an unused address family by
following NPROTO, AF_MAX and PF_MAX usage. If I did not big errors it
should be about 70Byte on 32bit systems and 130Byte on 64bit systems for
each new address family.

I also compiled a kernel on a x86_64 machine:
Without patch
text data bss dec hex filename
10935491 1398904 1175552 13509947 ce253b vmlinux

With patch
text data bss dec hex filename
10935427 1399544 1175552 13510523 ce277b vmlinux

Signed-off-by: Federico Vaga <federico.vaga@xxxxxxxxx>
---
include/linux/socket.h | 12 +++++++++++-
net/core/sock.c | 12 +++++++++---
2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/include/linux/socket.h b/include/linux/socket.h
index 428c37a..4775d69 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -179,7 +179,12 @@ struct ucred {
#define AF_ALG 38 /* Algorithm sockets */
#define AF_NFC 39 /* NFC sockets */
#define AF_VSOCK 40 /* vSockets */
-#define AF_MAX 41 /* For now.. */
+#define AF_LOCAL1 41 /* Local use sockets */
+#define AF_LOCAL2 42 /* Local use sockets */
+#define AF_LOCAL3 43 /* Local use sockets */
+#define AF_LOCAL4 44 /* Local use sockets */
+/* new address families here */
+#define AF_MAX 64

/* Protocol families, same as address families. */
#define PF_UNSPEC AF_UNSPEC
@@ -223,6 +228,11 @@ struct ucred {
#define PF_ALG AF_ALG
#define PF_NFC AF_NFC
#define PF_VSOCK AF_VSOCK
+#define PF_LOCAL1 AF_LOCAL1
+#define PF_LOCAL2 AF_LOCAL2
+#define PF_LOCAL3 AF_LOCAL3
+#define PF_LOCAL4 AF_LOCAL4
+/* new protocol families here */
#define PF_MAX AF_MAX

/* Maximum queue length specifiable by listen. */
diff --git a/net/core/sock.c b/net/core/sock.c
index 6ba327d..9bf66ab 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -210,7 +210,9 @@ static const char *const af_family_key_strings[AF_MAX+1] = {
"sk_lock-AF_TIPC" , "sk_lock-AF_BLUETOOTH", "sk_lock-IUCV" ,
"sk_lock-AF_RXRPC" , "sk_lock-AF_ISDN" , "sk_lock-AF_PHONET" ,
"sk_lock-AF_IEEE802154", "sk_lock-AF_CAIF" , "sk_lock-AF_ALG" ,
- "sk_lock-AF_NFC" , "sk_lock-AF_MAX"
+ "sk_lock-AF_NFC" , "sk_lock-AF_LOCAL1" , "sk_lock-AF_LOCAL2" ,
+ "sk_lock-AF_LOCAL3", "sk_lock-AF_LOCAL4" ,
+ [AF_MAX] = "sk_lock-AF_MAX"
};
static const char *const af_family_slock_key_strings[AF_MAX+1] = {
"slock-AF_UNSPEC", "slock-AF_UNIX" , "slock-AF_INET" ,
@@ -226,7 +228,9 @@ static const char *const af_family_slock_key_strings[AF_MAX+1] = {
"slock-AF_TIPC" , "slock-AF_BLUETOOTH", "slock-AF_IUCV" ,
"slock-AF_RXRPC" , "slock-AF_ISDN" , "slock-AF_PHONET" ,
"slock-AF_IEEE802154", "slock-AF_CAIF" , "slock-AF_ALG" ,
- "slock-AF_NFC" , "slock-AF_MAX"
+ "slock-AF_NFC" , "slock-AF_LOCAL1" , "slock-AF_LOCAL2" ,
+ "slock-AF_LOCAL3", "slock-AF_LOCAL4" ,
+ [AF_MAX] = "slock-AF_MAX"
};
static const char *const af_family_clock_key_strings[AF_MAX+1] = {
"clock-AF_UNSPEC", "clock-AF_UNIX" , "clock-AF_INET" ,
@@ -242,7 +246,9 @@ static const char *const af_family_clock_key_strings[AF_MAX+1] = {
"clock-AF_TIPC" , "clock-AF_BLUETOOTH", "clock-AF_IUCV" ,
"clock-AF_RXRPC" , "clock-AF_ISDN" , "clock-AF_PHONET" ,
"clock-AF_IEEE802154", "clock-AF_CAIF" , "clock-AF_ALG" ,
- "clock-AF_NFC" , "clock-AF_MAX"
+ "clock-AF_NFC" , "clock-AF_LOCAL1" , "clock-AF_LOCAL2" ,
+ "clock-AF_LOCAL3", "clock-AF_LOCAL4" ,
+ [AF_MAX] = "clock-AF_MAX"
};

/*
--
1.8.1.4


--nextPart3729943.S8xGMTGp2U--

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/