Skip to contentSkip to conversation

net: introduce generic type and helpers for IP address

PATCH In review Cong Wang 6 participants 22 messages Aug 19, 2013 – Aug 22, 2013

Subsystems (18)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

v3 cover net: introduce generic type and helpers for IP address

From: Cong Wang <[email protected]>

As IPv6 becomes popular, more and more subsystems begin to support IPv6, therefore we need a generic IP address type, in case of duplicates. Also we will also need some helpers to compare, print, check the generic IP address.

This patchset introduce a new type union inet_addr as a union of IPv4 and IPv6 address, and struct in_addr_gen for inetpeer and bridge mdb, plus some helper functions that will be used by existing code and in the future VXLAN module.

However, due to ABI limit, we still can't convert union nf_inet_addr to union inet_addr.

v2 -> v3:
* introduce sockaddr_*() helper functions as well
* split the first patch into two
* rebase on to the latest net-next

v1 -> v2:
* introduce another generic IP address type, struct in_addr_gen
* convert bridge multicast code too
* complete the smack part

RFC -> v1:
* rebase these patches on top of Daniel's
* rename inet_pton() to simple_inet_pton()
* fix the simple_inet_pton() API
* make inet_addr_equal() non-inline
* add two more patches

Cong Wang (9):
net: introduce generic union inet_addr
net: rename '%pIS' to '%pIA' for union inet_addr
net: introduce generic simple_inet_pton()
inetpeer: use generic struct in_addr_gen
bridge: use generic struct in_addr_gen
sunrpc: use generic union inet_addr
fs: use generic union inet_addr and help functions
sctp: use generic union inet_addr
selinux: use generic union inet_addr

 Documentation/printk-formats.txt   |   20 ++--
 drivers/net/netconsole.c           |   22 ++--
 fs/cifs/connect.c                  |   54 ++------
 fs/dlm/lowcomms.c                  |   24 +---
 fs/lockd/clntlock.c                |    2 +-
 fs/lockd/host.c                    |    8 +-
 fs/lockd/mon.c                     |    2 +-
 fs/lockd/svcsubs.c                 |    2 +-
 fs/nfs/client.c                    |  113 +-----------------
 fs/nfs/nfs4client.c                |    2 +-
 fs/nfs/nfs4filelayoutdev.c         |   37 +-----
 fs/nfs/nfs4namespace.c             |    2 +-
 fs/nfs/super.c                     |   37 +-----
 fs/nfsd/nfs4state.c                |    6 +-
 fs/nfsd/nfscache.c                 |    8 +-
 include/linux/lsm_audit.h          |   19 +---
 include/linux/netpoll.h            |    9 +--
 include/linux/sunrpc/addr.h        |  131 +-------------------
 include/net/inet_addr.h            |  160 ++++++++++++++++++++++++
 include/net/inetpeer.h             |   25 +---
 include/net/sctp/sctp.h            |   22 ++--
 include/net/sctp/sm.h              |    4 +-
 include/net/sctp/structs.h         |  132 +++++++++-----------
 lib/vsprintf.c                     |   29 ++---
 net/bridge/br_mdb.c                |   53 ++++----
 net/bridge/br_multicast.c          |   65 ++++------
 net/bridge/br_private.h            |    9 +-
 net/core/netpoll.c                 |   86 +++++--------
 net/core/utils.c                   |   84 +++++++++++++
 net/ipv4/inetpeer.c                |   33 +++--
 net/ipv4/tcp_metrics.c             |   74 +++++-------
 net/sctp/associola.c               |   32 +++---
 net/sctp/bind_addr.c               |   61 +++------
 net/sctp/endpointola.c             |   12 +-
 net/sctp/input.c                   |   56 ++++----
 net/sctp/ipv6.c                    |  240 ++++++++++++++++--------------------
 net/sctp/outqueue.c                |    4 +-
 net/sctp/proc.c                    |   10 +-
 net/sctp/protocol.c                |  204 ++++++++++++-------------------
 net/sctp/sm_make_chunk.c           |   54 ++++----
 net/sctp/sm_sideeffect.c           |    2 +-
 net/sctp/sm_statefuns.c            |   23 +---
 net/sctp/socket.c                  |  130 +++++++++++---------
 net/sctp/transport.c               |   12 +-
 net/sctp/ulpevent.c                |    2 +-
 net/sunrpc/clnt.c                  |    2 +-
 net/sunrpc/rpcb_clnt.c             |    2 +-
 net/sunrpc/xprtrdma/transport.c    |    4 +-
 net/sunrpc/xprtsock.c              |    8 +-
 security/lsm_audit.c               |   58 +++++-----
 security/selinux/hooks.c           |  130 +++++++++----------
 security/selinux/include/netnode.h |    4 +-
 security/selinux/include/objsec.h  |    7 +-
 security/selinux/netnode.c         |  102 +++++-----------
 security/smack/smack_lsm.c         |   19 ++--
 55 files changed, 1063 insertions(+), 1389 deletions(-)
 create mode 100644 include/net/inet_addr.h
Signature · 1 line
1.7.7.6
author
#1 lore raw

PATCH v3 1/9 net: introduce generic union inet_addr

From: Cong Wang <[email protected]>

Introduce a generic IP address type, union inet_addr, so that subsystems don't have to use their own definitions. Because netpoll already defines union inet_addr, just move it to global. Some of the helper functions will be used by VXLAN IPv6 code too.

---
 drivers/net/netconsole.c |   20 +++++++++------
 include/linux/netpoll.h  |    9 +------
 include/net/inet_addr.h  |   62 ++++++++++++++++++++++++++++++++++++++++++++++
 net/core/netpoll.c       |   50 +++++++++++++++++++-----------------
 4 files changed, 101 insertions(+), 40 deletions(-)
 create mode 100644 include/net/inet_addr.h
drivers/net/netconsole.c +12 -8
index 4822aaf..e4eac0c 100644
@@ -271,17 +271,17 @@ static ssize_t show_remote_port(struct netconsole_target *nt, char *buf)
 static ssize_t show_local_ip(struct netconsole_target *nt, char *buf)
 {
 	if (nt->np.ipv6)
-		return snprintf(buf, PAGE_SIZE, "%pI6c\n", &nt->np.local_ip.in6);
+		return snprintf(buf, PAGE_SIZE, "%pI6c\n", &nt->np.local_ip.sin6.sin6_addr);
 	else
-		return snprintf(buf, PAGE_SIZE, "%pI4\n", &nt->np.local_ip);
+		return snprintf(buf, PAGE_SIZE, "%pI4\n", &nt->np.local_ip.sin.sin_addr.s_addr);
 }
 
 static ssize_t show_remote_ip(struct netconsole_target *nt, char *buf)
 {
 	if (nt->np.ipv6)
-		return snprintf(buf, PAGE_SIZE, "%pI6c\n", &nt->np.remote_ip.in6);
+		return snprintf(buf, PAGE_SIZE, "%pI6c\n", &nt->np.remote_ip.sin6.sin6_addr);
 	else
-		return snprintf(buf, PAGE_SIZE, "%pI4\n", &nt->np.remote_ip);
+		return snprintf(buf, PAGE_SIZE, "%pI4\n", &nt->np.remote_ip.sin.sin_addr.s_addr);
 }
 
 static ssize_t show_local_mac(struct netconsole_target *nt, char *buf)
@@ -419,17 +419,19 @@ static ssize_t store_local_ip(struct netconsole_target *nt,
 
 	if (strnchr(buf, count, ':')) {
 		const char *end;
-		if (in6_pton(buf, count, nt->np.local_ip.in6.s6_addr, -1, &end) > 0) {
+		if (in6_pton(buf, count, nt->np.local_ip.sin6.sin6_addr.s6_addr, -1, &end) > 0) {
 			if (*end && *end != '\n') {
 				printk(KERN_ERR "netconsole: invalid IPv6 address at: <%c>\n", *end);
 				return -EINVAL;
 			}
+			nt->np.local_ip.sa.sa_family = AF_INET6;
 			nt->np.ipv6 = true;
 		} else
 			return -EINVAL;
 	} else {
 		if (!nt->np.ipv6) {
-			nt->np.local_ip.ip = in_aton(buf);
+			nt->np.local_ip.sin.sin_addr.s_addr = in_aton(buf);
+			nt->np.local_ip.sa.sa_family = AF_INET;
 		} else
 			return -EINVAL;
 	}
@@ -450,17 +452,19 @@ static ssize_t store_remote_ip(struct netconsole_target *nt,
 
 	if (strnchr(buf, count, ':')) {
 		const char *end;
-		if (in6_pton(buf, count, nt->np.remote_ip.in6.s6_addr, -1, &end) > 0) {
+		if (in6_pton(buf, count, nt->np.remote_ip.sin6.sin6_addr.s6_addr, -1, &end) > 0) {
 			if (*end && *end != '\n') {
 				printk(KERN_ERR "netconsole: invalid IPv6 address at: <%c>\n", *end);
 				return -EINVAL;
 			}
+			nt->np.remote_ip.sa.sa_family = AF_INET6;
 			nt->np.ipv6 = true;
 		} else
 			return -EINVAL;
 	} else {
 		if (!nt->np.ipv6) {
-			nt->np.remote_ip.ip = in_aton(buf);
+			nt->np.remote_ip.sin.sin_addr.s_addr = in_aton(buf);
+			nt->np.remote_ip.sa.sa_family = AF_INET;
 		} else
 			return -EINVAL;
 	}
include/linux/netpoll.h +1 -8
index f3c7c24..3884834 100644
@@ -11,14 +11,7 @@
 #include <linux/interrupt.h>
 #include <linux/rcupdate.h>
 #include <linux/list.h>
-
-union inet_addr {
-	__u32		all[4];
-	__be32		ip;
-	__be32		ip6[4];
-	struct in_addr	in;
-	struct in6_addr	in6;
-};
+#include <net/inet_addr.h>
 
 struct netpoll {
 	struct net_device *dev;
include/net/inet_addr.h new file +62 -0

62 lines not on this page · raw message

net/core/netpoll.c +26 -24

141 lines not on this page · raw message

Signature · 1 line
1.7.7.6
author
#2 lore raw

PATCH v3 2/9 net: rename '%pIS' to '%pIA' for union inet_addr

In reply to Cong Wang

From: Cong Wang <[email protected]>

The "%pIS" specifier is for struct Sockaddr, since now we have union inet_addr, rename it to '%pIA' so that it can accept union inet_addr*. But struct sockaddr * can still safely passed to
'%pIA', since it is a union of it.

---
 Documentation/printk-formats.txt |   20 ++++++++++----------
 drivers/net/netconsole.c         |   10 ++--------
 lib/vsprintf.c                   |   29 +++++++++++++----------------
 net/core/netpoll.c               |   10 ++--------
 net/sctp/associola.c             |    6 +++---
 net/sctp/protocol.c              |    6 +++---
 net/sctp/sm_sideeffect.c         |    2 +-
 net/sctp/socket.c                |    4 ++--
 8 files changed, 36 insertions(+), 51 deletions(-)
Documentation/printk-formats.txt +10 -10
index 3e8cb73..3521cc9 100644
@@ -123,15 +123,15 @@ IPv6 addresses:
 
 IPv4/IPv6 addresses (generic, with port, flowinfo, scope):
 
-	%pIS	1.2.3.4		or 0001:0002:0003:0004:0005:0006:0007:0008
-	%piS	001.002.003.004	or 00010002000300040005000600070008
-	%pISc	1.2.3.4		or 1:2:3:4:5:6:7:8
-	%pISpc	1.2.3.4:12345	or [1:2:3:4:5:6:7:8]:12345
-	%p[Ii]S[pfschnbl]
+	%pIA	1.2.3.4		or 0001:0002:0003:0004:0005:0006:0007:0008
+	%piA	001.002.003.004	or 00010002000300040005000600070008
+	%pIAc	1.2.3.4		or 1:2:3:4:5:6:7:8
+	%pIApc	1.2.3.4:12345	or [1:2:3:4:5:6:7:8]:12345
+	%p[Ii]A[pfschnbl]
 
 	For printing an IP address without the need to distinguish whether it's
-	of type AF_INET or AF_INET6, a pointer to a valid 'struct sockaddr',
-	specified through 'IS' or 'iS', can be passed to this format specifier.
+	of type AF_INET or AF_INET6, a pointer to a valid 'union inet_addr',
+	specified through 'IA' or 'iA', can be passed to this format specifier.
 
 	The additional 'p', 'f', and 's' specifiers are used to specify port
 	(IPv4, IPv6), flowinfo (IPv6) and scope (IPv6). Ports have a ':' prefix,
@@ -149,9 +149,9 @@ IPv4/IPv6 addresses (generic, with port, flowinfo, scope):
 
 	Further examples:
 
-	%pISfc		1.2.3.4		or [1:2:3:4:5:6:7:8]/123456789
-	%pISsc		1.2.3.4		or [1:2:3:4:5:6:7:8]%1234567890
-	%pISpfc		1.2.3.4:12345	or [1:2:3:4:5:6:7:8]:12345/123456789
+	%pIAfc		1.2.3.4		or [1:2:3:4:5:6:7:8]/123456789
+	%pIAsc		1.2.3.4		or [1:2:3:4:5:6:7:8]%1234567890
+	%pIApfc		1.2.3.4:12345	or [1:2:3:4:5:6:7:8]:12345/123456789
 
 UUID/GUID addresses:
 
drivers/net/netconsole.c +2 -8
index e4eac0c..28234f8 100644
@@ -270,18 +270,12 @@ static ssize_t show_remote_port(struct netconsole_target *nt, char *buf)
 
 static ssize_t show_local_ip(struct netconsole_target *nt, char *buf)
 {
-	if (nt->np.ipv6)
-		return snprintf(buf, PAGE_SIZE, "%pI6c\n", &nt->np.local_ip.sin6.sin6_addr);
-	else
-		return snprintf(buf, PAGE_SIZE, "%pI4\n", &nt->np.local_ip.sin.sin_addr.s_addr);
+	return snprintf(buf, PAGE_SIZE, "%pIA\n", &nt->np.local_ip);
 }
 
 static ssize_t show_remote_ip(struct netconsole_target *nt, char *buf)
 {
-	if (nt->np.ipv6)
-		return snprintf(buf, PAGE_SIZE, "%pI6c\n", &nt->np.remote_ip.sin6.sin6_addr);
-	else
-		return snprintf(buf, PAGE_SIZE, "%pI4\n", &nt->np.remote_ip.sin.sin_addr.s_addr);
+	return snprintf(buf, PAGE_SIZE, "%pIA\n", &nt->np.remote_ip);
 }
 
 static ssize_t show_local_mac(struct netconsole_target *nt, char *buf)
lib/vsprintf.c +13 -16
index 739a363..49618d0 100644
@@ -27,6 +27,7 @@
 #include <linux/uaccess.h>
 #include <linux/ioport.h>
 #include <net/addrconf.h>
+#include <net/inet_addr.h>
 
 #include <asm/page.h>		/* for PAGE_SIZE */
 #include <asm/sections.h>	/* for dereference_function_descriptor() */
@@ -1104,14 +1105,14 @@ int kptr_restrict __read_mostly;
  * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way
  *       IPv4 uses dot-separated decimal without leading 0's (1.2.3.4)
  *       IPv6 uses colon separated network-order 16 bit hex with leading 0's
- *       [S][pfs]
- *       Generic IPv4/IPv6 address (struct sockaddr *) that falls back to
+ *       [A][pfs]
+ *       Generic IPv4/IPv6 address (union inet_addr *) that falls back to
  *       [4] or [6] and is able to print port [p], flowinfo [f], scope [s]
  * - 'i' [46] for 'raw' IPv4/IPv6 addresses
  *       IPv6 omits the colons (01020304...0f)
  *       IPv4 uses dot-separated decimal with leading 0's (010.123.045.006)
- *       [S][pfs]
- *       Generic IPv4/IPv6 address (struct sockaddr *) that falls back to
+ *       [A][pfs]
+ *       Generic IPv4/IPv6 address (union inet_addr *) that falls back to
  *       [4] or [6] and is able to print port [p], flowinfo [f], scope [s]
  * - '[Ii][4S][hnbl]' IPv4 addresses in host, network, big or little endian order
  * - 'I[6S]c' for IPv6 addresses printed as specified by
@@ -1196,18 +1197,14 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
 			return ip6_addr_string(buf, end, ptr, spec, fmt);
 		case '4':
 			return ip4_addr_string(buf, end, ptr, spec, fmt);
-		case 'S': {
-			const union {
-				struct sockaddr		raw;
-				struct sockaddr_in	v4;
-				struct sockaddr_in6	v6;
-			} *sa = ptr;
-
-			switch (sa->raw.sa_family) {
+		case 'A': {
+			const union inet_addr *sa = ptr;
+
+			switch (sa->sa.sa_family) {
 			case AF_INET:
-				return ip4_addr_string_sa(buf, end, &sa->v4, spec, fmt);
+				return ip4_addr_string_sa(buf, end, &sa->sin, spec, fmt);
 			case AF_INET6:
-				return ip6_addr_string_sa(buf, end, &sa->v6, spec, fmt);
+				return ip6_addr_string_sa(buf, end, &sa->sin6, spec, fmt);
 			default:
 				return string(buf, end, "(invalid address)", spec);
 			}}
@@ -1488,8 +1485,8 @@ qualifier:
  * %pI6 print an IPv6 address with colons
  * %pi6 print an IPv6 address without colons
  * %pI6c print an IPv6 address as specified by RFC 5952
- * %pIS depending on sa_family of 'struct sockaddr *' print IPv4/IPv6 address
- * %piS depending on sa_family of 'struct sockaddr *' print IPv4/IPv6 address
+ * %pIA depending on sa_family of 'union inet_addr *' print IPv4/IPv6 address
+ * %piA depending on sa_family of 'union inet_addr *' print IPv4/IPv6 address
  * %pU[bBlL] print a UUID/GUID in big or little endian using lower or upper
  *   case.
  * %*ph[CDN] a variable-length hex string with a separator (supports up to 64
net/core/netpoll.c +2 -8
index dd38553..9a45c54 100644
@@ -900,16 +900,10 @@ out:
 void netpoll_print_options(struct netpoll *np)
 {
 	np_info(np, "local port %d\n", np->local_port);
-	if (np->ipv6)
-		np_info(np, "local IPv6 address %pI6c\n", &np->local_ip.sin6.sin6_addr);
-	else
-		np_info(np, "local IPv4 address %pI4\n", &np->local_ip.sin.sin_addr.s_addr);
+	np_info(np, "local IP address %pIA\n", &np->local_ip);
 	np_info(np, "interface '%s'\n", np->dev_name);
 	np_info(np, "remote port %d\n", np->remote_port);
-	if (np->ipv6)
-		np_info(np, "remote IPv6 address %pI6c\n", &np->remote_ip.sin6.sin6_addr);
-	else
-		np_info(np, "remote IPv4 address %pI4\n", &np->remote_ip.sin.sin_addr.s_addr);
+	np_info(np, "remote IP address %pIA\n", &np->remote_ip);
 	np_info(np, "remote ethernet address %pM\n", np->remote_mac);
 }
 EXPORT_SYMBOL(netpoll_print_options);
net/sctp/associola.c +3 -3
index cef5099..a514612 100644
@@ -534,7 +534,7 @@ void sctp_assoc_rm_peer(struct sctp_association *asoc,
 	struct list_head	*pos;
 	struct sctp_transport	*transport;
 
-	pr_debug("%s: association:%p addr:%pISpc\n",
+	pr_debug("%s: association:%p addr:%pIApc\n",
 		 __func__, asoc, &peer->ipaddr.sa);
 
 	/* If we are to remove the current retran_path, update it
@@ -631,7 +631,7 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
 	/* AF_INET and AF_INET6 share common port field. */
 	port = ntohs(addr->v4.sin_port);
 
-	pr_debug("%s: association:%p addr:%pISpc state:%d\n", __func__,
+	pr_debug("%s: association:%p addr:%pIApc state:%d\n", __func__,
 		 asoc, &addr->sa, peer_state);
 
 	/* Set the port if it has not been set yet.  */
@@ -1341,7 +1341,7 @@ void sctp_assoc_update_retran_path(struct sctp_association *asoc)
 	else
 		t = asoc->peer.retran_path;
 
-	pr_debug("%s: association:%p addr:%pISpc\n", __func__, asoc,
+	pr_debug("%s: association:%p addr:%pIApc\n", __func__, asoc,
 		 &t->ipaddr.sa);
 }
 
net/sctp/protocol.c +3 -3
index 5e17092..0680be7 100644
@@ -598,7 +598,7 @@ static void sctp_addr_wq_timeout_handler(unsigned long arg)
 	spin_lock_bh(&net->sctp.addr_wq_lock);
 
 	list_for_each_entry_safe(addrw, temp, &net->sctp.addr_waitq, list) {
-		pr_debug("%s: the first ent in wq:%p is addr:%pISc for cmd:%d at "
+		pr_debug("%s: the first ent in wq:%p is addr:%pIAc for cmd:%d at "
 			 "entry:%p\n", __func__, &net->sctp.addr_waitq, &addrw->a.sa,
 			 addrw->state, addrw);
 
@@ -703,7 +703,7 @@ void sctp_addr_wq_mgmt(struct net *net, struct sctp_sockaddr_entry *addr, int cm
 	addrw = sctp_addr_wq_lookup(net, addr);
 	if (addrw) {
 		if (addrw->state != cmd) {
-			pr_debug("%s: offsets existing entry for %d, addr:%pISc "
+			pr_debug("%s: offsets existing entry for %d, addr:%pIAc "
 				 "in wq:%p\n", __func__, addrw->state, &addrw->a.sa,
 				 &net->sctp.addr_waitq);
 
@@ -723,7 +723,7 @@ void sctp_addr_wq_mgmt(struct net *net, struct sctp_sockaddr_entry *addr, int cm
 	addrw->state = cmd;
 	list_add_tail(&addrw->list, &net->sctp.addr_waitq);
 
-	pr_debug("%s: add new entry for cmd:%d, addr:%pISc in wq:%p\n",
+	pr_debug("%s: add new entry for cmd:%d, addr:%pIAc in wq:%p\n",
 		 __func__, addrw->state, &addrw->a.sa, &net->sctp.addr_waitq);
 
 	if (!timer_pending(&net->sctp.addr_wq_timer)) {
net/sctp/sm_sideeffect.c +1 -1
index 666c668..638c63c 100644
@@ -514,7 +514,7 @@ static void sctp_do_8_2_transport_strike(sctp_cmd_seq_t *commands,
 
 	if (transport->state != SCTP_INACTIVE &&
 	    (transport->error_count > transport->pathmaxrxt)) {
-		pr_debug("%s: association:%p transport addr:%pISpc failed\n",
+		pr_debug("%s: association:%p transport addr:%pIApc failed\n",
 			 __func__, asoc, &transport->ipaddr.sa);
 
 		sctp_assoc_control_transport(asoc, transport,
net/sctp/socket.c +2 -2
index d5d5882..dba117a 100644
@@ -343,7 +343,7 @@ static int sctp_do_bind(struct sock *sk, union sctp_addr *addr, int len)
 
 	snum = ntohs(addr->v4.sin_port);
 
-	pr_debug("%s: sk:%p, new addr:%pISc, port:%d, new port:%d, len:%d\n",
+	pr_debug("%s: sk:%p, new addr:%pIAc, port:%d, new port:%d, len:%d\n",
 		 __func__, sk, &addr->sa, bp->port, snum, len);
 
 	/* PF specific bind() address verification. */
@@ -797,7 +797,7 @@ static int sctp_send_asconf_del_ip(struct sock		*sk,
 				asoc->asconf_addr_del_pending->v6.sin6_addr = sin6->sin6_addr;
 			}
 
-			pr_debug("%s: keep the last address asoc:%p %pISc at %p\n",
+			pr_debug("%s: keep the last address asoc:%p %pIAc at %p\n",
 				 __func__, asoc, &asoc->asconf_addr_del_pending->sa,
 				 asoc->asconf_addr_del_pending);
 
Signature · 1 line
1.7.7.6
author
#3 lore raw

PATCH v3 3/9 net: introduce generic simple_inet_pton()

In reply to Cong Wang

From: Cong Wang <[email protected]>

simple_inet_pton() is a simple implementation of inet_pton() in kernel, the original code is already in netpoll, so just move it to global.

Cc Ben Hutchings <[email protected]>
Cc Stephen Hemminger <[email protected]>
---
 include/net/inet_addr.h |    3 +++
 net/core/netpoll.c      |   36 ++++++++----------------------------
 net/core/utils.c        |   36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+), 28 deletions(-)
include/net/inet_addr.h +3 -0
index 66a16fe..7289aed 100644
@@ -4,6 +4,7 @@
 #include <linux/in.h>
 #include <linux/in6.h>
 #include <linux/socket.h>
+#include <linux/inet.h>
 #include <net/addrconf.h>
 
 union inet_addr {
@@ -59,4 +60,6 @@ static inline bool inet_addr_multicast(const union inet_addr *ipa)
 }
 #endif
 
+int simple_inet_pton(const char *str, union inet_addr *addr);
+
 #endif
net/core/netpoll.c +8 -28
index 9a45c54..5b1d0c8 100644
@@ -908,30 +908,10 @@ void netpoll_print_options(struct netpoll *np)
 }
 EXPORT_SYMBOL(netpoll_print_options);
 
-static int netpoll_parse_ip_addr(const char *str, union inet_addr *addr)
-{
-	const char *end;
-
-	if (!strchr(str, ':') &&
-	    in4_pton(str, -1, (void *)addr, -1, &end) > 0) {
-		if (!*end)
-			return 0;
-	}
-	if (in6_pton(str, -1, addr->sin6.sin6_addr.s6_addr, -1, &end) > 0) {
-#if IS_ENABLED(CONFIG_IPV6)
-		if (!*end)
-			return 1;
-#else
-		return -1;
-#endif
-	}
-	return -1;
-}
-
 int netpoll_parse_options(struct netpoll *np, char *opt)
 {
 	char *cur=opt, *delim;
-	int ipv6;
+	int ret;
 
 	if (*cur != '@') {
 		if ((delim = strchr(cur, '@')) == NULL)
@@ -947,11 +927,11 @@ int netpoll_parse_options(struct netpoll *np, char *opt)
 		if ((delim = strchr(cur, '/')) == NULL)
 			goto parse_failed;
 		*delim = 0;
-		ipv6 = netpoll_parse_ip_addr(cur, &np->local_ip);
-		if (ipv6 < 0)
+		ret = simple_inet_pton(cur, &np->local_ip);
+		if (ret < 0)
 			goto parse_failed;
 		else
-			np->ipv6 = (bool)ipv6;
+			np->ipv6 = np->local_ip.sa.sa_family == AF_INET6;
 		cur = delim;
 	}
 	cur++;
@@ -983,13 +963,13 @@ int netpoll_parse_options(struct netpoll *np, char *opt)
 	if ((delim = strchr(cur, '/')) == NULL)
 		goto parse_failed;
 	*delim = 0;
-	ipv6 = netpoll_parse_ip_addr(cur, &np->remote_ip);
-	if (ipv6 < 0)
+	ret = simple_inet_pton(cur, &np->remote_ip);
+	if (ret < 0)
 		goto parse_failed;
-	else if (np->ipv6 != (bool)ipv6)
+	else if (np->ipv6 != (np->local_ip.sa.sa_family == AF_INET6))
 		goto parse_failed;
 	else
-		np->ipv6 = (bool)ipv6;
+		np->ipv6 = np->local_ip.sa.sa_family == AF_INET6;
 	cur = delim + 1;
 
 	if (*cur != 0) {
net/core/utils.c +36 -0
index aa88e23..22dd621 100644
@@ -29,6 +29,7 @@
 
 #include <net/sock.h>
 #include <net/net_ratelimit.h>
+#include <net/inet_addr.h>
 
 #include <asm/byteorder.h>
 #include <asm/uaccess.h>
@@ -338,3 +339,38 @@ void inet_proto_csum_replace16(__sum16 *sum, struct sk_buff *skb,
 				  csum_unfold(*sum)));
 }
 EXPORT_SYMBOL(inet_proto_csum_replace16);
+
+/**
+ * simple_inet_pton - a simple implementation of inet_pton()
+ * @str: the start of the IPv4 or IPv6 address string
+ * @addr: a pointer to union inet_addr
+ *
+ * Return zero on success, callers should check addr->sa.sa_family
+ * to know if the address is IPv4 or IPv6; return negative when
+ * any error occurs.
+ *
+ */
+int simple_inet_pton(const char *str, union inet_addr *addr)
+{
+	const char *end;
+
+	if (!strchr(str, ':') &&
+	    in4_pton(str, -1, (void *)addr, -1, &end) > 0) {
+		if (!*end) {
+			addr->sa.sa_family = AF_INET;
+			return 0;
+		}
+	}
+	if (in6_pton(str, -1, addr->sin6.sin6_addr.s6_addr, -1, &end) > 0) {
+#if IS_ENABLED(CONFIG_IPV6)
+		if (!*end) {
+			addr->sa.sa_family = AF_INET6;
+			return 0;
+		}
+#else
+		return -EAFNOSUPPORT;
+#endif
+	}
+	return -EINVAL;
+}
+EXPORT_SYMBOL(simple_inet_pton);
Signature · 1 line
1.7.7.6
author
#4 lore raw

PATCH v3 4/9 inetpeer: use generic struct in_addr_gen

In reply to Cong Wang

From: Cong Wang <[email protected]>

Similar definition of struct inetpeer_addr is used by bridge multciast code too, therefore it makes sense to introduce a generic struct in_addr_gen, so that code can be shared.

There is no more overhead for inet_peer structs now.

Cc Eric Dumazet <[email protected]>
---
 include/net/inet_addr.h |   22 ++++++++++++++
 include/net/inetpeer.h  |   25 ++++-----------
 net/ipv4/inetpeer.c     |   33 +++++++++++++-------
 net/ipv4/tcp_metrics.c  |   74 ++++++++++++++++++----------------------------
 4 files changed, 79 insertions(+), 75 deletions(-)
include/net/inet_addr.h +22 -0
index 7289aed..ee80df4 100644
@@ -13,6 +13,28 @@ union inet_addr {
 	struct sockaddr sa;
 };
 
+/* a simpler definition of generic inet addr, without additional
+ * information for IPv6 address.
+ */
+struct in_addr_gen {
+	union {
+		struct in_addr	in_addr;
+		struct in6_addr	in6_addr;
+	};
+	unsigned short int	family;
+};
+
+static inline
+bool in_addr_gen_equal(const struct in_addr_gen *a, const struct in_addr_gen *b)
+{
+	if (a->family != b->family)
+		return false;
+	if (a->family == AF_INET6)
+		return ipv6_addr_equal(&a->in6_addr, &b->in6_addr);
+	else
+		return a->in_addr.s_addr == b->in_addr.s_addr;
+}
+
 #if IS_ENABLED(CONFIG_IPV6)
 static inline
 bool inet_addr_equal(const union inet_addr *a, const union inet_addr *b)
include/net/inetpeer.h +7 -18
index 53f464d..9574843 100644
@@ -13,24 +13,13 @@
 #include <linux/spinlock.h>
 #include <linux/rtnetlink.h>
 #include <net/ipv6.h>
+#include <net/inet_addr.h>
 #include <linux/atomic.h>
 
-struct inetpeer_addr_base {
-	union {
-		__be32			a4;
-		__be32			a6[4];
-	};
-};
-
-struct inetpeer_addr {
-	struct inetpeer_addr_base	addr;
-	__u16				family;
-};
-
 struct inet_peer {
 	/* group together avl_left,avl_right,v4daddr to speedup lookups */
 	struct inet_peer __rcu	*avl_left, *avl_right;
-	struct inetpeer_addr	daddr;
+	struct in_addr_gen	daddr;
 	__u32			avl_height;
 
 	u32			metrics[RTAX_MAX];
@@ -133,16 +122,16 @@ static inline bool inet_metrics_new(const struct inet_peer *p)
 
 /* can be called with or without local BH being disabled */
 struct inet_peer *inet_getpeer(struct inet_peer_base *base,
-			       const struct inetpeer_addr *daddr,
+			       const struct in_addr_gen *daddr,
 			       int create);
 
 static inline struct inet_peer *inet_getpeer_v4(struct inet_peer_base *base,
 						__be32 v4daddr,
 						int create)
 {
-	struct inetpeer_addr daddr;
+	struct in_addr_gen daddr;
 
-	daddr.addr.a4 = v4daddr;
+	daddr.in_addr.s_addr = v4daddr;
 	daddr.family = AF_INET;
 	return inet_getpeer(base, &daddr, create);
 }
@@ -151,9 +140,9 @@ static inline struct inet_peer *inet_getpeer_v6(struct inet_peer_base *base,
 						const struct in6_addr *v6daddr,
 						int create)
 {
-	struct inetpeer_addr daddr;
+	struct in_addr_gen daddr;
 
-	*(struct in6_addr *)daddr.addr.a6 = *v6daddr;
+	daddr.in6_addr = *v6daddr;
 	daddr.family = AF_INET6;
 	return inet_getpeer(base, &daddr, create);
 }
net/ipv4/inetpeer.c +21 -12
index 000e3d2..70ffc9e 100644
@@ -197,17 +197,26 @@ void __init inet_initpeers(void)
 	INIT_DEFERRABLE_WORK(&gc_work, inetpeer_gc_worker);
 }
 
-static int addr_compare(const struct inetpeer_addr *a,
-			const struct inetpeer_addr *b)
+static int addr_compare(const struct in_addr_gen *a,
+			const struct in_addr_gen *b)
 {
-	int i, n = (a->family == AF_INET ? 1 : 4);
+	int i;
 
-	for (i = 0; i < n; i++) {
-		if (a->addr.a6[i] == b->addr.a6[i])
-			continue;
-		if ((__force u32)a->addr.a6[i] < (__force u32)b->addr.a6[i])
+	if (a->family == AF_INET) {
+		if (a->in_addr.s_addr == b->in_addr.s_addr)
+			return 0;
+		if ((__force u32)a->in_addr.s_addr <
+		    (__force u32)b->in_addr.s_addr)
 			return -1;
-		return 1;
+	} else {
+		for (i = 0; i < 4; i++) {
+			if (a->in6_addr.s6_addr32[i] == b->in6_addr.s6_addr32[i])
+				continue;
+			if ((__force u32)a->in6_addr.s6_addr32[i] <
+			    (__force u32)b->in6_addr.s6_addr32[i])
+				return -1;
+			return 1;
+		}
 	}
 
 	return 0;
@@ -248,7 +257,7 @@ static int addr_compare(const struct inetpeer_addr *a,
  * But every pointer we follow is guaranteed to be valid thanks to RCU.
  * We exit from this function if number of links exceeds PEER_MAXDEPTH
  */
-static struct inet_peer *lookup_rcu(const struct inetpeer_addr *daddr,
+static struct inet_peer *lookup_rcu(const struct in_addr_gen *daddr,
 				    struct inet_peer_base *base)
 {
 	struct inet_peer *u = rcu_dereference(base->root);
@@ -457,7 +466,7 @@ static int inet_peer_gc(struct inet_peer_base *base,
 }
 
 struct inet_peer *inet_getpeer(struct inet_peer_base *base,
-			       const struct inetpeer_addr *daddr,
+			       const struct in_addr_gen *daddr,
 			       int create)
 {
 	struct inet_peer __rcu **stack[PEER_MAXDEPTH], ***stackptr;
@@ -506,8 +515,8 @@ relookup:
 		atomic_set(&p->rid, 0);
 		atomic_set(&p->ip_id_count,
 				(daddr->family == AF_INET) ?
-					secure_ip_id(daddr->addr.a4) :
-					secure_ipv6_id(daddr->addr.a6));
+					secure_ip_id(daddr->in_addr.s_addr) :
+					secure_ipv6_id(daddr->in6_addr.s6_addr32));
 		p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
 		p->rate_tokens = 0;
 		/* 60*HZ is arbitrary, but chosen enough high so that the first
net/ipv4/tcp_metrics.c +29 -45

211 lines not on this page · raw message

Signature · 1 line
1.7.7.6
author
#5 lore raw

PATCH v3 5/9 bridge: use generic struct in_addr_gen

In reply to Cong Wang

From: Cong Wang <[email protected]>

Cc Stephen Hemminger <[email protected]>
---
 net/bridge/br_mdb.c       |   53 ++++++++++++++++++------------------
 net/bridge/br_multicast.c |   65 +++++++++++++++++++-------------------------
 net/bridge/br_private.h   |    9 +-----
 3 files changed, 57 insertions(+), 70 deletions(-)
net/bridge/br_mdb.c +27 -26
index e4d5cd4..55d6b59 100644
@@ -13,6 +13,29 @@
 
 #include "br_private.h"
 
+static void br_ip_to_entry(struct br_mdb_entry *entry, struct br_ip *ip)
+{
+	if (ip->ip.family == AF_INET) {
+		entry->addr.proto = htons(ETH_P_IP);
+		entry->addr.u.ip4 = ip->ip.in_addr.s_addr;
+	} else {
+		entry->addr.proto = htons(ETH_P_IPV6);
+		entry->addr.u.ip6 = ip->ip.in6_addr;
+	}
+}
+
+static void br_entry_to_ip(struct br_ip *ip, struct br_mdb_entry *entry)
+{
+	__be16 proto = entry->addr.proto;
+	if (proto == htons(ETH_P_IP)) {
+		ip->ip.family = AF_INET;
+		ip->ip.in_addr.s_addr = entry->addr.u.ip4;
+	} else {
+		ip->ip.family = AF_INET6;
+		ip->ip.in6_addr = entry->addr.u.ip6;
+	}
+}
+
 static int br_rports_fill_info(struct sk_buff *skb, struct netlink_callback *cb,
 			       struct net_device *dev)
 {
@@ -84,13 +107,7 @@ static int br_mdb_fill_info(struct sk_buff *skb, struct netlink_callback *cb,
 					memset(&e, 0, sizeof(e));
 					e.ifindex = port->dev->ifindex;
 					e.state = p->state;
-					if (p->addr.proto == htons(ETH_P_IP))
-						e.addr.u.ip4 = p->addr.u.ip4;
-#if IS_ENABLED(CONFIG_IPV6)
-					if (p->addr.proto == htons(ETH_P_IPV6))
-						e.addr.u.ip6 = p->addr.u.ip6;
-#endif
-					e.addr.proto = p->addr.proto;
+					br_ip_to_entry(&e, &p->addr);
 					if (nla_put(skb, MDBA_MDB_ENTRY_INFO, sizeof(e), &e)) {
 						nla_nest_cancel(skb, nest2);
 						err = -EMSGSIZE;
@@ -234,11 +251,7 @@ void br_mdb_notify(struct net_device *dev, struct net_bridge_port *port,
 
 	memset(&entry, 0, sizeof(entry));
 	entry.ifindex = port->dev->ifindex;
-	entry.addr.proto = group->proto;
-	entry.addr.u.ip4 = group->u.ip4;
-#if IS_ENABLED(CONFIG_IPV6)
-	entry.addr.u.ip6 = group->u.ip6;
-#endif
+	br_ip_to_entry(&entry, group);
 	__br_mdb_notify(dev, &entry, type);
 }
 
@@ -369,13 +382,7 @@ static int __br_mdb_add(struct net *net, struct net_bridge *br,
 	if (!p || p->br != br || p->state == BR_STATE_DISABLED)
 		return -EINVAL;
 
-	ip.proto = entry->addr.proto;
-	if (ip.proto == htons(ETH_P_IP))
-		ip.u.ip4 = entry->addr.u.ip4;
-#if IS_ENABLED(CONFIG_IPV6)
-	else
-		ip.u.ip6 = entry->addr.u.ip6;
-#endif
+	br_entry_to_ip(&ip, entry);
 
 	spin_lock_bh(&br->multicast_lock);
 	ret = br_mdb_add_group(br, p, &ip, entry->state);
@@ -418,13 +425,7 @@ static int __br_mdb_del(struct net_bridge *br, struct br_mdb_entry *entry)
 	if (timer_pending(&br->multicast_querier_timer))
 		return -EBUSY;
 
-	ip.proto = entry->addr.proto;
-	if (ip.proto == htons(ETH_P_IP))
-		ip.u.ip4 = entry->addr.u.ip4;
-#if IS_ENABLED(CONFIG_IPV6)
-	else
-		ip.u.ip6 = entry->addr.u.ip6;
-#endif
+	br_entry_to_ip(&ip, entry);
 
 	spin_lock_bh(&br->multicast_lock);
 	mdb = mlock_dereference(br->mdb, br);
net/bridge/br_multicast.c +28 -37

148 lines not on this page · raw message

net/bridge/br_private.h +2 -7
index d41283c..4a5a52a 100644
@@ -19,6 +19,7 @@
 #include <linux/u64_stats_sync.h>
 #include <net/route.h>
 #include <linux/if_vlan.h>
+#include <net/inet_addr.h>
 
 #define BR_HASH_BITS 8
 #define BR_HASH_SIZE (1 << BR_HASH_BITS)
@@ -56,13 +57,7 @@ struct mac_addr
 
 struct br_ip
 {
-	union {
-		__be32	ip4;
-#if IS_ENABLED(CONFIG_IPV6)
-		struct in6_addr ip6;
-#endif
-	} u;
-	__be16		proto;
+	struct in_addr_gen ip;
 	__u16		vid;
 };
 
Signature · 1 line
1.7.7.6
author
#6 lore raw

PATCH v3 6/9 sunrpc: use generic union inet_addr

In reply to Cong Wang

From: Cong Wang <[email protected]>

sunrpc defines some helper functions for sockaddr, actually they can re-use the generic functions for union inet_addr too.

Cc Jeff Layton <[email protected]>
Cc Trond Myklebust <[email protected]>
Cc "J. Bruce Fields" <[email protected]>
---
 fs/lockd/clntlock.c             |    2 +-
 fs/lockd/host.c                 |    8 +-
 fs/lockd/mon.c                  |    2 +-
 fs/lockd/svcsubs.c              |    2 +-
 fs/nfs/nfs4namespace.c          |    2 +-
 fs/nfs/super.c                  |    6 +-
 fs/nfsd/nfs4state.c             |    6 +-
 fs/nfsd/nfscache.c              |    8 +-
 include/linux/sunrpc/addr.h     |  131 +--------------------------------------
 include/net/inet_addr.h         |   99 ++++++++++++++++++++++++-----
 net/core/utils.c                |   25 ++++++++
 net/sunrpc/clnt.c               |    2 +-
 net/sunrpc/rpcb_clnt.c          |    2 +-
 net/sunrpc/xprtrdma/transport.c |    4 +-
 net/sunrpc/xprtsock.c           |    8 +-
 15 files changed, 134 insertions(+), 173 deletions(-)
fs/lockd/clntlock.c +1 -1
index 41e491b..289444e 100644
@@ -184,7 +184,7 @@ __be32 nlmclnt_grant(const struct sockaddr *addr, const struct nlm_lock *lock)
 		 */
 		if (fl_blocked->fl_u.nfs_fl.owner->pid != lock->svid)
 			continue;
-		if (!rpc_cmp_addr(nlm_addr(block->b_host), addr))
+		if (!sockaddr_equal(nlm_addr(block->b_host), addr))
 			continue;
 		if (nfs_compare_fh(NFS_FH(file_inode(fl_blocked->fl_file)) ,fh) != 0)
 			continue;
fs/lockd/host.c +4 -4
index 969d589..155c720 100644
@@ -134,7 +134,7 @@ static struct nlm_host *nlm_alloc_host(struct nlm_lookup_host_info *ni,
 
 	memcpy(nlm_addr(host), ni->sap, ni->salen);
 	host->h_addrlen    = ni->salen;
-	rpc_set_port(nlm_addr(host), 0);
+	sockaddr_set_port(nlm_addr(host), 0);
 	host->h_srcaddrlen = 0;
 
 	host->h_rpcclnt    = NULL;
@@ -240,7 +240,7 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap,
 	hlist_for_each_entry(host, chain, h_hash) {
 		if (host->net != net)
 			continue;
-		if (!rpc_cmp_addr(nlm_addr(host), sap))
+		if (!sockaddr_equal(nlm_addr(host), sap))
 			continue;
 
 		/* Same address. Share an NSM handle if we already have one */
@@ -352,7 +352,7 @@ struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp,
 	hlist_for_each_entry(host, chain, h_hash) {
 		if (host->net != net)
 			continue;
-		if (!rpc_cmp_addr(nlm_addr(host), ni.sap))
+		if (!sockaddr_equal(nlm_addr(host), ni.sap))
 			continue;
 
 		/* Same address. Share an NSM handle if we already have one */
@@ -363,7 +363,7 @@ struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp,
 			continue;
 		if (host->h_version != ni.version)
 			continue;
-		if (!rpc_cmp_addr(nlm_srcaddr(host), src_sap))
+		if (!sockaddr_equal(nlm_srcaddr(host), src_sap))
 			continue;
 
 		/* Move to head of hash chain. */
fs/lockd/mon.c +1 -1
index 1812f02..d36d65a 100644
@@ -270,7 +270,7 @@ static struct nsm_handle *nsm_lookup_addr(const struct sockaddr *sap)
 	struct nsm_handle *nsm;
 
 	list_for_each_entry(nsm, &nsm_handles, sm_link)
-		if (rpc_cmp_addr(nsm_addr(nsm), sap))
+		if (sockaddr_equal(nsm_addr(nsm), sap))
 			return nsm;
 	return NULL;
 }
fs/lockd/svcsubs.c +1 -1
index dc5c759..a9f4a6f 100644
@@ -431,7 +431,7 @@ EXPORT_SYMBOL_GPL(nlmsvc_unlock_all_by_sb);
 static int
 nlmsvc_match_ip(void *datap, struct nlm_host *host)
 {
-	return rpc_cmp_addr(nlm_srcaddr(host), datap);
+	return sockaddr_equal(nlm_srcaddr(host), datap);
 }
 
 /**
fs/nfs/nfs4namespace.c +1 -1
index cdb0b41..79767fc 100644
@@ -243,7 +243,7 @@ static struct vfsmount *try_location(struct nfs_clone_mount *mountdata,
 		if (mountdata->addrlen == 0)
 			continue;
 
-		rpc_set_port(mountdata->addr, NFS_PORT);
+		sockaddr_set_port(mountdata->addr, NFS_PORT);
 
 		memcpy(page2, buf->data, buf->len);
 		page2[buf->len] = '\0';
fs/nfs/super.c +3 -3
index f6db66d..ac7c359 100644
@@ -978,7 +978,7 @@ static void nfs_set_port(struct sockaddr *sap, int *port,
 	if (*port == NFS_UNSPEC_PORT)
 		*port = default_port;
 
-	rpc_set_port(sap, *port);
+	sockaddr_set_port(sap, *port);
 }
 
 /*
@@ -2133,8 +2133,8 @@ nfs_compare_remount_data(struct nfs_server *nfss,
 	    data->timeo != (10U * nfss->client->cl_timeout->to_initval / HZ) ||
 	    data->nfs_server.port != nfss->port ||
 	    data->nfs_server.addrlen != nfss->nfs_client->cl_addrlen ||
-	    !rpc_cmp_addr((struct sockaddr *)&data->nfs_server.address,
-			  (struct sockaddr *)&nfss->nfs_client->cl_addr))
+	    !sockaddr_equal((struct sockaddr *)&data->nfs_server.address,
+			    (struct sockaddr *)&nfss->nfs_client->cl_addr))
 		return -EINVAL;
 
 	return 0;
fs/nfsd/nfs4state.c +3 -3
index 43f4229..92689bf 100644
@@ -1009,7 +1009,7 @@ static void init_session(struct svc_rqst *rqstp, struct nfsd4_session *new, stru
 		 * the rpc client not to require an address in the
 		 * future:
 		 */
-		rpc_copy_addr((struct sockaddr *)&clp->cl_cb_conn.cb_addr, sa);
+		sockaddr_copy((struct sockaddr *)&clp->cl_cb_conn.cb_addr, sa);
 		clp->cl_cb_conn.cb_addrlen = svc_addr_len(sa);
 	}
 }
@@ -1362,7 +1362,7 @@ static struct nfs4_client *create_client(struct xdr_netobj name,
 	clear_bit(0, &clp->cl_cb_slot_busy);
 	rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
 	copy_verf(clp, verf);
-	rpc_copy_addr((struct sockaddr *) &clp->cl_addr, sa);
+	sockaddr_copy((struct sockaddr *) &clp->cl_addr, sa);
 	gen_confirm(clp);
 	clp->cl_cb_session = NULL;
 	clp->net = net;
@@ -1939,7 +1939,7 @@ nfsd4_create_session(struct svc_rqst *rqstp,
 	} else if (unconf) {
 		struct nfs4_client *old;
 		if (!same_creds(&unconf->cl_cred, &rqstp->rq_cred) ||
-		    !rpc_cmp_addr(sa, (struct sockaddr *) &unconf->cl_addr)) {
+		    !sockaddr_equal(sa, (struct sockaddr *) &unconf->cl_addr)) {
 			status = nfserr_clid_inuse;
 			goto out_free_conn;
 		}
fs/nfsd/nfscache.c +4 -4
index e76244e..e2561d6 100644
@@ -318,8 +318,8 @@ nfsd_cache_match(struct svc_rqst *rqstp, __wsum csum, struct svc_cacherep *rp)
 	if (rqstp->rq_xid != rp->c_xid || rqstp->rq_proc != rp->c_proc ||
 	    rqstp->rq_prot != rp->c_prot || rqstp->rq_vers != rp->c_vers ||
 	    rqstp->rq_arg.len != rp->c_len ||
-	    !rpc_cmp_addr(svc_addr(rqstp), (struct sockaddr *)&rp->c_addr) ||
-	    rpc_get_port(svc_addr(rqstp)) != rpc_get_port((struct sockaddr *)&rp->c_addr))
+	    !sockaddr_equal(svc_addr(rqstp), (struct sockaddr *)&rp->c_addr) ||
+	    sockaddr_get_port(svc_addr(rqstp)) != sockaddr_get_port((struct sockaddr *)&rp->c_addr))
 		return false;
 
 	/* compare checksum of NFS data */
@@ -446,8 +446,8 @@ search_cache:
 	rp->c_state = RC_INPROG;
 	rp->c_xid = xid;
 	rp->c_proc = proc;
-	rpc_copy_addr((struct sockaddr *)&rp->c_addr, svc_addr(rqstp));
-	rpc_set_port((struct sockaddr *)&rp->c_addr, rpc_get_port(svc_addr(rqstp)));
+	sockaddr_equal((struct sockaddr *)&rp->c_addr, svc_addr(rqstp));
+	sockaddr_set_port((struct sockaddr *)&rp->c_addr, sockaddr_get_port(svc_addr(rqstp)));
 	rp->c_prot = proto;
 	rp->c_vers = vers;
 	rp->c_len = rqstp->rq_arg.len;
include/linux/sunrpc/addr.h +1 -130

146 lines not on this page · raw message

include/net/inet_addr.h +82 -17

117 lines not on this page · raw message

net/core/utils.c +25 -0
index 22dd621..837bb18 100644
@@ -374,3 +374,28 @@ int simple_inet_pton(const char *str, union inet_addr *addr)
 	return -EINVAL;
 }
 EXPORT_SYMBOL(simple_inet_pton);
+
+#if IS_ENABLED(CONFIG_IPV6)
+bool inet_addr_equal(const union inet_addr *a, const union inet_addr *b)
+{
+	if (a->sa.sa_family != b->sa.sa_family)
+		return false;
+	else if (a->sa.sa_family == AF_INET6) {
+		if (!ipv6_addr_equal(&a->sin6.sin6_addr, &b->sin6.sin6_addr))
+			return false;
+		else if (__ipv6_addr_needs_scope_id(__ipv6_addr_type(&a->sin6.sin6_addr)))
+			return a->sin6.sin6_scope_id == b->sin6.sin6_scope_id;
+		else
+			return true;
+	} else
+		return a->sin.sin_addr.s_addr == b->sin.sin_addr.s_addr;
+}
+#else
+bool inet_addr_equal(const union inet_addr *a, const union inet_addr *b)
+{
+	if (a->sa.sa_family == AF_UNSPEC)
+		return a->sa.sa_family == b->sa.sa_family;
+	return a->sin.sin_addr.s_addr == b->sin.sin_addr.s_addr;
+}
+#endif
+EXPORT_SYMBOL(inet_addr_equal);
net/sunrpc/clnt.c +1 -1
index ecbc4e3..49fe013 100644
@@ -1137,7 +1137,7 @@ int rpc_localaddr(struct rpc_clnt *clnt, struct sockaddr *buf, size_t buflen)
 	net = get_net(xprt->xprt_net);
 	rcu_read_unlock();
 
-	rpc_set_port(sap, 0);
+	sockaddr_set_port(sap, 0);
 	err = rpc_sockname(net, sap, salen, buf, buflen);
 	put_net(net);
 	if (err != 0)
net/sunrpc/rpcb_clnt.c +1 -1
index 1891a10..8078161 100644
@@ -971,7 +971,7 @@ static int rpcb_dec_getaddr(struct rpc_rqst *req, struct xdr_stream *xdr,
 	if (rpc_uaddr2sockaddr(req->rq_xprt->xprt_net, (char *)p, len,
 				sap, sizeof(address)) == 0)
 		goto out_fail;
-	rpcb->r_port = rpc_get_port(sap);
+	rpcb->r_port = sockaddr_get_port(sap);
 
 	return 0;
 
net/sunrpc/xprtrdma/transport.c +2 -2
index 285dc08..aa09a36 100644
@@ -162,7 +162,7 @@ xprt_rdma_format_addresses(struct rpc_xprt *xprt)
 	(void)rpc_ntop(sap, buf, sizeof(buf));
 	xprt->address_strings[RPC_DISPLAY_ADDR] = kstrdup(buf, GFP_KERNEL);
 
-	snprintf(buf, sizeof(buf), "%u", rpc_get_port(sap));
+	snprintf(buf, sizeof(buf), "%u", sockaddr_get_port(sap));
 	xprt->address_strings[RPC_DISPLAY_PORT] = kstrdup(buf, GFP_KERNEL);
 
 	xprt->address_strings[RPC_DISPLAY_PROTO] = "rdma";
@@ -170,7 +170,7 @@ xprt_rdma_format_addresses(struct rpc_xprt *xprt)
 	snprintf(buf, sizeof(buf), "%08x", ntohl(sin->sin_addr.s_addr));
 	xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = kstrdup(buf, GFP_KERNEL);
 
-	snprintf(buf, sizeof(buf), "%4hx", rpc_get_port(sap));
+	snprintf(buf, sizeof(buf), "%4hx", sockaddr_get_port(sap));
 	xprt->address_strings[RPC_DISPLAY_HEX_PORT] = kstrdup(buf, GFP_KERNEL);
 
 	/* netid */
net/sunrpc/xprtsock.c +4 -4
index d6656d7..5922c8b 100644
@@ -333,10 +333,10 @@ static void xs_format_common_peer_ports(struct rpc_xprt *xprt)
 	struct sockaddr *sap = xs_addr(xprt);
 	char buf[128];
 
-	snprintf(buf, sizeof(buf), "%u", rpc_get_port(sap));
+	snprintf(buf, sizeof(buf), "%u", sockaddr_get_port(sap));
 	xprt->address_strings[RPC_DISPLAY_PORT] = kstrdup(buf, GFP_KERNEL);
 
-	snprintf(buf, sizeof(buf), "%4hx", rpc_get_port(sap));
+	snprintf(buf, sizeof(buf), "%4hx", sockaddr_get_port(sap));
 	xprt->address_strings[RPC_DISPLAY_HEX_PORT] = kstrdup(buf, GFP_KERNEL);
 }
 
@@ -1674,7 +1674,7 @@ static void xs_set_port(struct rpc_xprt *xprt, unsigned short port)
 {
 	dprintk("RPC:       setting port for xprt %p to %u\n", xprt, port);
 
-	rpc_set_port(xs_addr(xprt), port);
+	sockaddr_set_port(xs_addr(xprt), port);
 	xs_update_peer_port(xprt);
 }
 
@@ -1706,7 +1706,7 @@ static int xs_bind(struct sock_xprt *transport, struct socket *sock)
 
 	memcpy(&myaddr, &transport->srcaddr, transport->xprt.addrlen);
 	do {
-		rpc_set_port((struct sockaddr *)&myaddr, port);
+		sockaddr_set_port((struct sockaddr *)&myaddr, port);
 		err = kernel_bind(sock, (struct sockaddr *)&myaddr,
 				transport->xprt.addrlen);
 		if (port == 0)
Signature · 1 line
1.7.7.6
author
#7 lore raw

PATCH v3 7/9 fs: use generic union inet_addr and helper functions

In reply to Cong Wang

From: Cong Wang <[email protected]>

nfs and cifs define some helper functions for sockaddr, they can use the generic functions for union inet_addr/struct sockaddr too.

Since some dlm code needs to compare ->sin_port, introduce a generic function inet_addr_equal_strict() for it.

Cc Steve French <[email protected]>
Cc Christine Caulfield <[email protected]>
Cc David Teigland <[email protected]>
Cc Trond Myklebust <[email protected]>
Cc linux-cifs at vger.kernel.org
Cc linux-kernel at vger.kernel.org
Cc cluster-devel at redhat.com
Cc linux-nfs at vger.kernel.org
---
 fs/cifs/connect.c          |   54 +++++---------------
 fs/dlm/lowcomms.c          |   24 ++-------
 fs/nfs/client.c            |  113 +-------------------------------------------
 fs/nfs/nfs4client.c        |    2 +-
 fs/nfs/nfs4filelayoutdev.c |   37 ++-------------
 fs/nfs/super.c             |   31 +-----------
 include/net/inet_addr.h    |    8 +++
 net/core/utils.c           |   23 +++++++++
 8 files changed, 60 insertions(+), 232 deletions(-)
fs/cifs/connect.c +14 -40
index d67c550..081cb6c 100644
@@ -40,6 +40,7 @@
 #include <linux/module.h>
 #include <keys/user-type.h>
 #include <net/ipv6.h>
+#include <net/inet_addr.h>
 #include <linux/parser.h>
 
 #include "cifspdu.h"
@@ -1900,17 +1901,9 @@ srcip_matches(struct sockaddr *srcaddr, struct sockaddr *rhs)
 {
 	switch (srcaddr->sa_family) {
 	case AF_UNSPEC:
-		return (rhs->sa_family == AF_UNSPEC);
-	case AF_INET: {
-		struct sockaddr_in *saddr4 = (struct sockaddr_in *)srcaddr;
-		struct sockaddr_in *vaddr4 = (struct sockaddr_in *)rhs;
-		return (saddr4->sin_addr.s_addr == vaddr4->sin_addr.s_addr);
-	}
-	case AF_INET6: {
-		struct sockaddr_in6 *saddr6 = (struct sockaddr_in6 *)srcaddr;
-		struct sockaddr_in6 *vaddr6 = (struct sockaddr_in6 *)rhs;
-		return ipv6_addr_equal(&saddr6->sin6_addr, &vaddr6->sin6_addr);
-	}
+	case AF_INET:
+	case AF_INET6:
+		return sockaddr_equal(srcaddr, rhs);
 	default:
 		WARN_ON(1);
 		return false; /* don't expect to be here */
@@ -1925,16 +1918,13 @@ srcip_matches(struct sockaddr *srcaddr, struct sockaddr *rhs)
 static bool
 match_port(struct TCP_Server_Info *server, struct sockaddr *addr)
 {
-	__be16 port, *sport;
+	unsigned short port, sport;
 
 	switch (addr->sa_family) {
 	case AF_INET:
-		sport = &((struct sockaddr_in *) &server->dstaddr)->sin_port;
-		port = ((struct sockaddr_in *) addr)->sin_port;
-		break;
 	case AF_INET6:
-		sport = &((struct sockaddr_in6 *) &server->dstaddr)->sin6_port;
-		port = ((struct sockaddr_in6 *) addr)->sin6_port;
+		sport = sockaddr_get_port((struct sockaddr *)&server->dstaddr);
+		port = sockaddr_get_port(addr);
 		break;
 	default:
 		WARN_ON(1);
@@ -1942,14 +1932,14 @@ match_port(struct TCP_Server_Info *server, struct sockaddr *addr)
 	}
 
 	if (!port) {
-		port = htons(CIFS_PORT);
-		if (port == *sport)
+		port = CIFS_PORT;
+		if (port == sport)
 			return true;
 
-		port = htons(RFC1001_PORT);
+		port = RFC1001_PORT;
 	}
 
-	return port == *sport;
+	return port == sport;
 }
 
 static bool
@@ -1957,27 +1947,11 @@ match_address(struct TCP_Server_Info *server, struct sockaddr *addr,
 	      struct sockaddr *srcaddr)
 {
 	switch (addr->sa_family) {
-	case AF_INET: {
-		struct sockaddr_in *addr4 = (struct sockaddr_in *)addr;
-		struct sockaddr_in *srv_addr4 =
-					(struct sockaddr_in *)&server->dstaddr;
-
-		if (addr4->sin_addr.s_addr != srv_addr4->sin_addr.s_addr)
-			return false;
-		break;
-	}
-	case AF_INET6: {
-		struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)addr;
-		struct sockaddr_in6 *srv_addr6 =
-					(struct sockaddr_in6 *)&server->dstaddr;
-
-		if (!ipv6_addr_equal(&addr6->sin6_addr,
-				     &srv_addr6->sin6_addr))
-			return false;
-		if (addr6->sin6_scope_id != srv_addr6->sin6_scope_id)
+	case AF_INET:
+	case AF_INET6:
+		if (!sockaddr_equal(addr, (struct sockaddr *)&server->dstaddr))
 			return false;
 		break;
-	}
 	default:
 		WARN_ON(1);
 		return false; /* don't expect to be here */
fs/dlm/lowcomms.c +5 -19
index d90909e..c051237 100644
@@ -54,6 +54,7 @@
 #include <linux/slab.h>
 #include <net/sctp/sctp.h>
 #include <net/ipv6.h>
+#include <net/inet_addr.h>
 
 #include "dlm_internal.h"
 #include "lowcomms.h"
@@ -286,28 +287,13 @@ static struct dlm_node_addr *find_node_addr(int nodeid)
 static int addr_compare(struct sockaddr_storage *x, struct sockaddr_storage *y)
 {
 	switch (x->ss_family) {
-	case AF_INET: {
-		struct sockaddr_in *sinx = (struct sockaddr_in *)x;
-		struct sockaddr_in *siny = (struct sockaddr_in *)y;
-		if (sinx->sin_addr.s_addr != siny->sin_addr.s_addr)
-			return 0;
-		if (sinx->sin_port != siny->sin_port)
-			return 0;
-		break;
-	}
-	case AF_INET6: {
-		struct sockaddr_in6 *sinx = (struct sockaddr_in6 *)x;
-		struct sockaddr_in6 *siny = (struct sockaddr_in6 *)y;
-		if (!ipv6_addr_equal(&sinx->sin6_addr, &siny->sin6_addr))
-			return 0;
-		if (sinx->sin6_port != siny->sin6_port)
-			return 0;
-		break;
-	}
+	case AF_INET:
+	case AF_INET6:
+		return inet_addr_equal_strict((union inet_addr *)x,
+					      (union inet_addr *)y);
 	default:
 		return 0;
 	}
-	return 1;
 }
 
 static int nodeid_to_addr(int nodeid, struct sockaddr_storage *sas_out,
fs/nfs/client.c +2 -111

131 lines not on this page · raw message

fs/nfs/nfs4client.c +1 -1
index 90dce91..383b97a 100644
@@ -552,7 +552,7 @@ static bool nfs4_cb_match_client(const struct sockaddr *addr,
 		return false;
 
 	/* Match only the IP address, not the port number */
-	if (!nfs_sockaddr_match_ipaddr(addr, clap))
+	if (!sockaddr_equal(addr, clap))
 		return false;
 
 	return true;
fs/nfs/nfs4filelayoutdev.c +4 -33
index 95604f6..955494cb 100644
@@ -32,6 +32,7 @@
 #include <linux/vmalloc.h>
 #include <linux/module.h>
 #include <linux/sunrpc/addr.h>
+#include <net/inet_addr.h>
 
 #include "internal.h"
 #include "nfs4session.h"
@@ -74,44 +75,14 @@ print_ds(struct nfs4_pnfs_ds *ds)
 static bool
 same_sockaddr(struct sockaddr *addr1, struct sockaddr *addr2)
 {
-	struct sockaddr_in *a, *b;
-	struct sockaddr_in6 *a6, *b6;
-
-	if (addr1->sa_family != addr2->sa_family)
-		return false;
-
-	switch (addr1->sa_family) {
-	case AF_INET:
-		a = (struct sockaddr_in *)addr1;
-		b = (struct sockaddr_in *)addr2;
-
-		if (a->sin_addr.s_addr == b->sin_addr.s_addr &&
-		    a->sin_port == b->sin_port)
-			return true;
-		break;
-
-	case AF_INET6:
-		a6 = (struct sockaddr_in6 *)addr1;
-		b6 = (struct sockaddr_in6 *)addr2;
-
-		/* LINKLOCAL addresses must have matching scope_id */
-		if (ipv6_addr_scope(&a6->sin6_addr) ==
-		    IPV6_ADDR_SCOPE_LINKLOCAL &&
-		    a6->sin6_scope_id != b6->sin6_scope_id)
-			return false;
-
-		if (ipv6_addr_equal(&a6->sin6_addr, &b6->sin6_addr) &&
-		    a6->sin6_port == b6->sin6_port)
-			return true;
-		break;
-
-	default:
+	if (addr1->sa_family != AF_INET && addr1->sa_family != AF_INET6) {
 		dprintk("%s: unhandled address family: %u\n",
 			__func__, addr1->sa_family);
 		return false;
 	}
 
-	return false;
+	return inet_addr_equal_strict((union inet_addr *)addr1,
+				      (union inet_addr *)addr2);
 }
 
 static bool
fs/nfs/super.c +3 -28
index ac7c359..0744abb 100644
@@ -49,6 +49,7 @@
 #include <linux/in6.h>
 #include <linux/slab.h>
 #include <net/ipv6.h>
+#include <net/inet_addr.h>
 #include <linux/netdevice.h>
 #include <linux/nfs_xdr.h>
 #include <linux/magic.h>
@@ -2335,34 +2336,8 @@ static int nfs_compare_super_address(struct nfs_server *server1,
 
 	sap1 = (struct sockaddr *)&server1->nfs_client->cl_addr;
 	sap2 = (struct sockaddr *)&server2->nfs_client->cl_addr;
-
-	if (sap1->sa_family != sap2->sa_family)
-		return 0;
-
-	switch (sap1->sa_family) {
-	case AF_INET: {
-		struct sockaddr_in *sin1 = (struct sockaddr_in *)sap1;
-		struct sockaddr_in *sin2 = (struct sockaddr_in *)sap2;
-		if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr)
-			return 0;
-		if (sin1->sin_port != sin2->sin_port)
-			return 0;
-		break;
-	}
-	case AF_INET6: {
-		struct sockaddr_in6 *sin1 = (struct sockaddr_in6 *)sap1;
-		struct sockaddr_in6 *sin2 = (struct sockaddr_in6 *)sap2;
-		if (!ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr))
-			return 0;
-		if (sin1->sin6_port != sin2->sin6_port)
-			return 0;
-		break;
-	}
-	default:
-		return 0;
-	}
-
-	return 1;
+	return inet_addr_equal_strict((union inet_addr *)sap1,
+				      (union inet_addr *)sap2);
 }
 
 static int nfs_compare_super(struct super_block *sb, void *data)
include/net/inet_addr.h +8 -0
index 44179c8..f317f0f 100644
@@ -122,6 +122,7 @@ void inet_addr_set_port(union inet_addr *sap,
 }
 
 bool inet_addr_equal(const union inet_addr *a, const union inet_addr *b);
+bool inet_addr_equal_strict(const union inet_addr *a, const union inet_addr *b);
 int simple_inet_pton(const char *str, union inet_addr *addr);
 
 static inline bool sockaddr_equal(const struct sockaddr *sap1,
@@ -131,6 +132,13 @@ static inline bool sockaddr_equal(const struct sockaddr *sap1,
 			       (const union inet_addr *)sap2);
 }
 
+static inline int sockaddr_equal_strict(const struct sockaddr *sa1,
+					const struct sockaddr *sa2)
+{
+	return inet_addr_equal_strict((union inet_addr *)sa1,
+				      (union inet_addr *)sa2);
+}
+
 static inline bool sockaddr_copy(struct sockaddr *dst,
 				 const struct sockaddr *src)
 {
net/core/utils.c +23 -0
index 837bb18..489bc8d 100644
@@ -380,6 +380,8 @@ bool inet_addr_equal(const union inet_addr *a, const union inet_addr *b)
 {
 	if (a->sa.sa_family != b->sa.sa_family)
 		return false;
+	if (a->sa.sa_family == AF_UNSPEC)
+		return true;
 	else if (a->sa.sa_family == AF_INET6) {
 		if (!ipv6_addr_equal(&a->sin6.sin6_addr, &b->sin6.sin6_addr))
 			return false;
@@ -399,3 +401,24 @@ bool inet_addr_equal(const union inet_addr *a, const union inet_addr *b)
 }
 #endif
 EXPORT_SYMBOL(inet_addr_equal);
+
+/*
+ * Unlike inet_addr_equal(), this function compares ->sin_port too.
+ */
+bool inet_addr_equal_strict(const union inet_addr *a, const union inet_addr *b)
+{
+	if (inet_addr_equal(a, b)) {
+		switch (a->sa.sa_family) {
+#if IS_ENABLED(CONFIG_IPV6)
+		case AF_INET6:
+			return a->sin6.sin6_port == b->sin6.sin6_port;
+#endif
+		case AF_INET:
+			return a->sin.sin_port == b->sin.sin_port;
+		default:
+			return true;
+		}
+	} else
+		return false;
+}
+EXPORT_SYMBOL(inet_addr_equal_strict);
Signature · 1 line
1.7.7.6
#8 lore raw

Re: [Patch net-next v3 7/9] fs: use generic union inet_addr and helper functions

Review srcip_matches(struct sockaddr *srcaddr, struct sockaddr *rhs) · line 1901

Quoted 2 lines
(quoted diff) +0 -0
@@ -1900,17 +1901,9 @@ srcip_matches(struct sockaddr *srcaddr, struct sockaddr *rhs)
 {

I think your new sockaddr_equal should be equivalent to to this srcip_matches, that is it should warn about and return false for unknown address families.

author
#9 lore raw

PATCH v3 8/9 sctp: use generic union inet_addr

In reply to Cong Wang

From: Cong Wang <[email protected]>

sctp has its own union sctp_addr which is nearly same with the generic union inet_addr, so just convert it to the generic one.

Sorry for the big patch, it is not easy to split it. Most of the patch simply does s/union sctp_addr/union inet_addr/ and some adjustments for the fields.

The address family specific ops, ->cmp_addr(), ->is_any() etc., are removed, since we have generic helpers, they are unnecessary.

Cc Daniel Borkmann <[email protected]>
Cc Vlad Yasevich <[email protected]>
Cc Neil Horman <[email protected]>
---
 include/net/sctp/sctp.h    |   22 ++--
 include/net/sctp/sm.h      |    4 +-
 include/net/sctp/structs.h |  132 +++++++++++-------------
 net/sctp/associola.c       |   26 +++---
 net/sctp/bind_addr.c       |   61 ++++--------
 net/sctp/endpointola.c     |   12 +-
 net/sctp/input.c           |   56 +++++-----
 net/sctp/ipv6.c            |  240 +++++++++++++++++++-------------------------
 net/sctp/outqueue.c        |    4 +-
 net/sctp/proc.c            |   10 +-
 net/sctp/protocol.c        |  198 ++++++++++++++----------------------
 net/sctp/sm_make_chunk.c   |   54 +++++-----
 net/sctp/sm_statefuns.c    |   23 ++---
 net/sctp/socket.c          |  126 +++++++++++++-----------
 net/sctp/transport.c       |   12 +-
 net/sctp/ulpevent.c        |    2 +-
 16 files changed, 437 insertions(+), 545 deletions(-)
include/net/sctp/sctp.h +11 -11
index 3794c5a..0472336 100644
@@ -584,22 +584,22 @@ static inline int __sctp_sstate(const struct sock *sk, sctp_sock_state_t state)
 }
 
 /* Map v4-mapped v6 address back to v4 address */
-static inline void sctp_v6_map_v4(union sctp_addr *addr)
+static inline void sctp_v6_map_v4(union inet_addr *addr)
 {
-	addr->v4.sin_family = AF_INET;
-	addr->v4.sin_port = addr->v6.sin6_port;
-	addr->v4.sin_addr.s_addr = addr->v6.sin6_addr.s6_addr32[3];
+	addr->sin.sin_family = AF_INET;
+	addr->sin.sin_port = addr->sin6.sin6_port;
+	addr->sin.sin_addr.s_addr = addr->sin6.sin6_addr.s6_addr32[3];
 }
 
 /* Map v4 address to v4-mapped v6 address */
-static inline void sctp_v4_map_v6(union sctp_addr *addr)
+static inline void sctp_v4_map_v6(union inet_addr *addr)
 {
-	addr->v6.sin6_family = AF_INET6;
-	addr->v6.sin6_port = addr->v4.sin_port;
-	addr->v6.sin6_addr.s6_addr32[3] = addr->v4.sin_addr.s_addr;
-	addr->v6.sin6_addr.s6_addr32[0] = 0;
-	addr->v6.sin6_addr.s6_addr32[1] = 0;
-	addr->v6.sin6_addr.s6_addr32[2] = htonl(0x0000ffff);
+	addr->sin6.sin6_family = AF_INET6;
+	addr->sin6.sin6_port = addr->sin.sin_port;
+	addr->sin6.sin6_addr.s6_addr32[3] = addr->sin.sin_addr.s_addr;
+	addr->sin6.sin6_addr.s6_addr32[0] = 0;
+	addr->sin6.sin6_addr.s6_addr32[1] = 0;
+	addr->sin6.sin6_addr.s6_addr32[2] = htonl(0x0000ffff);
 }
 
 /* The cookie is always 0 since this is how it's used in the
include/net/sctp/sm.h +2 -2
index 4ef75af..63ed797 100644
@@ -244,11 +244,11 @@ struct sctp_chunk *sctp_make_op_error(const struct sctp_association *,
 				 size_t reserve_tail);
 
 struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *,
-					      union sctp_addr *,
+					      union inet_addr *,
 					      struct sockaddr *,
 					      int, __be16);
 struct sctp_chunk *sctp_make_asconf_set_prim(struct sctp_association *asoc,
-					     union sctp_addr *addr);
+					     union inet_addr *addr);
 int sctp_verify_asconf(const struct sctp_association *asoc,
 		       struct sctp_paramhdr *param_hdr, void *chunk_end,
 		       struct sctp_paramhdr **errp);
include/net/sctp/structs.h +60 -72

296 lines not on this page · raw message

net/sctp/associola.c +13 -13
index a514612..ed0a9a7 100644
@@ -487,7 +487,7 @@ void sctp_assoc_set_primary(struct sctp_association *asoc,
 
 	/* Set a default msg_name for events. */
 	memcpy(&asoc->peer.primary_addr, &transport->ipaddr,
-	       sizeof(union sctp_addr));
+	       sizeof(union inet_addr));
 
 	/* If the primary path is changing, assume that the
 	 * user wants to use this new path.
@@ -617,7 +617,7 @@ void sctp_assoc_rm_peer(struct sctp_association *asoc,
 
 /* Add a transport address to an association.  */
 struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
-					   const union sctp_addr *addr,
+					   const union inet_addr *addr,
 					   const gfp_t gfp,
 					   const int peer_state)
 {
@@ -629,7 +629,7 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
 	sp = sctp_sk(asoc->base.sk);
 
 	/* AF_INET and AF_INET6 share common port field. */
-	port = ntohs(addr->v4.sin_port);
+	port = ntohs(addr->sin.sin_port);
 
 	pr_debug("%s: association:%p addr:%pIApc state:%d\n", __func__,
 		 asoc, &addr->sa, peer_state);
@@ -761,7 +761,7 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
 
 /* Delete a transport address from an association.  */
 void sctp_assoc_del_peer(struct sctp_association *asoc,
-			 const union sctp_addr *addr)
+			 const union inet_addr *addr)
 {
 	struct list_head	*pos;
 	struct list_head	*temp;
@@ -780,7 +780,7 @@ void sctp_assoc_del_peer(struct sctp_association *asoc,
 /* Lookup a transport by address. */
 struct sctp_transport *sctp_assoc_lookup_paddr(
 					const struct sctp_association *asoc,
-					const union sctp_addr *address)
+					const union inet_addr *address)
 {
 	struct sctp_transport *t;
 
@@ -977,8 +977,8 @@ __u32 sctp_association_get_next_tsn(struct sctp_association *asoc)
 /* Compare two addresses to see if they match.  Wildcard addresses
  * only match themselves.
  */
-int sctp_cmp_addr_exact(const union sctp_addr *ss1,
-			const union sctp_addr *ss2)
+int sctp_cmp_addr_exact(const union inet_addr *ss1,
+			const union inet_addr *ss2)
 {
 	struct sctp_af *af;
 
@@ -1069,13 +1069,13 @@ out:
 /* Is this the association we are looking for? */
 struct sctp_transport *sctp_assoc_is_match(struct sctp_association *asoc,
 					   struct net *net,
-					   const union sctp_addr *laddr,
-					   const union sctp_addr *paddr)
+					   const union inet_addr *laddr,
+					   const union inet_addr *paddr)
 {
 	struct sctp_transport *transport;
 
-	if ((htons(asoc->base.bind_addr.port) == laddr->v4.sin_port) &&
-	    (htons(asoc->peer.port) == paddr->v4.sin_port) &&
+	if ((htons(asoc->base.bind_addr.port) == laddr->sin.sin_port) &&
+	    (htons(asoc->peer.port) == paddr->sin.sin_port) &&
 	    net_eq(sock_net(asoc->base.sk), net)) {
 		transport = sctp_assoc_lookup_paddr(asoc, paddr);
 		if (!transport)
@@ -1551,11 +1551,11 @@ int sctp_assoc_set_bind_addr_from_cookie(struct sctp_association *asoc,
 
 /* Lookup laddr in the bind address list of an association. */
 int sctp_assoc_lookup_laddr(struct sctp_association *asoc,
-			    const union sctp_addr *laddr)
+			    const union inet_addr *laddr)
 {
 	int found = 0;
 
-	if ((asoc->base.bind_addr.port == ntohs(laddr->v4.sin_port)) &&
+	if ((asoc->base.bind_addr.port == ntohs(laddr->sin.sin_port)) &&
 	    sctp_bind_addr_match(&asoc->base.bind_addr, laddr,
 				 sctp_sk(asoc->base.sk)))
 		found = 1;
net/sctp/bind_addr.c +21 -40

167 lines not on this page · raw message

net/sctp/endpointola.c +6 -6
index 09b8daa..3b19e06 100644
@@ -299,11 +299,11 @@ void sctp_endpoint_put(struct sctp_endpoint *ep)
 /* Is this the endpoint we are looking for?  */
 struct sctp_endpoint *sctp_endpoint_is_match(struct sctp_endpoint *ep,
 					       struct net *net,
-					       const union sctp_addr *laddr)
+					       const union inet_addr *laddr)
 {
 	struct sctp_endpoint *retval = NULL;
 
-	if ((htons(ep->base.bind_addr.port) == laddr->v4.sin_port) &&
+	if ((htons(ep->base.bind_addr.port) == laddr->sin.sin_port) &&
 	    net_eq(sock_net(ep->base.sk), net)) {
 		if (sctp_bind_addr_match(&ep->base.bind_addr, laddr,
 					 sctp_sk(ep->base.sk)))
@@ -319,7 +319,7 @@ struct sctp_endpoint *sctp_endpoint_is_match(struct sctp_endpoint *ep,
  */
 static struct sctp_association *__sctp_endpoint_lookup_assoc(
 	const struct sctp_endpoint *ep,
-	const union sctp_addr *paddr,
+	const union inet_addr *paddr,
 	struct sctp_transport **transport)
 {
 	struct sctp_association *asoc = NULL;
@@ -338,7 +338,7 @@ static struct sctp_association *__sctp_endpoint_lookup_assoc(
 	if (!ep->base.bind_addr.port)
 		goto out;
 
-	rport = ntohs(paddr->v4.sin_port);
+	rport = ntohs(paddr->sin.sin_port);
 
 	hash = sctp_assoc_hashfn(sock_net(ep->base.sk), ep->base.bind_addr.port,
 				 rport);
@@ -364,7 +364,7 @@ out:
 /* Lookup association on an endpoint based on a peer address.  BH-safe.  */
 struct sctp_association *sctp_endpoint_lookup_assoc(
 	const struct sctp_endpoint *ep,
-	const union sctp_addr *paddr,
+	const union inet_addr *paddr,
 	struct sctp_transport **transport)
 {
 	struct sctp_association *asoc;
@@ -380,7 +380,7 @@ struct sctp_association *sctp_endpoint_lookup_assoc(
  * given peer address.
  */
 int sctp_endpoint_is_peeled_off(struct sctp_endpoint *ep,
-				const union sctp_addr *paddr)
+				const union inet_addr *paddr)
 {
 	struct sctp_sockaddr_entry *addr;
 	struct sctp_bind_addr *bp;
net/sctp/input.c +28 -28

152 lines not on this page · raw message

net/sctp/ipv6.c +104 -136

521 lines not on this page · raw message

net/sctp/outqueue.c +2 -2
index 94df758..57583a2 100644
@@ -57,7 +57,7 @@ static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn);
 static void sctp_check_transmitted(struct sctp_outq *q,
 				   struct list_head *transmitted_queue,
 				   struct sctp_transport *transport,
-				   union sctp_addr *saddr,
+				   union inet_addr *saddr,
 				   struct sctp_sackhdr *sack,
 				   __u32 *highest_new_tsn);
 
@@ -1315,7 +1315,7 @@ int sctp_outq_is_empty(const struct sctp_outq *q)
 static void sctp_check_transmitted(struct sctp_outq *q,
 				   struct list_head *transmitted_queue,
 				   struct sctp_transport *transport,
-				   union sctp_addr *saddr,
+				   union inet_addr *saddr,
 				   struct sctp_sackhdr *sack,
 				   __u32 *highest_new_tsn_in_sack)
 {
net/sctp/proc.c +5 -5
index 0c06421..e216ee0 100644
@@ -124,7 +124,7 @@ static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_commo
 	struct sctp_association *asoc;
 	struct sctp_sockaddr_entry *laddr;
 	struct sctp_transport *peer;
-	union sctp_addr *addr, *primary = NULL;
+	union inet_addr *addr, *primary = NULL;
 	struct sctp_af *af;
 
 	if (epb->type == SCTP_EP_TYPE_ASSOCIATION) {
@@ -149,7 +149,7 @@ static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_commo
 		if (primary && af->cmp_addr(addr, primary)) {
 			seq_printf(seq, "*");
 		}
-		af->seq_dump_addr(seq, addr);
+		seq_printf(seq, "%pIA ", &addr);
 	}
 	rcu_read_unlock();
 }
@@ -158,7 +158,7 @@ static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_commo
 static void sctp_seq_dump_remote_addrs(struct seq_file *seq, struct sctp_association *assoc)
 {
 	struct sctp_transport *transport;
-	union sctp_addr *addr, *primary;
+	union inet_addr *addr, *primary;
 	struct sctp_af *af;
 
 	primary = &assoc->peer.primary_addr;
@@ -173,7 +173,7 @@ static void sctp_seq_dump_remote_addrs(struct seq_file *seq, struct sctp_associa
 		if (af->cmp_addr(addr, primary)) {
 			seq_printf(seq, "*");
 		}
-		af->seq_dump_addr(seq, addr);
+		seq_printf(seq, "%pIA ", addr);
 	}
 	rcu_read_unlock();
 }
@@ -462,7 +462,7 @@ static int sctp_remaddr_seq_show(struct seq_file *seq, void *v)
 			/*
 			 * The remote address (ADDR)
 			 */
-			tsp->af_specific->seq_dump_addr(seq, &tsp->ipaddr);
+			seq_printf(seq, "%pIA ", &tsp->ipaddr);
 			seq_printf(seq, " ");
 
 			/*
net/sctp/protocol.c +76 -122

412 lines not on this page · raw message

net/sctp/sm_make_chunk.c +27 -27

187 lines not on this page · raw message

net/sctp/sm_statefuns.c +7 -16
index dfe3f36..ee975a3 100644
@@ -1124,7 +1124,7 @@ sctp_disposition_t sctp_sf_backbeat_8_3(struct net *net,
 					sctp_cmd_seq_t *commands)
 {
 	struct sctp_chunk *chunk = arg;
-	union sctp_addr from_addr;
+	union inet_addr from_addr;
 	struct sctp_transport *link;
 	sctp_sender_hb_info_t *hbinfo;
 	unsigned long max_interval;
@@ -1150,17 +1150,8 @@ sctp_disposition_t sctp_sf_backbeat_8_3(struct net *net,
 
 	/* This should never happen, but lets log it if so.  */
 	if (unlikely(!link)) {
-		if (from_addr.sa.sa_family == AF_INET6) {
-			net_warn_ratelimited("%s association %p could not find address %pI6\n",
-					     __func__,
-					     asoc,
-					     &from_addr.v6.sin6_addr);
-		} else {
-			net_warn_ratelimited("%s association %p could not find address %pI4\n",
-					     __func__,
-					     asoc,
-					     &from_addr.v4.sin_addr.s_addr);
-		}
+		net_warn_ratelimited("%s association %p could not find address %pIA\n",
+				     __func__, asoc, &from_addr);
 		return SCTP_DISPOSITION_DISCARD;
 	}
 
@@ -1193,7 +1184,7 @@ sctp_disposition_t sctp_sf_backbeat_8_3(struct net *net,
 /* Helper function to send out an abort for the restart
  * condition.
  */
-static int sctp_sf_send_restart_abort(struct net *net, union sctp_addr *ssa,
+static int sctp_sf_send_restart_abort(struct net *net, union inet_addr *ssa,
 				      struct sctp_chunk *init,
 				      sctp_cmd_seq_t *commands)
 {
@@ -1203,7 +1194,7 @@ static int sctp_sf_send_restart_abort(struct net *net, union sctp_addr *ssa,
 	struct sctp_errhdr *errhdr;
 	struct sctp_endpoint *ep;
 	char buffer[sizeof(struct sctp_errhdr)+sizeof(union sctp_addr_param)];
-	struct sctp_af *af = sctp_get_af_specific(ssa->v4.sin_family);
+	struct sctp_af *af = sctp_get_af_specific(ssa->sin.sin_family);
 
 	/* Build the error on the stack.   We are way to malloc crazy
 	 * throughout the code today.
@@ -1243,7 +1234,7 @@ out:
 }
 
 static bool list_has_sctp_addr(const struct list_head *list,
-			       union sctp_addr *ipaddr)
+			       union inet_addr *ipaddr)
 {
 	struct sctp_transport *addr;
 
@@ -6041,7 +6032,7 @@ static struct sctp_packet *sctp_ootb_pkt_new(struct net *net,
 	/* Cache a route for the transport with the chunk's destination as
 	 * the source address.
 	 */
-	sctp_transport_route(transport, (union sctp_addr *)&chunk->dest,
+	sctp_transport_route(transport, (union inet_addr *)&chunk->dest,
 			     sctp_sk(net->sctp.ctl_sock));
 
 	packet = sctp_packet_init(&transport->packet, transport, sport, dport);
net/sctp/socket.c +68 -58

437 lines not on this page · raw message

net/sctp/transport.c +6 -6
index e332efb..aeaec64 100644
@@ -9,7 +9,7 @@
  *
  * This module provides the abstraction for an SCTP tranport representing
  * a remote transport address.  For local transport addresses, we just use
- * union sctp_addr.
+ * union inet_addr.
  *
  * This SCTP implementation is free software;
  * you can redistribute it and/or modify it under the terms of
@@ -55,13 +55,13 @@
 /* Initialize a new transport from provided memory.  */
 static struct sctp_transport *sctp_transport_init(struct net *net,
 						  struct sctp_transport *peer,
-						  const union sctp_addr *addr,
+						  const union inet_addr *addr,
 						  gfp_t gfp)
 {
 	/* Copy in the address.  */
 	peer->ipaddr = *addr;
 	peer->af_specific = sctp_get_af_specific(addr->sa.sa_family);
-	memset(&peer->saddr, 0, sizeof(union sctp_addr));
+	memset(&peer->saddr, 0, sizeof(union inet_addr));
 
 	peer->sack_generation = 0;
 
@@ -105,7 +105,7 @@ static struct sctp_transport *sctp_transport_init(struct net *net,
 
 /* Allocate and initialize a new transport.  */
 struct sctp_transport *sctp_transport_new(struct net *net,
-					  const union sctp_addr *addr,
+					  const union inet_addr *addr,
 					  gfp_t gfp)
 {
 	struct sctp_transport *transport;
@@ -267,7 +267,7 @@ void sctp_transport_update_pmtu(struct sock *sk, struct sctp_transport *t, u32 p
  * address.
  */
 void sctp_transport_route(struct sctp_transport *transport,
-			  union sctp_addr *saddr, struct sctp_sock *opt)
+			  union inet_addr *saddr, struct sctp_sock *opt)
 {
 	struct sctp_association *asoc = transport->asoc;
 	struct sctp_af *af = transport->af_specific;
@@ -275,7 +275,7 @@ void sctp_transport_route(struct sctp_transport *transport,
 	af->get_dst(transport, saddr, &transport->fl, sctp_opt2sk(opt));
 
 	if (saddr)
-		memcpy(&transport->saddr, saddr, sizeof(union sctp_addr));
+		memcpy(&transport->saddr, saddr, sizeof(union inet_addr));
 	else
 		af->get_saddr(opt, transport, &transport->fl);
 
net/sctp/ulpevent.c +1 -1
index 81089ed..d81b983 100644
@@ -344,7 +344,7 @@ struct sctp_ulpevent *sctp_ulpevent_make_peer_addr_change(
 	/* Map ipv4 address into v4-mapped-on-v6 address.  */
 	sctp_get_pf_specific(asoc->base.sk->sk_family)->addr_v4map(
 					sctp_sk(asoc->base.sk),
-					(union sctp_addr *)&spc->spc_aaddr);
+					(union inet_addr *)&spc->spc_aaddr);
 
 	return event;
 
Signature · 1 line
1.7.7.6
#10 lore raw

Re: [Patch net-next v3 8/9] sctp: use generic union inet_addr

Quoted 6 lines · Cong Wang

From: Cong Wang <[email protected]>

sctp has its own union sctp_addr which is nearly same with the generic union inet_addr, so just convert it to the generic one.

Quoted 6 lines

Sorry for the big patch, it is not easy to split it. Most of the patch simply does s/union sctp_addr/union inet_addr/ and some adjustments for the fields.

The address family specific ops, ->cmp_addr(), ->is_any() etc., are removed, since we have generic helpers, they are unnecessary.

You are not actually removing cmp_addr(), so that's invalid. For the usage of ->is_any, see below.

Quoted 5 lines
include/net/sctp/structs.h +0 -0
index 422db6c..8dfaa39 100644

include/net/sctp/structs.h union sctp_params sctp_bind_addrs_to_raw(const struct sctp_bind_addr *bp, · line 1110

Quoted 10 lines
include/net/sctp/structs.h +3 -4
@@ -1117,10 +1105,10 @@ union sctp_params sctp_bind_addrs_to_raw(const struct sctp_bind_addr *bp,
  int sctp_raw_to_bind_addrs(struct sctp_bind_addr *bp, __u8 *raw, int len,
  			   __u16 port, gfp_t gfp);
 
-sctp_scope_t sctp_scope(const union sctp_addr *);
-int sctp_in_scope(struct net *net, const union sctp_addr *addr, const sctp_scope_t scope);
-int sctp_is_any(struct sock *sk, const union sctp_addr *addr);
-int sctp_addr_is_valid(const union sctp_addr *addr);
+sctp_scope_t sctp_scope(const union inet_addr *);
+int sctp_in_scope(struct net *net, const union inet_addr *addr, const sctp_scope_t scope);
+int sctp_is_any(struct sock *sk, const union inet_addr *addr);

You are keeping the prototype and remove the implementation of sctp_is_any later, but that's ok since I don't think the implementation should be removed. However, this points out that this should probably be a separate patch (first do straight conversion to new data structure, then fix up usage and delete unneeded functions).

Quoted 38 lines
include/net/sctp/structs.h +1 -0
+int sctp_addr_is_valid(const union inet_addr *addr);
  int sctp_is_ep_boundall(struct sock *sk);
 
 
net/sctp/bind_addr.c +2 -11
index 077bb07..03d8f85 100644
@@ -47,7 +47,7 @@
@@ -436,13 +436,13 @@ union sctp_addr *sctp_find_unmatch_addr(struct sctp_bind_addr	*bp,
 
  /* Copy out addresses from the global local address list. */
  static int sctp_copy_one_addr(struct net *net, struct sctp_bind_addr *dest,
-			      union sctp_addr *addr,
+			      union inet_addr *addr,
  			      sctp_scope_t scope, gfp_t gfp,
  			      int flags)
  {
  	int error = 0;
 
-	if (sctp_is_any(NULL, addr)) {
+	if (inet_addr_any(addr)) {
  		error = sctp_copy_local_addr_list(net, dest, scope, gfp, flags);
  	} else if (sctp_in_scope(net, addr, scope)) {
  		/* Now that the address is in scope, check to see if
@@ -461,27 +461,8 @@ static int sctp_copy_one_addr(struct net *net, struct sctp_bind_addr *dest,
  	return error;
  }
 
-/* Is this a wildcard address?  */
-int sctp_is_any(struct sock *sk, const union sctp_addr *addr)
-{
-	unsigned short fam = 0;
-	struct sctp_af *af;
-
-	/* Try to get the right address family */
-	if (addr->sa.sa_family != AF_UNSPEC)
-		fam = addr->sa.sa_family;

net/sctp/bind_addr.c static int sctp_copy_one_addr(struct net *net, struct sctp_bind_addr *dest, · line 482

Quoted 10 lines
net/sctp/bind_addr.c +0 -10
-	else if (sk)
-		fam = sk->sk_family;
-
-	af = sctp_get_af_specific(fam);
-	if (!af)
-		return 0;
-
-	return af->is_any(addr);
-}
-

I don't think you can remove this implentation. It is would introduce a lot of regressions for code that does:

	struct sockaddr_in sin;
	memset(&sin, 0, sizeof(sin));

	/* Do some setsockopt... with sin */

While I do agree that this is a bit sloppy (and I've made that argument to all the bug submitters), this type of bug has been reported for a long time and sctp_is_any() was finally changed to fix it once and for all. You are un-fixing it...

Quoted 71 lines
net/sctp/bind_addr.c +2 -2
  /* Is 'addr' valid for 'scope'?  */
-int sctp_in_scope(struct net *net, const union sctp_addr *addr, sctp_scope_t scope)
+int sctp_in_scope(struct net *net, const union inet_addr *addr, sctp_scope_t scope)
  {
  	sctp_scope_t addr_scope = sctp_scope(addr);
 
@@ -530,7 +511,7 @@ int sctp_is_ep_boundall(struct sock *sk)
  	if (sctp_list_single_entry(&bp->address_list)) {
  		addr = list_entry(bp->address_list.next,
  				  struct sctp_sockaddr_entry, list);
-		if (sctp_is_any(sk, &addr->a))
+		if (inet_addr_any(&addr->a))
  			return 1;
  	}
  	return 0;
net/sctp/ipv6.c +10 -25
index da613ce..2e1262b 100644
 
  /* Compare addresses exactly.
   * v4-mapped-v6 is also in consideration.
   */
-static int sctp_v6_cmp_addr(const union sctp_addr *addr1,
-			    const union sctp_addr *addr2)
+static bool sctp_v6_cmp_addr(const union inet_addr *addr1,
+			     const union inet_addr *addr2)
  {
  	if (addr1->sa.sa_family != addr2->sa.sa_family) {
  		if (addr1->sa.sa_family = AF_INET &&
  		    addr2->sa.sa_family = AF_INET6 &&
-		    ipv6_addr_v4mapped(&addr2->v6.sin6_addr)) {
-			if (addr2->v6.sin6_port = addr1->v4.sin_port &&
-			    addr2->v6.sin6_addr.s6_addr32[3] =
-			    addr1->v4.sin_addr.s_addr)
+		    ipv6_addr_v4mapped(&addr2->sin6.sin6_addr)) {
+			if (addr2->sin6.sin6_port = addr1->sin.sin_port &&
+			    addr2->sin6.sin6_addr.s6_addr32[3] =
+			    addr1->sin.sin_addr.s_addr)
  				return 1;
  		}
  		if (addr2->sa.sa_family = AF_INET &&
  		    addr1->sa.sa_family = AF_INET6 &&
-		    ipv6_addr_v4mapped(&addr1->v6.sin6_addr)) {
-			if (addr1->v6.sin6_port = addr2->v4.sin_port &&
-			    addr1->v6.sin6_addr.s6_addr32[3] =
-			    addr2->v4.sin_addr.s_addr)
+		    ipv6_addr_v4mapped(&addr1->sin6.sin6_addr)) {
+			if (addr1->sin6.sin6_port = addr2->sin.sin_port &&
+			    addr1->sin6.sin6_addr.s6_addr32[3] =
+			    addr2->sin.sin_addr.s_addr)
  				return 1;
  		}
  		return 0;
  	}
-	if (!ipv6_addr_equal(&addr1->v6.sin6_addr, &addr2->v6.sin6_addr))
-		return 0;
-	/* If this is a linklocal address, compare the scope_id. */
-	if (ipv6_addr_type(&addr1->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL) {
-		if (addr1->v6.sin6_scope_id && addr2->v6.sin6_scope_id &&
-		    (addr1->v6.sin6_scope_id != addr2->v6.sin6_scope_id)) {
-			return 0;
-		}
-	}
-
-	return 1;
-}
 
-/* Initialize addr struct to INADDR_ANY. */
-static void sctp_v6_inaddr_any(union sctp_addr *addr, __be16 port)
-{

net/sctp/ipv6.c static void sctp_v6_copy_addrlist(struct list_head *addrlist, · line 537

Quoted 10 lines
net/sctp/ipv6.c +1 -9
-	memset(addr, 0x00, sizeof(union sctp_addr));
-	addr->v6.sin6_family = AF_INET6;
-	addr->v6.sin6_port = port;
-}
-
-/* Is this a wildcard address? */
-static int sctp_v6_is_any(const union sctp_addr *addr)
-{
-	return ipv6_addr_any(&addr->v6.sin6_addr);
+	return inet_addr_equal(addr1, addr2);

You've dropped the scope_id comparision which inet_addr_equal does not
seem to do. As far as I can see from this series, inet_addr_equal()
just calls ipv6_addr_equal.

-vlad

author
#11 lore raw

PATCH v3 9/9 selinux: use generic union inet_addr

In reply to Cong Wang

From: Cong Wang <[email protected]>

selinux has some similar definition like union inet_addr, it can re-use the generic union inet_addr too.

---
 include/linux/lsm_audit.h          |   19 +-----
 security/lsm_audit.c               |   58 ++++++++--------
 security/selinux/hooks.c           |  130 +++++++++++++++++-------------------
 security/selinux/include/netnode.h |    4 +-
 security/selinux/include/objsec.h  |    7 +--
 security/selinux/netnode.c         |  102 ++++++++--------------------
 security/smack/smack_lsm.c         |   19 +++---
 7 files changed, 138 insertions(+), 201 deletions(-)
include/linux/lsm_audit.h +3 -16
index 1cc89e9..48cab1e 100644
@@ -21,23 +21,13 @@
 #include <linux/path.h>
 #include <linux/key.h>
 #include <linux/skbuff.h>
+#include <net/inet_addr.h>
 
 struct lsm_network_audit {
 	int netif;
 	struct sock *sk;
-	u16 family;
-	__be16 dport;
-	__be16 sport;
-	union {
-		struct {
-			__be32 daddr;
-			__be32 saddr;
-		} v4;
-		struct {
-			struct in6_addr daddr;
-			struct in6_addr saddr;
-		} v6;
-	} fam;
+	union inet_addr saddr;
+	union inet_addr daddr;
 };
 
 /* Auxiliary data to use in generating the audit record. */
@@ -83,9 +73,6 @@ struct common_audit_data {
 	}; /* per LSM data pointer union */
 };
 
-#define v4info fam.v4
-#define v6info fam.v6
-
 int ipv4_skb_to_auditdata(struct sk_buff *skb,
 		struct common_audit_data *ad, u8 *proto);
 
security/lsm_audit.c +29 -29

130 lines not on this page · raw message

security/selinux/hooks.c +61 -69

345 lines not on this page · raw message

security/selinux/include/netnode.h +3 -1
index df7a5ed..f32c909 100644
@@ -27,6 +27,8 @@
 #ifndef _SELINUX_NETNODE_H
 #define _SELINUX_NETNODE_H
 
-int sel_netnode_sid(void *addr, u16 family, u32 *sid);
+#include <net/inet_addr.h>
+
+int sel_netnode_sid(union inet_addr *addr, u32 *sid);
 
 #endif
security/selinux/include/objsec.h +2 -5
index aa47bca..a46caaf 100644
@@ -24,6 +24,7 @@
 #include <linux/binfmts.h>
 #include <linux/in.h>
 #include <linux/spinlock.h>
+#include <net/inet_addr.h>
 #include "flask.h"
 #include "avc.h"
 
@@ -80,12 +81,8 @@ struct netif_security_struct {
 };
 
 struct netnode_security_struct {
-	union {
-		__be32 ipv4;		/* IPv4 node address */
-		struct in6_addr ipv6;	/* IPv6 node address */
-	} addr;
+	union inet_addr addr;
 	u32 sid;			/* SID for this node */
-	u16 family;			/* address family */
 };
 
 struct netport_security_struct {
security/selinux/netnode.c +30 -72

198 lines not on this page · raw message

security/smack/smack_lsm.c +10 -9
index eefbd10..9a80923 100644
@@ -1900,9 +1900,7 @@ static int smack_netlabel_send(struct sock *sk, struct sockaddr_in *sap)
 		struct lsm_network_audit net;
 
 		smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
-		ad.a.u.net->family = sap->sin_family;
-		ad.a.u.net->dport = sap->sin_port;
-		ad.a.u.net->v4info.daddr = sap->sin_addr.s_addr;
+		ad.a.u.net->daddr = (union inet_addr )*sap;
 #endif
 		sk_lbl = SMACK_UNLABELED_SOCKET;
 		skp = ssp->smk_out;
@@ -2055,12 +2053,13 @@ auditout:
 
 #ifdef CONFIG_AUDIT
 	smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
-	ad.a.u.net->family = sk->sk_family;
-	ad.a.u.net->dport = port;
+	inet_addr_set_port(&ad.a.u.net->daddr, port);
+	ad.a.u.net->saddr.sa.sa_family = sk->sk_family;
+	ad.a.u.net->daddr.sa.sa_family = sk->sk_family;
 	if (act == SMK_RECEIVING)
-		ad.a.u.net->v6info.saddr = address->sin6_addr;
+		ad.a.u.net->saddr.sin6.sin6_addr = address->sin6_addr;
 	else
-		ad.a.u.net->v6info.daddr = address->sin6_addr;
+		ad.a.u.net->daddr.sin6.sin6_addr = address->sin6_addr;
 #endif
 	return smk_access(skp, object, MAY_WRITE, &ad);
 }
@@ -3202,7 +3201,8 @@ static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
 
 #ifdef CONFIG_AUDIT
 		smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
-		ad.a.u.net->family = sk->sk_family;
+		ad.a.u.net->saddr.sa.sa_family = sk->sk_family;
+		ad.a.u.net->daddr.sa.sa_family = sk->sk_family;
 		ad.a.u.net->netif = skb->skb_iif;
 		ipv4_skb_to_auditdata(skb, &ad.a, NULL);
 #endif
@@ -3384,7 +3384,8 @@ static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb,
 
 #ifdef CONFIG_AUDIT
 	smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
-	ad.a.u.net->family = family;
+	ad.a.u.net->saddr.sa.sa_family = family;
+	ad.a.u.net->daddr.sa.sa_family = family;
 	ad.a.u.net->netif = skb->skb_iif;
 	ipv4_skb_to_auditdata(skb, &ad.a, NULL);
 #endif
Signature · 1 line
1.7.7.6
maintainer
#12 lore raw

Re: [Patch net-next v3 9/9] selinux: use generic union inet_addr

Quoted 4 lines · Cong Wang

From: Cong Wang <[email protected]>

selinux has some similar definition like union inet_addr, it can re-use the generic union inet_addr too.

I'm trying to understand what value this change adds. All it appears to do is swap one set of inconvenient structure members for a different set of inconvenient structure members. Does it improve performance?

Quoted 885 lines
---
 include/linux/lsm_audit.h          |   19 +-----
 security/lsm_audit.c               |   58 ++++++++--------
 security/selinux/hooks.c           |  130 +++++++++++++++++-------------------
 security/selinux/include/netnode.h |    4 +-
 security/selinux/include/objsec.h  |    7 +--
 security/selinux/netnode.c         |  102 ++++++++--------------------
 security/smack/smack_lsm.c         |   19 +++---
 7 files changed, 138 insertions(+), 201 deletions(-)
include/linux/lsm_audit.h +3 -16
index 1cc89e9..48cab1e 100644
@@ -21,23 +21,13 @@
 #include <linux/path.h>
 #include <linux/key.h>
 #include <linux/skbuff.h>
+#include <net/inet_addr.h>
 
 struct lsm_network_audit {
 	int netif;
 	struct sock *sk;
-	u16 family;
-	__be16 dport;
-	__be16 sport;
-	union {
-		struct {
-			__be32 daddr;
-			__be32 saddr;
-		} v4;
-		struct {
-			struct in6_addr daddr;
-			struct in6_addr saddr;
-		} v6;
-	} fam;
+	union inet_addr saddr;
+	union inet_addr daddr;
 };
 
 /* Auxiliary data to use in generating the audit record. */
@@ -83,9 +73,6 @@ struct common_audit_data {
 	}; /* per LSM data pointer union */
 };
 
-#define v4info fam.v4
-#define v6info fam.v6
-
 int ipv4_skb_to_auditdata(struct sk_buff *skb,
 		struct common_audit_data *ad, u8 *proto);
 
security/lsm_audit.c +29 -29
index 8d8d97d..244c2a1 100644
@@ -49,8 +49,8 @@ int ipv4_skb_to_auditdata(struct sk_buff *skb,
 	if (ih == NULL)
 		return -EINVAL;
 
-	ad->u.net->v4info.saddr = ih->saddr;
-	ad->u.net->v4info.daddr = ih->daddr;
+	ad->u.net->saddr.sin.sin_addr.s_addr = ih->saddr;
+	ad->u.net->daddr.sin.sin_addr.s_addr = ih->daddr;
 
 	if (proto)
 		*proto = ih->protocol;
@@ -64,8 +64,8 @@ int ipv4_skb_to_auditdata(struct sk_buff *skb,
 		if (th == NULL)
 			break;
 
-		ad->u.net->sport = th->source;
-		ad->u.net->dport = th->dest;
+		inet_addr_set_port(&ad->u.net->saddr, ntohs(th->source));
+		inet_addr_set_port(&ad->u.net->daddr, ntohs(th->dest));
 		break;
 	}
 	case IPPROTO_UDP: {
@@ -73,8 +73,8 @@ int ipv4_skb_to_auditdata(struct sk_buff *skb,
 		if (uh == NULL)
 			break;
 
-		ad->u.net->sport = uh->source;
-		ad->u.net->dport = uh->dest;
+		inet_addr_set_port(&ad->u.net->saddr, ntohs(uh->source));
+		inet_addr_set_port(&ad->u.net->daddr, ntohs(uh->dest));
 		break;
 	}
 	case IPPROTO_DCCP: {
@@ -82,16 +82,16 @@ int ipv4_skb_to_auditdata(struct sk_buff *skb,
 		if (dh == NULL)
 			break;
 
-		ad->u.net->sport = dh->dccph_sport;
-		ad->u.net->dport = dh->dccph_dport;
+		inet_addr_set_port(&ad->u.net->saddr, ntohs(dh->dccph_sport));
+		inet_addr_set_port(&ad->u.net->daddr, ntohs(dh->dccph_dport));
 		break;
 	}
 	case IPPROTO_SCTP: {
 		struct sctphdr *sh = sctp_hdr(skb);
 		if (sh == NULL)
 			break;
-		ad->u.net->sport = sh->source;
-		ad->u.net->dport = sh->dest;
+		inet_addr_set_port(&ad->u.net->saddr, ntohs(sh->source));
+		inet_addr_set_port(&ad->u.net->daddr, ntohs(sh->dest));
 		break;
 	}
 	default:
@@ -119,8 +119,8 @@ int ipv6_skb_to_auditdata(struct sk_buff *skb,
 	ip6 = ipv6_hdr(skb);
 	if (ip6 == NULL)
 		return -EINVAL;
-	ad->u.net->v6info.saddr = ip6->saddr;
-	ad->u.net->v6info.daddr = ip6->daddr;
+	ad->u.net->saddr.sin6.sin6_addr = ip6->saddr;
+	ad->u.net->daddr.sin6.sin6_addr = ip6->daddr;
 	ret = 0;
 	/* IPv6 can have several extension header before the Transport header
 	 * skip them */
@@ -140,8 +140,8 @@ int ipv6_skb_to_auditdata(struct sk_buff *skb,
 		if (th == NULL)
 			break;
 
-		ad->u.net->sport = th->source;
-		ad->u.net->dport = th->dest;
+		inet_addr_set_port(&ad->u.net->saddr, ntohs(th->source));
+		inet_addr_set_port(&ad->u.net->daddr, ntohs(th->dest));
 		break;
 	}
 	case IPPROTO_UDP: {
@@ -151,8 +151,8 @@ int ipv6_skb_to_auditdata(struct sk_buff *skb,
 		if (uh == NULL)
 			break;
 
-		ad->u.net->sport = uh->source;
-		ad->u.net->dport = uh->dest;
+		inet_addr_set_port(&ad->u.net->saddr, ntohs(uh->source));
+		inet_addr_set_port(&ad->u.net->daddr, ntohs(uh->dest));
 		break;
 	}
 	case IPPROTO_DCCP: {
@@ -162,8 +162,8 @@ int ipv6_skb_to_auditdata(struct sk_buff *skb,
 		if (dh == NULL)
 			break;
 
-		ad->u.net->sport = dh->dccph_sport;
-		ad->u.net->dport = dh->dccph_dport;
+		inet_addr_set_port(&ad->u.net->saddr, ntohs(dh->dccph_sport));
+		inet_addr_set_port(&ad->u.net->daddr, ntohs(dh->dccph_dport));
 		break;
 	}
 	case IPPROTO_SCTP: {
@@ -172,8 +172,8 @@ int ipv6_skb_to_auditdata(struct sk_buff *skb,
 		sh = skb_header_pointer(skb, offset, sizeof(_sctph), &_sctph);
 		if (sh == NULL)
 			break;
-		ad->u.net->sport = sh->source;
-		ad->u.net->dport = sh->dest;
+		inet_addr_set_port(&ad->u.net->saddr, ntohs(sh->source));
+		inet_addr_set_port(&ad->u.net->daddr, ntohs(sh->dest));
 		break;
 	}
 	default:
@@ -333,21 +333,21 @@ static void dump_common_audit_data(struct audit_buffer *ab,
 			}
 		}
 
-		switch (a->u.net->family) {
+		switch (a->u.net->saddr.sa.sa_family) {
 		case AF_INET:
-			print_ipv4_addr(ab, a->u.net->v4info.saddr,
-					a->u.net->sport,
+			print_ipv4_addr(ab, a->u.net->saddr.sin.sin_addr.s_addr,
+					a->u.net->saddr.sin.sin_port,
 					"saddr", "src");
-			print_ipv4_addr(ab, a->u.net->v4info.daddr,
-					a->u.net->dport,
+			print_ipv4_addr(ab, a->u.net->daddr.sin.sin_addr.s_addr,
+					a->u.net->daddr.sin.sin_port,
 					"daddr", "dest");
 			break;
 		case AF_INET6:
-			print_ipv6_addr(ab, &a->u.net->v6info.saddr,
-					a->u.net->sport,
+			print_ipv6_addr(ab, &a->u.net->saddr.sin6.sin6_addr,
+					a->u.net->saddr.sin.sin_port,
 					"saddr", "src");
-			print_ipv6_addr(ab, &a->u.net->v6info.daddr,
-					a->u.net->dport,
+			print_ipv6_addr(ab, &a->u.net->daddr.sin6.sin6_addr,
+					a->u.net->daddr.sin.sin_port,
 					"daddr", "dest");
 			break;
 		}
security/selinux/hooks.c +61 -69
index c956390..f9959c0 100644
@@ -3595,8 +3595,8 @@ static int selinux_parse_skb_ipv4(struct sk_buff *skb,
 	if (ihlen < sizeof(_iph))
 		goto out;
 
-	ad->u.net->v4info.saddr = ih->saddr;
-	ad->u.net->v4info.daddr = ih->daddr;
+	ad->u.net->saddr.sin.sin_addr.s_addr = ih->saddr;
+	ad->u.net->daddr.sin.sin_addr.s_addr = ih->daddr;
 	ret = 0;
 
 	if (proto)
@@ -3614,8 +3614,8 @@ static int selinux_parse_skb_ipv4(struct sk_buff *skb,
 		if (th == NULL)
 			break;
 
-		ad->u.net->sport = th->source;
-		ad->u.net->dport = th->dest;
+		inet_addr_set_port(&ad->u.net->saddr, ntohs(th->source));
+		inet_addr_set_port(&ad->u.net->daddr, ntohs(th->dest));
 		break;
 	}
 
@@ -3630,8 +3630,8 @@ static int selinux_parse_skb_ipv4(struct sk_buff *skb,
 		if (uh == NULL)
 			break;
 
-		ad->u.net->sport = uh->source;
-		ad->u.net->dport = uh->dest;
+		inet_addr_set_port(&ad->u.net->saddr, ntohs(uh->source));
+		inet_addr_set_port(&ad->u.net->daddr, ntohs(uh->dest));
 		break;
 	}
 
@@ -3646,8 +3646,8 @@ static int selinux_parse_skb_ipv4(struct sk_buff *skb,
 		if (dh == NULL)
 			break;
 
-		ad->u.net->sport = dh->dccph_sport;
-		ad->u.net->dport = dh->dccph_dport;
+		inet_addr_set_port(&ad->u.net->saddr, ntohs(dh->dccph_sport));
+		inet_addr_set_port(&ad->u.net->daddr, ntohs(dh->dccph_dport));
 		break;
 	}
 
@@ -3674,8 +3674,8 @@ static int selinux_parse_skb_ipv6(struct sk_buff *skb,
 	if (ip6 == NULL)
 		goto out;
 
-	ad->u.net->v6info.saddr = ip6->saddr;
-	ad->u.net->v6info.daddr = ip6->daddr;
+	ad->u.net->saddr.sin6.sin6_addr = ip6->saddr;
+	ad->u.net->daddr.sin6.sin6_addr = ip6->daddr;
 	ret = 0;
 
 	nexthdr = ip6->nexthdr;
@@ -3695,8 +3695,8 @@ static int selinux_parse_skb_ipv6(struct sk_buff *skb,
 		if (th == NULL)
 			break;
 
-		ad->u.net->sport = th->source;
-		ad->u.net->dport = th->dest;
+		inet_addr_set_port(&ad->u.net->saddr, ntohs(th->source));
+		inet_addr_set_port(&ad->u.net->daddr, ntohs(th->dest));
 		break;
 	}
 
@@ -3707,8 +3707,8 @@ static int selinux_parse_skb_ipv6(struct sk_buff *skb,
 		if (uh == NULL)
 			break;
 
-		ad->u.net->sport = uh->source;
-		ad->u.net->dport = uh->dest;
+		inet_addr_set_port(&ad->u.net->saddr, ntohs(uh->source));
+		inet_addr_set_port(&ad->u.net->daddr, ntohs(uh->dest));
 		break;
 	}
 
@@ -3719,8 +3719,8 @@ static int selinux_parse_skb_ipv6(struct sk_buff *skb,
 		if (dh == NULL)
 			break;
 
-		ad->u.net->sport = dh->dccph_sport;
-		ad->u.net->dport = dh->dccph_dport;
+		inet_addr_set_port(&ad->u.net->saddr, ntohs(dh->dccph_sport));
+		inet_addr_set_port(&ad->u.net->daddr, ntohs(dh->dccph_dport));
 		break;
 	}
 
@@ -3735,18 +3735,17 @@ out:
 #endif /* IPV6 */
 
 static int selinux_parse_skb(struct sk_buff *skb, struct common_audit_data *ad,
-			     char **_addrp, int src, u8 *proto)
+			     union inet_addr **_addrp, int src, u8 *proto)
 {
-	char *addrp;
+	union inet_addr *addrp;
 	int ret;
+	sa_family_t family = src ? ad->u.net->saddr.sa.sa_family : ad->u.net->daddr.sa.sa_family;
 
-	switch (ad->u.net->family) {
+	switch (family) {
 	case PF_INET:
 		ret = selinux_parse_skb_ipv4(skb, ad, proto);
 		if (ret)
 			goto parse_error;
-		addrp = (char *)(src ? &ad->u.net->v4info.saddr :
-				       &ad->u.net->v4info.daddr);
 		goto okay;
 
 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
@@ -3754,13 +3753,11 @@ static int selinux_parse_skb(struct sk_buff *skb, struct common_audit_data *ad,
 		ret = selinux_parse_skb_ipv6(skb, ad, proto);
 		if (ret)
 			goto parse_error;
-		addrp = (char *)(src ? &ad->u.net->v6info.saddr :
-				       &ad->u.net->v6info.daddr);
 		goto okay;
 #endif	/* IPV6 */
 	default:
 		addrp = NULL;
-		goto okay;
+		goto save;
 	}
 
 parse_error:
@@ -3770,6 +3767,8 @@ parse_error:
 	return ret;
 
 okay:
+	addrp = src ? &ad->u.net->saddr : &ad->u.net->daddr;
+save:
 	if (_addrp)
 		*_addrp = addrp;
 	return 0;
@@ -3912,25 +3911,15 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
 	 */
 	family = sk->sk_family;
 	if (family == PF_INET || family == PF_INET6) {
-		char *addrp;
+		union inet_addr *addrp = (union inet_addr *)address;
 		struct sk_security_struct *sksec = sk->sk_security;
 		struct common_audit_data ad;
 		struct lsm_network_audit net = {0,};
-		struct sockaddr_in *addr4 = NULL;
-		struct sockaddr_in6 *addr6 = NULL;
 		unsigned short snum;
 		u32 sid, node_perm;
 
-		if (family == PF_INET) {
-			addr4 = (struct sockaddr_in *)address;
-			snum = ntohs(addr4->sin_port);
-			addrp = (char *)&addr4->sin_addr.s_addr;
-		} else {
-			addr6 = (struct sockaddr_in6 *)address;
-			snum = ntohs(addr6->sin6_port);
-			addrp = (char *)&addr6->sin6_addr.s6_addr;
-		}
-
+		addrp->sa.sa_family = family;
+		snum = inet_addr_get_port(addrp);
 		if (snum) {
 			int low, high;
 
@@ -3943,8 +3932,9 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
 					goto out;
 				ad.type = LSM_AUDIT_DATA_NET;
 				ad.u.net = &net;
-				ad.u.net->sport = htons(snum);
-				ad.u.net->family = family;
+				inet_addr_set_port(&ad.u.net->saddr, snum);
+				ad.u.net->saddr.sa.sa_family = family;
+				ad.u.net->daddr.sa.sa_family = family;
 				err = avc_has_perm(sksec->sid, sid,
 						   sksec->sclass,
 						   SOCKET__NAME_BIND, &ad);
@@ -3971,19 +3961,17 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
 			break;
 		}
 
-		err = sel_netnode_sid(addrp, family, &sid);
+		err = sel_netnode_sid(addrp, &sid);
 		if (err)
 			goto out;
 
 		ad.type = LSM_AUDIT_DATA_NET;
 		ad.u.net = &net;
-		ad.u.net->sport = htons(snum);
-		ad.u.net->family = family;
+		inet_addr_set_port(&ad.u.net->saddr, snum);
+		ad.u.net->saddr.sa.sa_family = family;
+		ad.u.net->daddr.sa.sa_family = family;
 
-		if (family == PF_INET)
-			ad.u.net->v4info.saddr = addr4->sin_addr.s_addr;
-		else
-			ad.u.net->v6info.saddr = addr6->sin6_addr;
+		ad.u.net->saddr = *addrp;
 
 		err = avc_has_perm(sksec->sid, sid,
 				   sksec->sclass, node_perm, &ad);
@@ -4011,22 +3999,18 @@ static int selinux_socket_connect(struct socket *sock, struct sockaddr *address,
 	    sksec->sclass == SECCLASS_DCCP_SOCKET) {
 		struct common_audit_data ad;
 		struct lsm_network_audit net = {0,};
-		struct sockaddr_in *addr4 = NULL;
-		struct sockaddr_in6 *addr6 = NULL;
+		union inet_addr *addrp = (union inet_addr *)address;
 		unsigned short snum;
 		u32 sid, perm;
 
 		if (sk->sk_family == PF_INET) {
-			addr4 = (struct sockaddr_in *)address;
 			if (addrlen < sizeof(struct sockaddr_in))
 				return -EINVAL;
-			snum = ntohs(addr4->sin_port);
 		} else {
-			addr6 = (struct sockaddr_in6 *)address;
 			if (addrlen < SIN6_LEN_RFC2133)
 				return -EINVAL;
-			snum = ntohs(addr6->sin6_port);
 		}
+		snum = inet_addr_get_port(addrp);
 
 		err = sel_netport_sid(sk->sk_protocol, snum, &sid);
 		if (err)
@@ -4037,8 +4021,9 @@ static int selinux_socket_connect(struct socket *sock, struct sockaddr *address,
 
 		ad.type = LSM_AUDIT_DATA_NET;
 		ad.u.net = &net;
-		ad.u.net->dport = htons(snum);
-		ad.u.net->family = sk->sk_family;
+		inet_addr_set_port(&ad.u.net->daddr, snum);
+		ad.u.net->saddr.sa.sa_family = sk->sk_family;
+		ad.u.net->daddr.sa.sa_family = sk->sk_family;
 		err = avc_has_perm(sksec->sid, sid, sksec->sclass, perm, &ad);
 		if (err)
 			goto out;
@@ -4169,7 +4154,7 @@ static int selinux_socket_unix_may_send(struct socket *sock,
 			    &ad);
 }
 
-static int selinux_inet_sys_rcv_skb(int ifindex, char *addrp, u16 family,
+static int selinux_inet_sys_rcv_skb(int ifindex, union inet_addr *addrp,
 				    u32 peer_sid,
 				    struct common_audit_data *ad)
 {
@@ -4185,7 +4170,7 @@ static int selinux_inet_sys_rcv_skb(int ifindex, char *addrp, u16 family,
 	if (err)
 		return err;
 
-	err = sel_netnode_sid(addrp, family, &node_sid);
+	err = sel_netnode_sid(addrp, &node_sid);
 	if (err)
 		return err;
 	return avc_has_perm(peer_sid, node_sid,
@@ -4200,12 +4185,13 @@ static int selinux_sock_rcv_skb_compat(struct sock *sk, struct sk_buff *skb,
 	u32 sk_sid = sksec->sid;
 	struct common_audit_data ad;
 	struct lsm_network_audit net = {0,};
-	char *addrp;
+	union inet_addr *addrp;
 
 	ad.type = LSM_AUDIT_DATA_NET;
 	ad.u.net = &net;
 	ad.u.net->netif = skb->skb_iif;
-	ad.u.net->family = family;
+	ad.u.net->saddr.sa.sa_family = family;
+	ad.u.net->daddr.sa.sa_family = family;
 	err = selinux_parse_skb(skb, &ad, &addrp, 1, NULL);
 	if (err)
 		return err;
@@ -4233,7 +4219,7 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
 	u32 sk_sid = sksec->sid;
 	struct common_audit_data ad;
 	struct lsm_network_audit net = {0,};
-	char *addrp;
+	union inet_addr *addrp;
 	u8 secmark_active;
 	u8 peerlbl_active;
 
@@ -4259,7 +4245,8 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
 	ad.type = LSM_AUDIT_DATA_NET;
 	ad.u.net = &net;
 	ad.u.net->netif = skb->skb_iif;
-	ad.u.net->family = family;
+	ad.u.net->saddr.sa.sa_family = family;
+	ad.u.net->daddr.sa.sa_family = family;
 	err = selinux_parse_skb(skb, &ad, &addrp, 1, NULL);
 	if (err)
 		return err;
@@ -4270,7 +4257,8 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
 		err = selinux_skb_peerlbl_sid(skb, family, &peer_sid);
 		if (err)
 			return err;
-		err = selinux_inet_sys_rcv_skb(skb->skb_iif, addrp, family,
+		addrp->sa.sa_family = family;
+		err = selinux_inet_sys_rcv_skb(skb->skb_iif, addrp,
 					       peer_sid, &ad);
 		if (err) {
 			selinux_netlbl_err(skb, err, 0);
@@ -4621,7 +4609,7 @@ static unsigned int selinux_ip_forward(struct sk_buff *skb, int ifindex,
 				       u16 family)
 {
 	int err;
-	char *addrp;
+	union inet_addr *addrp;
 	u32 peer_sid;
 	struct common_audit_data ad;
 	struct lsm_network_audit net = {0,};
@@ -4644,12 +4632,14 @@ static unsigned int selinux_ip_forward(struct sk_buff *skb, int ifindex,
 	ad.type = LSM_AUDIT_DATA_NET;
 	ad.u.net = &net;
 	ad.u.net->netif = ifindex;
-	ad.u.net->family = family;
+	ad.u.net->saddr.sa.sa_family = family;
+	ad.u.net->daddr.sa.sa_family = family;
 	if (selinux_parse_skb(skb, &ad, &addrp, 1, NULL) != 0)
 		return NF_DROP;
 
 	if (peerlbl_active) {
-		err = selinux_inet_sys_rcv_skb(ifindex, addrp, family,
+		addrp->sa.sa_family = family;
+		err = selinux_inet_sys_rcv_skb(ifindex, addrp,
 					       peer_sid, &ad);
 		if (err) {
 			selinux_netlbl_err(skb, err, 1);
@@ -4732,7 +4722,7 @@ static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb,
 	struct sk_security_struct *sksec;
 	struct common_audit_data ad;
 	struct lsm_network_audit net = {0,};
-	char *addrp;
+	union inet_addr *addrp;
 	u8 proto;
 
 	if (sk == NULL)
@@ -4742,7 +4732,8 @@ static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb,
 	ad.type = LSM_AUDIT_DATA_NET;
 	ad.u.net = &net;
 	ad.u.net->netif = ifindex;
-	ad.u.net->family = family;
+	ad.u.net->saddr.sa.sa_family = family;
+	ad.u.net->daddr.sa.sa_family = family;
 	if (selinux_parse_skb(skb, &ad, &addrp, 0, &proto))
 		return NF_DROP;
 
@@ -4765,7 +4756,7 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex,
 	struct sock *sk;
 	struct common_audit_data ad;
 	struct lsm_network_audit net = {0,};
-	char *addrp;
+	union inet_addr *addrp;
 	u8 secmark_active;
 	u8 peerlbl_active;
 
@@ -4813,7 +4804,8 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex,
 	ad.type = LSM_AUDIT_DATA_NET;
 	ad.u.net = &net;
 	ad.u.net->netif = ifindex;
-	ad.u.net->family = family;
+	ad.u.net->saddr.sa.sa_family = family;
+	ad.u.net->daddr.sa.sa_family = family;
 	if (selinux_parse_skb(skb, &ad, &addrp, 0, NULL))
 		return NF_DROP;
 
@@ -4832,7 +4824,7 @@ static unsigned int selinux_ip_postroute(struct sk_buff *skb, int ifindex,
 				 SECCLASS_NETIF, NETIF__EGRESS, &ad))
 			return NF_DROP_ERR(-ECONNREFUSED);
 
-		if (sel_netnode_sid(addrp, family, &node_sid))
+		if (sel_netnode_sid(addrp, &node_sid))
 			return NF_DROP;
 		if (avc_has_perm(peer_sid, node_sid,
 				 SECCLASS_NODE, NODE__SENDTO, &ad))
security/selinux/include/netnode.h +3 -1
index df7a5ed..f32c909 100644
@@ -27,6 +27,8 @@
 #ifndef _SELINUX_NETNODE_H
 #define _SELINUX_NETNODE_H
 
-int sel_netnode_sid(void *addr, u16 family, u32 *sid);
+#include <net/inet_addr.h>
+
+int sel_netnode_sid(union inet_addr *addr, u32 *sid);
 
 #endif
security/selinux/include/objsec.h +2 -5
index aa47bca..a46caaf 100644
@@ -24,6 +24,7 @@
 #include <linux/binfmts.h>
 #include <linux/in.h>
 #include <linux/spinlock.h>
+#include <net/inet_addr.h>
 #include "flask.h"
 #include "avc.h"
 
@@ -80,12 +81,8 @@ struct netif_security_struct {
 };
 
 struct netnode_security_struct {
-	union {
-		__be32 ipv4;		/* IPv4 node address */
-		struct in6_addr ipv6;	/* IPv6 node address */
-	} addr;
+	union inet_addr addr;
 	u32 sid;			/* SID for this node */
-	u16 family;			/* address family */
 };
 
 struct netport_security_struct {
security/selinux/netnode.c +30 -72
index c5454c0..713f14e 100644
@@ -68,79 +68,49 @@ static LIST_HEAD(sel_netnode_list);
 static DEFINE_SPINLOCK(sel_netnode_lock);
 static struct sel_netnode_bkt sel_netnode_hash[SEL_NETNODE_HASH_SIZE];
 
-/**
- * sel_netnode_hashfn_ipv4 - IPv4 hashing function for the node table
- * @addr: IPv4 address
- *
- * Description:
- * This is the IPv4 hashing function for the node interface table, it returns
- * the bucket number for the given IP address.
- *
- */
-static unsigned int sel_netnode_hashfn_ipv4(__be32 addr)
-{
-	/* at some point we should determine if the mismatch in byte order
-	 * affects the hash function dramatically */
-	return (addr & (SEL_NETNODE_HASH_SIZE - 1));
-}
 
 /**
- * sel_netnode_hashfn_ipv6 - IPv6 hashing function for the node table
- * @addr: IPv6 address
+ * sel_netnode_hashfn - IPv4/IPv6 hashing function for the node table
+ * @addr: generic IP address
  *
  * Description:
- * This is the IPv6 hashing function for the node interface table, it returns
+ * This is the IP hashing function for the node interface table, it returns
  * the bucket number for the given IP address.
  *
  */
-static unsigned int sel_netnode_hashfn_ipv6(const struct in6_addr *addr)
+static unsigned int sel_netnode_hashfn(const union inet_addr *addr)
 {
-	/* just hash the least significant 32 bits to keep things fast (they
-	 * are the most likely to be different anyway), we can revisit this
-	 * later if needed */
-	return (addr->s6_addr32[3] & (SEL_NETNODE_HASH_SIZE - 1));
+	if (addr->sa.sa_family == PF_INET)
+		/* at some point we should determine if the mismatch in byte order
+		 * affects the hash function dramatically */
+		return (addr->sin.sin_addr.s_addr & (SEL_NETNODE_HASH_SIZE - 1));
+	else if (addr->sa.sa_family == PF_INET6)
+		/* just hash the least significant 32 bits to keep things fast (they
+		 * are the most likely to be different anyway), we can revisit this
+		 * later if needed */
+		return (addr->sin6.sin6_addr.s6_addr32[3] & (SEL_NETNODE_HASH_SIZE - 1));
+	else
+		BUG();
 }
 
 /**
  * sel_netnode_find - Search for a node record
  * @addr: IP address
- * @family: address family
  *
  * Description:
  * Search the network node table and return the record matching @addr.  If an
  * entry can not be found in the table return NULL.
  *
  */
-static struct sel_netnode *sel_netnode_find(const void *addr, u16 family)
+static struct sel_netnode *sel_netnode_find(const union inet_addr *addr)
 {
 	unsigned int idx;
 	struct sel_netnode *node;
 
-	switch (family) {
-	case PF_INET:
-		idx = sel_netnode_hashfn_ipv4(*(__be32 *)addr);
-		break;
-	case PF_INET6:
-		idx = sel_netnode_hashfn_ipv6(addr);
-		break;
-	default:
-		BUG();
-		return NULL;
-	}
-
+	idx = sel_netnode_hashfn(addr);
 	list_for_each_entry_rcu(node, &sel_netnode_hash[idx].list, list)
-		if (node->nsec.family == family)
-			switch (family) {
-			case PF_INET:
-				if (node->nsec.addr.ipv4 == *(__be32 *)addr)
-					return node;
-				break;
-			case PF_INET6:
-				if (ipv6_addr_equal(&node->nsec.addr.ipv6,
-						    addr))
-					return node;
-				break;
-			}
+		if (inet_addr_equal(&node->nsec.addr, addr))
+			return node;
 
 	return NULL;
 }
@@ -156,18 +126,9 @@ static struct sel_netnode *sel_netnode_find(const void *addr, u16 family)
 static void sel_netnode_insert(struct sel_netnode *node)
 {
 	unsigned int idx;
+	union inet_addr *addr = &node->nsec.addr;
 
-	switch (node->nsec.family) {
-	case PF_INET:
-		idx = sel_netnode_hashfn_ipv4(node->nsec.addr.ipv4);
-		break;
-	case PF_INET6:
-		idx = sel_netnode_hashfn_ipv6(&node->nsec.addr.ipv6);
-		break;
-	default:
-		BUG();
-	}
-
+	idx = sel_netnode_hashfn(addr);
 	/* we need to impose a limit on the growth of the hash table so check
 	 * this bucket to make sure it is within the specified bounds */
 	list_add_rcu(&node->list, &sel_netnode_hash[idx].list);
@@ -186,7 +147,6 @@ static void sel_netnode_insert(struct sel_netnode *node)
 /**
  * sel_netnode_sid_slow - Lookup the SID of a network address using the policy
  * @addr: the IP address
- * @family: the address family
  * @sid: node SID
  *
  * Description:
@@ -196,14 +156,14 @@ static void sel_netnode_insert(struct sel_netnode *node)
  * failure.
  *
  */
-static int sel_netnode_sid_slow(void *addr, u16 family, u32 *sid)
+static int sel_netnode_sid_slow(union inet_addr *addr, u32 *sid)
 {
 	int ret = -ENOMEM;
 	struct sel_netnode *node;
 	struct sel_netnode *new = NULL;
 
 	spin_lock_bh(&sel_netnode_lock);
-	node = sel_netnode_find(addr, family);
+	node = sel_netnode_find(addr);
 	if (node != NULL) {
 		*sid = node->nsec.sid;
 		spin_unlock_bh(&sel_netnode_lock);
@@ -212,16 +172,16 @@ static int sel_netnode_sid_slow(void *addr, u16 family, u32 *sid)
 	new = kzalloc(sizeof(*new), GFP_ATOMIC);
 	if (new == NULL)
 		goto out;
-	switch (family) {
+	switch (addr->sa.sa_family) {
 	case PF_INET:
 		ret = security_node_sid(PF_INET,
 					addr, sizeof(struct in_addr), sid);
-		new->nsec.addr.ipv4 = *(__be32 *)addr;
+		new->nsec.addr = *addr;
 		break;
 	case PF_INET6:
 		ret = security_node_sid(PF_INET6,
 					addr, sizeof(struct in6_addr), sid);
-		new->nsec.addr.ipv6 = *(struct in6_addr *)addr;
+		new->nsec.addr = *addr;
 		break;
 	default:
 		BUG();
@@ -229,7 +189,6 @@ static int sel_netnode_sid_slow(void *addr, u16 family, u32 *sid)
 	if (ret != 0)
 		goto out;
 
-	new->nsec.family = family;
 	new->nsec.sid = *sid;
 	sel_netnode_insert(new);
 
@@ -246,8 +205,7 @@ out:
 
 /**
  * sel_netnode_sid - Lookup the SID of a network address
- * @addr: the IP address
- * @family: the address family
+ * @addr: the generic IP address
  * @sid: node SID
  *
  * Description:
@@ -258,12 +216,12 @@ out:
  * on failure.
  *
  */
-int sel_netnode_sid(void *addr, u16 family, u32 *sid)
+int sel_netnode_sid(union inet_addr *addr, u32 *sid)
 {
 	struct sel_netnode *node;
 
 	rcu_read_lock();
-	node = sel_netnode_find(addr, family);
+	node = sel_netnode_find(addr);
 	if (node != NULL) {
 		*sid = node->nsec.sid;
 		rcu_read_unlock();
@@ -271,7 +229,7 @@ int sel_netnode_sid(void *addr, u16 family, u32 *sid)
 	}
 	rcu_read_unlock();
 
-	return sel_netnode_sid_slow(addr, family, sid);
+	return sel_netnode_sid_slow(addr, sid);
 }
 
 /**
security/smack/smack_lsm.c +10 -9
index eefbd10..9a80923 100644
@@ -1900,9 +1900,7 @@ static int smack_netlabel_send(struct sock *sk, struct sockaddr_in *sap)
 		struct lsm_network_audit net;
 
 		smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
-		ad.a.u.net->family = sap->sin_family;
-		ad.a.u.net->dport = sap->sin_port;
-		ad.a.u.net->v4info.daddr = sap->sin_addr.s_addr;
+		ad.a.u.net->daddr = (union inet_addr )*sap;
 #endif
 		sk_lbl = SMACK_UNLABELED_SOCKET;
 		skp = ssp->smk_out;
@@ -2055,12 +2053,13 @@ auditout:
 
 #ifdef CONFIG_AUDIT
 	smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
-	ad.a.u.net->family = sk->sk_family;
-	ad.a.u.net->dport = port;
+	inet_addr_set_port(&ad.a.u.net->daddr, port);
+	ad.a.u.net->saddr.sa.sa_family = sk->sk_family;
+	ad.a.u.net->daddr.sa.sa_family = sk->sk_family;
 	if (act == SMK_RECEIVING)
-		ad.a.u.net->v6info.saddr = address->sin6_addr;
+		ad.a.u.net->saddr.sin6.sin6_addr = address->sin6_addr;
 	else
-		ad.a.u.net->v6info.daddr = address->sin6_addr;
+		ad.a.u.net->daddr.sin6.sin6_addr = address->sin6_addr;
 #endif
 	return smk_access(skp, object, MAY_WRITE, &ad);
 }
@@ -3202,7 +3201,8 @@ static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
 
 #ifdef CONFIG_AUDIT
 		smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
-		ad.a.u.net->family = sk->sk_family;
+		ad.a.u.net->saddr.sa.sa_family = sk->sk_family;
+		ad.a.u.net->daddr.sa.sa_family = sk->sk_family;
 		ad.a.u.net->netif = skb->skb_iif;
 		ipv4_skb_to_auditdata(skb, &ad.a, NULL);
 #endif
@@ -3384,7 +3384,8 @@ static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb,
 
 #ifdef CONFIG_AUDIT
 	smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
-	ad.a.u.net->family = family;
+	ad.a.u.net->saddr.sa.sa_family = family;
+	ad.a.u.net->daddr.sa.sa_family = family;
 	ad.a.u.net->netif = skb->skb_iif;
 	ipv4_skb_to_auditdata(skb, &ad.a, NULL);
 #endif
maintainer
#13 lore raw

Re: [Patch net-next v3 9/9] selinux: use generic union inet_addr

It's so that you can pass a generic ipv4/ipv6 address blob into things like printf formatting, and since there is an address family member present, it knows what's in there and therefore one printf format specifier can handle both ipv4 and ipv6 addresses.

Like you, I think these changes a complete waste of time too, I'm just relaying what I was told.

maintainer
#14 lore raw

Re: [Patch net-next v3 9/9] selinux: use generic union inet_addr

Quoted 4 lines · David Miller

It's so that you can pass a generic ipv4/ipv6 address blob into things like printf formatting, and since there is an address family member present, it knows what's in there and therefore one printf format specifier can handle both ipv4 and ipv6 addresses.

The patch message needs to say that, then.

Quoted 2 lines

Like you, I think these changes a complete waste of time too, I'm just relaying what I was told.

Well, they certainly don't appear to add any value on their own. I also generally oppose doing clever things with data structures. I recently got bitten by the "obvious" relationships between sockaddr, sockaddr_in and sockaddr_in6, and I've been doing this stuff since before ioctl was invented.

maintainer
#15 lore raw

Re: [Patch net-next v3 9/9] selinux: use generic union inet_addr

From: Casey Schaufler <[email protected]>
Date: Mon, 19 Aug 2013 14:42:55 -0700

Quoted 7 lines · David Miller
Quoted 4 lines

It's so that you can pass a generic ipv4/ipv6 address blob into things like printf formatting, and since there is an address family member present, it knows what's in there and therefore one printf format specifier can handle both ipv4 and ipv6 addresses.

The patch message needs to say that, then.

Actually, that belongs in the "0/N" posting, the contents of which will end up in the merge commit should I apply the series.

author
#16 lore raw

Re: [Patch net-next v3 9/9] selinux: use generic union inet_addr

In reply to Casey Schaufler
Quoted 3 lines · Casey Schaufler

Well, they certainly don't appear to add any value on their own. I also generally oppose doing clever things with data structures.

If you want to implement same thing for 5+ times, yes, it has no value for you. Enjoy the following code in current tree:

union nf_inet_addr;
union sctp_addr;
union vxlan_addr; (in my VXLAN IPv6 patches, search email archives) struct br_mdb_entry::addr;
union inet_addr; (in netpoll.h)

And may I tell you the last three are all from me? ;-)

maintainer
#17 lore raw

Re: [Patch net-next v3 9/9] selinux: use generic union inet_addr

Quoted 4 lines · Cong Wang
Quoted 2 lines · Casey Schaufler

Well, they certainly don't appear to add any value on their own. I also generally oppose doing clever things with data structures.

If you want to implement same thing for 5+ times,

Those 5+ implementations are already there, and already work. A 6th implementation to replace known working code is just churn unless it provides some additional value. Making the code "better" does not itself add value.

Quoted 10 lines

yes, it has no value
for you. Enjoy the following code in current tree:

union nf_inet_addr;
union sctp_addr;
union vxlan_addr; (in my VXLAN IPv6 patches, search email archives) struct br_mdb_entry::addr;
union inet_addr; (in netpoll.h)

And may I tell you the last three are all from me? ;-)

I do use and enjoy all of these implementations! Thank you for the fine implementations. In the end, if you're maintaining the code it's your call. I question change that does not have an obvious purpose because statistically every 10th change has a bug.

Now that I know what the change is for I am fine with it. I like seeing reasons up front.

Quoted 7 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#18 lore raw

Re: [Patch net-next v3 9/9] selinux: use generic union inet_addr

Imho, the patch doesn't go far enough actually. What should be done:

- get rid of the union
- use IPv6 format only
- store IPv4 addresses in IPv4 mapped format

author
#19 lore raw

Re: [Patch net-next v3 9/9] selinux: use generic union inet_addr

In reply to Casey Schaufler
Quoted 6 lines · Casey Schaufler

I do use and enjoy all of these implementations! Thank you for the fine implementations. In the end, if you're maintaining the code it's your call. I question change that does not have an obvious purpose because statistically every 10th change has a bug.

Sure, feel free to add more.

And please reject all new code >=10 changes in the future too... I give up, you win. :-)

maintainer
#20 lore raw
In reply to Cong Wang

From: Cong Wang <[email protected]>
Date: Mon, 19 Aug 2013 18:14:29 +0800

Quoted 12 lines

From: Cong Wang <[email protected]>

As IPv6 becomes popular, more and more subsystems begin to support IPv6, therefore we need a generic IP address type, in case of duplicates. Also we will also need some helpers to compare, print, check the generic IP address.

This patchset introduce a new type union inet_addr as a union of IPv4 and IPv6 address, and struct in_addr_gen for inetpeer and bridge mdb, plus some helper functions that will be used by existing code and in the future VXLAN module.

Quoted 4 lines

However, due to ABI limit, we still can't convert union nf_inet_addr to union inet_addr.

I still don't want to apply this patch series, and very honestly my patience is running very thin.

Netconsole and netpoll do not need the family field, and they absolutely do not need the port field that a sockaddr_in et al. provide.

So you have to get rid of it, and do the same simplification everywhere. So I don't have to tell you to do it again when you resubmit this stuff and the next patch I get to has the same exact problem.

If this patch series doesn't converge upon adding absolutely zero overhead where it isn't needed I'm just going to auto-reject these patches when you post them, that's how frustrated I am with this stuff.

If in the process of commonizing you add stuff where it isn't needed then you're doing it wrong.

That's why all these places use a different data structure! They have different needs. Can you see that?

author
#21 lore raw
Quoted 4 lines · David Miller

That's why all these places use a different data structure! They have different needs. Can you see that?

No problem, then let's drop this patchset.
And I will continue to duplicate the code in my VXLAN patchset.

Thanks.