net: introduce generic type and helpers for IP address
Subsystems (16)
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 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.
Changes since RFC:
* 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 (7):
net: introduce generic union inet_addr
net: introduce generic simple_inet_pton()
inetpeer: use generic union inet_addr
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 | 39 ++----- fs/dlm/lowcomms.c | 24 +--- fs/nfs/client.c | 94 +------------- fs/nfs/nfs4filelayoutdev.c | 37 +----- fs/nfs/super.c | 31 +---- include/linux/lsm_audit.h | 16 +-- include/linux/netpoll.h | 9 +-- include/linux/sunrpc/addr.h | 118 +----------------- include/net/inet_addr.h | 106 ++++++++++++++++ include/net/inetpeer.h | 29 ++--- include/net/sctp/sctp.h | 22 ++-- include/net/sctp/sm.h | 4 +- include/net/sctp/structs.h | 132 +++++++++----------- lib/vsprintf.c | 29 ++--- net/core/netpoll.c | 86 +++++-------- net/core/utils.c | 84 +++++++++++++ net/ipv4/inetpeer.c | 37 ++++-- net/ipv4/tcp_metrics.c | 92 ++++++-------- 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 +- security/lsm_audit.c | 16 ++-- security/selinux/hooks.c | 73 ++++------- security/selinux/include/netnode.h | 4 +- security/selinux/include/objsec.h | 7 +- security/selinux/netnode.c | 102 +++++----------- 39 files changed, 878 insertions(+), 1197 deletions(-) create mode 100644 include/net/inet_addr.h
Signature · 1 line
1.7.7.6
PATCH 1/7 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.
This patch also reuses the "%pIS" specifier, to make it accept union inet_addr instead of struct sockaddr.
--- Documentation/printk-formats.txt | 20 ++++++------ drivers/net/netconsole.c | 22 ++++++------- include/linux/netpoll.h | 9 +----- include/net/inet_addr.h | 62 ++++++++++++++++++++++++++++++++++++++ lib/vsprintf.c | 29 ++++++++---------- net/core/netpoll.c | 52 ++++++++++++++----------------- net/sctp/associola.c | 6 ++-- net/sctp/protocol.c | 6 ++-- net/sctp/sm_sideeffect.c | 2 +- net/sctp/socket.c | 4 +- 10 files changed, 129 insertions(+), 83 deletions(-) create mode 100644 include/net/inet_addr.h
Documentation/printk-formats.txt +10 -10
@@ -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 +10 -12
@@ -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.in6); -else -return snprintf (buf,PAGE_SIZE ,"%pI4\n" , &nt->np.local_ip); +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.in6); -else -return snprintf (buf,PAGE_SIZE ,"%pI4\n" , &nt->np.remote_ip); +return snprintf (buf,PAGE_SIZE ,"%pIA\n" , &nt->np.remote_ip); }static ssize_t show_local_mac (struct netconsole_target *nt,char *buf)
@@ -419,17 +413,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 +446,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
@@ -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
lib/vsprintf.c +13 -16
@@ -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 +24 -28
140 lines not on this page · raw message
net/sctp/associola.c +3 -3
@@ -540,7 +540,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
@@ -637,7 +637,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. */
@@ -1347,7 +1347,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
@@ -604,7 +604,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);
@@ -709,7 +709,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);
@@ -729,7 +729,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
@@ -520,7 +520,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
@@ -349,7 +349,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. */
@@ -803,7 +803,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
PATCH 2/7 net: introduce generic simple_inet_pton()
In reply to Cong WangFrom: 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.
--- 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
@@ -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 +extern int simple_inet_pton (const char *str,union inet_addr *addr); +#endif
net/core/netpoll.c +8 -28
@@ -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
@@ -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
PATCH 3/7 inetpeer: use generic union inet_addr
In reply to Cong WangFrom: Cong Wang <[email protected]>
struct inetpeer_addr is pretty similar to generic union inet_addr, therefore can be safely converted to it.
--- include/net/inetpeer.h | 29 +++++---------- net/ipv4/inetpeer.c | 37 ++++++++++++------- net/ipv4/tcp_metrics.c | 92 ++++++++++++++++++++---------------------------- 3 files changed, 70 insertions(+), 88 deletions(-)
include/net/inetpeer.h +9 -20
@@ -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; +union inet_addr daddr;__u32 avl_height;u32 metrics[RTAX_MAX ];
@@ -133,17 +122,17 @@ 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 union inet_addr *daddr,int create);static inline struct inet_peer *inet_getpeer_v4 (struct inet_peer_base *base,__be32 v4daddr,int create) { -struct inetpeer_addr daddr; +union inet_addr daddr; - daddr.addr.a4 = v4daddr; - daddr.family =AF_INET ; + daddr.sin.sin_addr.s_addr = v4daddr; + daddr.sa.sa_family =AF_INET ;return inet_getpeer (base, &daddr, create); }
@@ -151,10 +140,10 @@ static inline struct inet_peer *inet_getpeer_v6(struct inet_peer_base *base, const struct in6_addr *v6daddr, int create) { -struct inetpeer_addr daddr; +union inet_addr daddr; - *(struct in6_addr *)daddr.addr.a6 = *v6daddr; - daddr.family =AF_INET6 ; + daddr.sin6.sin6_addr = *v6daddr; + daddr.sa.sa_family =AF_INET6 ;return inet_getpeer (base, &daddr, create); }
net/ipv4/inetpeer.c +23 -14
@@ -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 union inet_addr *a, +const union inet_addr *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->sa.sa_family ==AF_INET ) { +if (a->sin.sin_addr.s_addr == b->sin.sin_addr.s_addr) +return 0 ; +if ((__force u32 )a->sin.sin_addr.s_addr < + (__force u32 )b->sin.sin_addr.s_addr)return -1 ; -return 1 ; + }else { +for (i =0 ; i <4 ; i++) { +if (a->sin6.sin6_addr.s6_addr32[i] == b->sin6.sin6_addr.s6_addr32[i]) +continue ; +if ((__force u32 )a->sin6.sin6_addr.s6_addr32[i] < + (__force u32 )b->sin6.sin6_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 union inet_addr *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 union inet_addr *daddr,int create) {struct inet_peer __rcu **stack[PEER_MAXDEPTH ], ***stackptr;
@@ -465,7 +474,7 @@ struct inet_peer *inet_getpeer(struct inet_peer_base *base,unsigned int sequence;int invalidated, gccnt =0 ; -flush_check (base, daddr->family); +flush_check (base, daddr->sa.sa_family);/* Attempt a lockless lookup first. * Because of a concurrent writer, we might not find an existing entry.
@@ -505,9 +514,9 @@ relookup:atomic_set (&p->refcnt,1 );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)); + (daddr->sa.sa_family ==AF_INET ) ? +secure_ip_id (daddr->sin.sin_addr.s_addr) : +secure_ipv6_id (daddr->sin6.sin6_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 +38 -54
226 lines not on this page · raw message
Signature · 1 line
1.7.7.6
Re: [Patch net-next 3/7] inetpeer: use generic union inet_addr
Quoted 4 lines · Cong Wang
From: Cong Wang <[email protected]>
struct
inetpeer_addris pretty similar to generic unioninet_addr, therefore can be safely converted to it.
Its 'safe' but adds 50% increase for struct tcp_metrics_block
I fail to see this mentioned in the changelog.
I guess its no big deal, but why do you think this code used hand coded functions instead of generic ?
Re: [Patch net-next 3/7] inetpeer: use generic union inet_addr
Quoted 9 lines · Eric Dumazet
Quoted 4 lines · Cong Wang
From: Cong Wang <[email protected]>
struct
inetpeer_addris pretty similar to generic unioninet_addr, therefore can be safely converted to it.Its 'safe' but adds 50% increase for struct
tcp_metrics_blockI fail to see this mentioned in the changelog.
I asked you in RFC, but you don't give me any response, this is the reason. :)
Quoted 5 lines
I guess its no big deal, but why do you think this code used hand coded functions instead of generic ?
I don't understand what you are asking here, seems totally unrelated with the point you raised above, therefore I am completely confused...
Thanks.
Re: [Patch net-next 3/7] inetpeer: use generic union inet_addr
Quoted 7 lines · Cong Wang
Quoted 6 lines · Eric Dumazet
Quoted 4 lines · Cong Wang
From: Cong Wang <[email protected]>
struct
inetpeer_addris pretty similar to generic unioninet_addr, therefore can be safely converted to it.
Quoted 7 lines
Quoted 3 lines
Its 'safe' but adds 50% increase for struct
tcp_metrics_blockI fail to see this mentioned in the changelog.
I asked you in RFC, but you don't give me any response, this is the reason. :)
I mentioned an increase in size of the structures, you replied :
"rearrange the fields of struct inet_peer in case of cacheline miss?" which was a complete different matter, I had other more urgent work I guess.
Quoted 8 lines
Quoted 5 lines
I guess its no big deal, but why do you think this code used hand coded functions instead of generic ?
I don't understand what you are asking here, seems totally unrelated with the point you raised above, therefore I am completely confused...
You are sending a patch with possible performance impact, and you only says "its safe", without any real study. It might have an impact, who knows.
I said "its no big deal", so consider this as an informative message.
Re: [Patch net-next 3/7] inetpeer: use generic union inet_addr
Quoted 5 lines · Eric Dumazet
You are sending a patch with possible performance impact, and you only says "its safe", without any real study. It might have an impact, who knows.
I said "its no big deal", so consider this as an informative message.
Yeah.
So changing from struct inetpeer_addr to union inet_addr just adds few bytes (8 bytes if I don't make mistake) to struct tcp_metrics_block, therefore should not cause performance issue on 32bit and 64bit?
BTW, I tried to use pahole to get the offsets of these fields, but it doesn't work for me.
Thanks!
PATCH 4/7 sunrpc: use generic union inet_addr
In reply to Cong WangFrom: Cong Wang <[email protected]>
sunrpc defines some helper functions for sockaddr, actually they can re-use the generic functions for union inet_addr too.
--- include/linux/sunrpc/addr.h | 118 +++---------------------------------------- include/net/inet_addr.h | 74 +++++++++++++++++++++------ net/core/utils.c | 25 +++++++++ 3 files changed, 89 insertions(+), 128 deletions(-)
include/linux/sunrpc/addr.h +7 -111
@@ -11,6 +11,7 @@#include <linux/in.h> #include <linux/in6.h> #include <net/ipv6.h> +#include <net/inet_addr.h> size_t rpc_ntop (const struct sockaddr *,char *,const size_t ); size_t rpc_pton(struct net *, const char *, const size_t,
@@ -21,135 +22,30 @@ size_t rpc_uaddr2sockaddr(struct net *, const char *, const size_t,static inline unsigned short rpc_get_port (const struct sockaddr *sap) { -switch (sap->sa_family) { -case AF_INET : -return ntohs (((struct sockaddr_in *)sap)->sin_port); -case AF_INET6 : -return ntohs (((struct sockaddr_in6 *)sap)->sin6_port); - } -return 0 ; +return inet_addr_get_port ((const union inet_addr *)sap); }static inline void rpc_set_port (struct sockaddr *sap,const unsigned short port) { -switch (sap->sa_family) { -case AF_INET : - ((struct sockaddr_in *)sap)->sin_port =htons (port); -break ; -case AF_INET6 : - ((struct sockaddr_in6 *)sap)->sin6_port =htons (port); -break ; - } +inet_addr_set_port ((union inet_addr *)sap, port); }#define IPV6_SCOPE_DELIMITER '%'#define IPV6_SCOPE_ID_LEN sizeof("%nnnnnnnnnn") -static inline bool __rpc_cmp_addr4 (const struct sockaddr *sap1, -const struct sockaddr *sap2) -{ -const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sap1; -const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sap2; - -return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr; -} - -static inline bool __rpc_copy_addr4 (struct sockaddr *dst, -const struct sockaddr *src) -{ -const struct sockaddr_in *ssin = (struct sockaddr_in *) src; -struct sockaddr_in *dsin = (struct sockaddr_in *) dst; - - dsin->sin_family = ssin->sin_family; - dsin->sin_addr.s_addr = ssin->sin_addr.s_addr; -return true; -} - -#if IS_ENABLED (CONFIG_IPV6 ) -static inline bool __rpc_cmp_addr6 (const struct sockaddr *sap1, -const struct sockaddr *sap2) -{ -const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sap1; -const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sap2; - -if (!ipv6_addr_equal (&sin1->sin6_addr, &sin2->sin6_addr)) -return false; -else if (ipv6_addr_type (&sin1->sin6_addr) &IPV6_ADDR_LINKLOCAL ) -return sin1->sin6_scope_id == sin2->sin6_scope_id; - -return true; -} - -static inline bool __rpc_copy_addr6 (struct sockaddr *dst, -const struct sockaddr *src) -{ -const struct sockaddr_in6 *ssin6 = (const struct sockaddr_in6 *) src; -struct sockaddr_in6 *dsin6 = (struct sockaddr_in6 *) dst; - - dsin6->sin6_family = ssin6->sin6_family; - dsin6->sin6_addr = ssin6->sin6_addr; - dsin6->sin6_scope_id = ssin6->sin6_scope_id; -return true; -} -#else /* !(IS_ENABLED(CONFIG_IPV6) */ -static inline bool __rpc_cmp_addr6 (const struct sockaddr *sap1, -const struct sockaddr *sap2) -{ -return false; -} - -static inline bool __rpc_copy_addr6 (struct sockaddr *dst, -const struct sockaddr *src) -{ -return false; -} -#endif /* !(IS_ENABLED(CONFIG_IPV6) */ - -/** -* rpc_cmp_addr - compare the address portion of two sockaddrs. -* @sap1: first sockaddr -* @sap2: second sockaddr -* -* Just compares the family and address portion. Ignores port, but -* compares the scope if it's a link-local address. -* -* Returns true if the addrs are equal, false if they aren't. -*/ static inline bool rpc_cmp_addr (const struct sockaddr *sap1,const struct sockaddr *sap2) { -if (sap1->sa_family == sap2->sa_family) { -switch (sap1->sa_family) { -case AF_INET : -return __rpc_cmp_addr4 (sap1, sap2); -case AF_INET6 : -return __rpc_cmp_addr6 (sap1, sap2); - } - } -return false; +return inet_addr_equal ((const union inet_addr *)sap1, + (const union inet_addr *)sap2); } -/** -* rpc_copy_addr - copy the address portion of one sockaddr to another -* @dst: destination sockaddr -* @src: source sockaddr -* -* Just copies the address portion and family. Ignores port, scope, etc. -* Caller is responsible for making certain that dst is large enough to hold -* the address in src. Returns true if address family is supported. Returns -* false otherwise. -*/ static inline bool rpc_copy_addr (struct sockaddr *dst,const struct sockaddr *src) { -switch (src->sa_family) { -case AF_INET : -return __rpc_copy_addr4 (dst, src); -case AF_INET6 : -return __rpc_copy_addr6 (dst, src); - } -return false; +return inet_addr_copy ((union inet_addr *)dst, + (const union inet_addr *)src); }/**
include/net/inet_addr.h +57 -17
92 lines not on this page · raw message
net/core/utils.c +25 -0
@@ -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);
Signature · 1 line
1.7.7.6
A message that is not in the archive (sent off-list or not yet received): 1374476713-8838-5-git-send-email-amwang-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Re: [Patch net-next 4/7] sunrpc: use generic union inet_addr
Quoted 4 lines · 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_addrtoo.
Happy to see that moved into common code....
Quoted 26 lines
Cc Trond Myklebust <[email protected]>Cc "J. Bruce Fields" <[email protected]>Signed-off-by Cong Wang <[email protected]>--- include/linux/sunrpc/addr.h | 118 +++---------------------------------------- include/net/inet_addr.h | 74 +++++++++++++++++++++------ net/core/utils.c | 25 +++++++++ 3 files changed, 89 insertions(+), 128 deletions(-)include/linux/sunrpc/addr.h +1
-0@@ -11,6 +11,7 @@#include <linux/in.h> #include <linux/in6.h> #include <net/ipv6.h> +#include <net/inet_addr.h> size_t rpc_ntop (const struct sockaddr *,char *,const size_t ); size_t rpc_pton(struct net *, const char *, const size_t,@@ -21,135 +22,30 @@ size_t rpc_uaddr2sockaddr(struct net *, const char *, const size_t,static inline unsigned short rpc_get_port (const struct sockaddr *sap)
include/linux/sunrpc/addr.h size_t rpc_uaddr2sockaddr(struct net *, const char *, const size_t, · line 26
Quoted 10 lines
include/linux/sunrpc/addr.h +1
-7{ -switch (sap->sa_family) { -case AF_INET : -return ntohs (((struct sockaddr_in *)sap)->sin_port); -case AF_INET6 : -return ntohs (((struct sockaddr_in6 *)sap)->sin6_port); - } -return 0 ; +return inet_addr_get_port ((const union inet_addr *)sap); }
Is there any reason to keep the rpc_get_port wrapper at all after this? Or if its still useful to have the convenience of not having to do the cast, maybe the wrapper should move to common code to? (Is there some reason only the rpc code needs this?)
--b.
Quoted 264 lines
include/linux/sunrpc/addr.h +5
-104static inline void rpc_set_port (struct sockaddr *sap,const unsigned short port) { -switch (sap->sa_family) { -case AF_INET : - ((struct sockaddr_in *)sap)->sin_port =htons (port); -break ; -case AF_INET6 : - ((struct sockaddr_in6 *)sap)->sin6_port =htons (port); -break ; - } +inet_addr_set_port ((union inet_addr *)sap, port); }#define IPV6_SCOPE_DELIMITER '%'#define IPV6_SCOPE_ID_LEN sizeof("%nnnnnnnnnn") -static inline bool __rpc_cmp_addr4 (const struct sockaddr *sap1, -const struct sockaddr *sap2) -{ -const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sap1; -const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sap2; - -return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr; -} - -static inline bool __rpc_copy_addr4 (struct sockaddr *dst, -const struct sockaddr *src) -{ -const struct sockaddr_in *ssin = (struct sockaddr_in *) src; -struct sockaddr_in *dsin = (struct sockaddr_in *) dst; - - dsin->sin_family = ssin->sin_family; - dsin->sin_addr.s_addr = ssin->sin_addr.s_addr; -return true; -} - -#if IS_ENABLED (CONFIG_IPV6 ) -static inline bool __rpc_cmp_addr6 (const struct sockaddr *sap1, -const struct sockaddr *sap2) -{ -const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sap1; -const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sap2; - -if (!ipv6_addr_equal (&sin1->sin6_addr, &sin2->sin6_addr)) -return false; -else if (ipv6_addr_type (&sin1->sin6_addr) &IPV6_ADDR_LINKLOCAL ) -return sin1->sin6_scope_id == sin2->sin6_scope_id; - -return true; -} - -static inline bool __rpc_copy_addr6 (struct sockaddr *dst, -const struct sockaddr *src) -{ -const struct sockaddr_in6 *ssin6 = (const struct sockaddr_in6 *) src; -struct sockaddr_in6 *dsin6 = (struct sockaddr_in6 *) dst; - - dsin6->sin6_family = ssin6->sin6_family; - dsin6->sin6_addr = ssin6->sin6_addr; - dsin6->sin6_scope_id = ssin6->sin6_scope_id; -return true; -} -#else /* !(IS_ENABLED(CONFIG_IPV6) */ -static inline bool __rpc_cmp_addr6 (const struct sockaddr *sap1, -const struct sockaddr *sap2) -{ -return false; -} - -static inline bool __rpc_copy_addr6 (struct sockaddr *dst, -const struct sockaddr *src) -{ -return false; -} -#endif /* !(IS_ENABLED(CONFIG_IPV6) */ - -/** -* rpc_cmp_addr - compare the address portion of two sockaddrs. -* @sap1: first sockaddr -* @sap2: second sockaddr -* -* Just compares the family and address portion. Ignores port, but -* compares the scope if it's a link-local address. -* -* Returns true if the addrs are equal, false if they aren't. -*/ static inline bool rpc_cmp_addr (const struct sockaddr *sap1,const struct sockaddr *sap2) { -if (sap1->sa_family == sap2->sa_family) { -switch (sap1->sa_family) { -case AF_INET : -return __rpc_cmp_addr4 (sap1, sap2); -case AF_INET6 : -return __rpc_cmp_addr6 (sap1, sap2); - } - } -return false; +return inet_addr_equal ((const union inet_addr *)sap1, + (const union inet_addr *)sap2); } -/** -* rpc_copy_addr - copy the address portion of one sockaddr to another -* @dst: destination sockaddr -* @src: source sockaddr -* -* Just copies the address portion and family. Ignores port, scope, etc. -* Caller is responsible for making certain that dst is large enough to hold -* the address in src. Returns true if address family is supported. Returns -* false otherwise. -*/ static inline bool rpc_copy_addr (struct sockaddr *dst,const struct sockaddr *src) { -switch (src->sa_family) { -case AF_INET : -return __rpc_copy_addr4 (dst, src); -case AF_INET6 : -return __rpc_copy_addr6 (dst, src); - } -return false; +return inet_addr_copy ((union inet_addr *)dst, + (const union inet_addr *)src); }/** include/net/inet_addr.h +57
-17@@ -14,17 +14,6 @@ union inet_addr { };#if IS_ENABLED (CONFIG_IPV6 ) -static inline -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_INET6 ) -return ipv6_addr_equal (&a->sin6.sin6_addr, &b->sin6.sin6_addr); -else -return a->sin.sin_addr.s_addr == b->sin.sin_addr.s_addr; -} -static inline bool inet_addr_any (const union inet_addr *ipa) {if (ipa->sa.sa_family ==AF_INET6 )@@ -43,12 +32,6 @@ static inline bool inet_addr_multicast(const union inet_addr *ipa)#else /* !CONFIG_IPV6 */ -static inline -bool inet_addr_equal (const union inet_addr *a,const union inet_addr *b) -{ -return a->sin.sin_addr.s_addr == b->sin.sin_addr.s_addr; -} -static inline bool inet_addr_any (const union inet_addr *ipa) {return ipa->sin.sin_addr.s_addr ==htonl (INADDR_ANY );@@ -60,6 +43,63 @@ static inline bool inet_addr_multicast(const union inet_addr *ipa) }#endif +/** +* inet_addr_copy - copy the address portion of one inet_addr to another +* @dst: destination sockaddr +* @src: source sockaddr +* +* Just copies the address portion and family. Ignores port, scope, etc. +* Caller is responsible for making certain that dst is large enough to hold +* the address in src. Returns true if address family is supported. Returns +* false otherwise. +*/ +static inline bool inet_addr_copy (union inet_addr *dst, +const union inet_addr *src) +{ + dst->sa.sa_family = src->sa.sa_family; + +switch (src->sa.sa_family) { +case AF_INET : + dst->sin.sin_addr.s_addr = src->sin.sin_addr.s_addr; +return true; +#if IS_ENABLED (CONFIG_IPV6 ) +case AF_INET6 : + dst->sin6.sin6_addr = src->sin6.sin6_addr; + dst->sin6.sin6_scope_id = src->sin6.sin6_scope_id; +return true; +#endif + } + +return false; +} + +static inline +unsigned short inet_addr_get_port (const union inet_addr *sap) +{ +switch (sap->sa.sa_family) { +case AF_INET : +return ntohs (sap->sin.sin_port); +case AF_INET6 : +return ntohs (sap->sin6.sin6_port); + } +return 0 ; +} + +static inline +void inet_addr_set_port (union inet_addr *sap, +const unsigned short port) +{ +switch (sap->sa.sa_family) { +case AF_INET : + sap->sin.sin_port =htons (port); +break ; +case AF_INET6 : + sap->sin6.sin6_port =htons (port); +break ; + } +} + +extern bool inet_addr_equal (const union inet_addr *a,const union inet_addr *b);extern int simple_inet_pton (const char *str,union inet_addr *addr);#endif net/core/utils.c +25
-0@@ -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);Signature · 1 line
1.7.7.6
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [Patch net-next 4/7] sunrpc: use generic union inet_addr
Quoted 18 lines · J. Bruce Fields
include/linux/sunrpc/addr.h size_t rpc_uaddr2sockaddr(struct net *, const char *, const size_t, · line 26
Quoted 11 lines · Cong Wang
static inline unsigned short
rpc_get_port(const struct sockaddr *sap){include/linux/sunrpc/addr.h +1
-7-switch (sap->sa_family) { -case AF_INET : -return ntohs (((struct sockaddr_in *)sap)->sin_port); -case AF_INET6 : -return ntohs (((struct sockaddr_in6 *)sap)->sin6_port); - } -return 0 ; +return inet_addr_get_port ((const union inet_addr *)sap); }Is there any reason to keep the
rpc_get_portwrapper at all after this? Or if its still useful to have the convenience of not having to do the cast, maybe the wrapper should move to common code to? (Is there some reason only the rpc code needs this?)
Yeah, the only reason why I keep it is that I don't want to touch all the callers of rpc_get_port(). I agree that we can make it a generic function.
Thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [Patch net-next 4/7] sunrpc: use generic union inet_addr
Quoted 20 lines · Cong Wang
Quoted 18 lines · J. Bruce Fields
include/linux/sunrpc/addr.h size_t rpc_uaddr2sockaddr(struct net *, const char *, const size_t, · line 26
Quoted 11 lines · Cong Wang
static inline unsigned short
rpc_get_port(const struct sockaddr *sap){include/linux/sunrpc/addr.h +1
-7-switch (sap->sa_family) { -case AF_INET : -return ntohs (((struct sockaddr_in *)sap)->sin_port); -case AF_INET6 : -return ntohs (((struct sockaddr_in6 *)sap)->sin6_port); - } -return 0 ; +return inet_addr_get_port ((const union inet_addr *)sap); }Is there any reason to keep the
rpc_get_portwrapper at all after this? Or if its still useful to have the convenience of not having to do the cast, maybe the wrapper should move to common code to? (Is there some reason only the rpc code needs this?)
Quoted 2 lines
Yeah, the only reason why I keep it is that I don't want to touch all the callers of
rpc_get_port().
Makes sense, thanks.
--b.
Quoted 5 lines
I agree that we can make it a generic
function.Thanks.
PATCH 5/7 fs: use generic union inet_addr and help functions
In reply to Cong WangFrom: Cong Wang <[email protected]>
nfs and cifs define some helper functions for sockaddr, they can use the generic functions for union inet_addr too.
Since some dlm code needs to compare ->sin_port, introduce a generic function inet_addr_equal_strict() for it.
--- fs/cifs/connect.c | 39 ++++-------------- fs/dlm/lowcomms.c | 24 ++--------- fs/nfs/client.c | 94 ++----------------------------------------- fs/nfs/nfs4filelayoutdev.c | 37 ++--------------- fs/nfs/super.c | 31 +------------- include/net/inet_addr.h | 1 + net/core/utils.c | 23 +++++++++++ 7 files changed, 50 insertions(+), 199 deletions(-)
fs/cifs/connect.c +9 -30
@@ -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"
@@ -1899,17 +1900,10 @@ 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 inet_addr_equal ((union inet_addr *)srcaddr, + (union inet_addr *)rhs);default :WARN_ON (1 );return false;/* don't expect to be here */
@@ -1956,27 +1950,12 @@ 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 (!inet_addr_equal ((union inet_addr *)addr, + (union inet_addr *)&server->dstaddr))return false;break ; - }default :WARN_ON (1 );return false;/* don't expect to be here */
fs/dlm/lowcomms.c +5 -19
@@ -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 +5 -89
118 lines not on this page · raw message
fs/nfs/nfs4filelayoutdev.c +4 -33
@@ -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
@@ -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 +1 -0
@@ -100,6 +100,7 @@ void inet_addr_set_port(union inet_addr *sap, }extern bool inet_addr_equal (const union inet_addr *a,const union inet_addr *b); +extern bool inet_addr_equal_strict (const union inet_addr *a,const union inet_addr *b);extern int simple_inet_pton (const char *str,union inet_addr *addr);#endif
net/core/utils.c +23 -0
@@ -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
PATCH 6/7 sctp: use generic union inet_addr
In reply to Cong WangFrom: 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.
--- 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
@@ -590,22 +590,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
@@ -250,11 +250,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
@@ -493,7 +493,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.
@@ -623,7 +623,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) {
@@ -635,7 +635,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);
@@ -767,7 +767,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;
@@ -786,7 +786,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;
@@ -983,8 +983,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;
@@ -1075,13 +1075,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)
@@ -1557,11 +1557,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
@@ -305,11 +305,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)))
@@ -325,7 +325,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 ;
@@ -344,7 +344,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);
@@ -370,7 +370,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;
@@ -386,7 +386,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
@@ -63,7 +63,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);
@@ -1321,7 +1321,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
@@ -130,7 +130,7 @@ static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_commostruct 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 ) {
@@ -155,7 +155,7 @@ static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_commoif (primary && af->cmp_addr (addr, primary)) {seq_printf (seq,"*" ); } - af->seq_dump_addr (seq, addr); +seq_printf (seq,"%pIA " , &addr); }rcu_read_unlock (); }
@@ -164,7 +164,7 @@ static void sctp_seq_dump_local_addrs(struct seq_file *seq, struct sctp_ep_commostatic 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;
@@ -179,7 +179,7 @@ static void sctp_seq_dump_remote_addrs(struct seq_file *seq, struct sctp_associaif (af->cmp_addr (addr, primary)) {seq_printf (seq,"*" ); } - af->seq_dump_addr (seq, addr); +seq_printf (seq,"%pIA " , addr); }rcu_read_unlock (); }
@@ -468,7 +468,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
@@ -1130,7 +1130,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;
@@ -1156,17 +1156,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 ; }
@@ -1199,7 +1190,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) {
@@ -1209,7 +1200,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.
@@ -1249,7 +1240,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;
@@ -6047,7 +6038,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
@@ -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
@@ -61,13 +61,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 ;
@@ -111,7 +111,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;
@@ -273,7 +273,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;
@@ -281,7 +281,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
@@ -350,7 +350,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
PATCH 7/7 selinux: use generic union inet_addr
In reply to Cong WangFrom: 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 | 16 +----- security/lsm_audit.c | 16 +++--- security/selinux/hooks.c | 73 ++++++++++---------------- security/selinux/include/netnode.h | 4 +- security/selinux/include/objsec.h | 7 +-- security/selinux/netnode.c | 102 +++++++++++------------------------- 6 files changed, 74 insertions(+), 144 deletions(-)
include/linux/lsm_audit.h +3 -13
@@ -21,6 +21,7 @@#include <linux/path.h> #include <linux/key.h> #include <linux/skbuff.h> +#include <net/inet_addr.h> struct lsm_network_audit {int netif;
@@ -28,16 +29,8 @@ struct lsm_network_audit {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 +76,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 +8 -8
@@ -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;
@@ -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 */
@@ -335,18 +335,18 @@ static void dump_common_audit_data(struct audit_buffer *ab,switch (a->u.net->family) {case AF_INET : -print_ipv4_addr (ab, a->u.net->v4info.saddr, +print_ipv4_addr (ab, a->u.net->saddr.sin.sin_addr.s_addr, a->u.net->sport,"saddr" ,"src" ); -print_ipv4_addr (ab, a->u.net->v4info.daddr, +print_ipv4_addr (ab, a->u.net->daddr.sin.sin_addr.s_addr, a->u.net->dport,"daddr" ,"dest" );break ;case AF_INET6 : -print_ipv6_addr (ab, &a->u.net->v6info.saddr, +print_ipv6_addr (ab, &a->u.net->saddr.sin6.sin6_addr, a->u.net->sport,"saddr" ,"src" ); -print_ipv6_addr (ab, &a->u.net->v6info.daddr, +print_ipv6_addr (ab, &a->u.net->daddr.sin6.sin6_addr, a->u.net->dport,"daddr" ,"dest" );break ;
security/selinux/hooks.c +28 -45
214 lines not on this page · raw message
security/selinux/include/netnode.h +3 -1
@@ -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
@@ -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
Signature · 1 line
1.7.7.6
Re: [Patch net-next 7/7] selinux: use generic union inet_addr
Quoted 32 lines · Cong Wang
include/linux/lsm_audit.h +3
-10@@ -21,6 +21,7 @@#include <linux/path.h> #include <linux/key.h> #include <linux/skbuff.h> +#include <net/inet_addr.h> struct lsm_network_audit {int netif;@@ -28,16 +29,8 @@ struct lsm_network_audit {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. */
include/linux/lsm_audit.h struct common_audit_data { · line 87
Quoted 5 lines
include/linux/lsm_audit.h +0
-2@@ -83,9 +76,6 @@ struct common_audit_data { };/* per LSM data pointer union */ }; -#define v4info fam.v4 -#define v6info fam.v6
These changes are going to affect Smack as well. You either need to respin this patch to include all of the LSMs (Smack should be the only other affected LSM) or add a new patch to the patchset.
Signature · 2 lines
paul moore security and virtualization @ redhat
Re: [Patch net-next 7/7] selinux: use generic union inet_addr
Quoted 5 lines · Paul Moore
These changes are going to affect Smack as well. You either need to respin this patch to include all of the LSMs (Smack should be the only other affected LSM) or add a new patch to the patchset.
Yeah, I will include the Smack part as well.
Thanks!
Quoted 10 lines · Cong Wang
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_addras a union of IPv4 and IPv6 address, and some helper functions that will be used by existing code and in the future VXLAN module.
I think this patchset is overly complicated.
I see no reason why vsprint's support for
"struct sockaddr *" %pIS should be removed.
%pIS and %pIA can both exist.
Quoted 7 lines · Joe Perches
I see no reason why vsprint's support for
"struct sockaddr *" %pIS should be removed.%pIS and %pIA can both exist.
Because there is no need to keep both of them, struct sockaddr can be safely converted to union inet_addr.
Quoted 9 lines · Cong Wang
Quoted 5 lines · Joe Perches
I see no reason why vsprint's support for
"struct sockaddr *" %pIS should be removed.%pIS and %pIA can both exist.
Because there is no need to keep both of them, struct sockaddr can be safely converted to union
inet_addr.
That's a bit fragile.
The cost of keeping %pIS is pretty low.
Also, if there is ever a check for %p<type>,
then using:
struct sockaddr *foo = bar; ... snprintf(buf, len, "%pIA", foo)
would need foo to be cast first to union inet_addr *
snprintf(buf, len, "%pIA", (union inet_addr *)foo);
Quoted 6 lines · Joe Perches
Quoted 5 lines · Cong Wang
Quoted 4 lines · Joe Perches
I see no reason why vsprint's support for
"struct sockaddr *" %pIS should be removed.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
%pIS and %pIA can both exist.
Because there is no need to keep both of them, struct sockaddr can be safely converted to union
inet_addr.That's a bit fragile.
The cost of keeping %pIS is pretty low.
I knew, but again, there is no need at all.
Quoted 4 lines
Also, if there is ever a check for %p<type>,
then using:
Quoted 9 lines
struct sockaddr *foo = bar; ... snprintf(buf, len, "%pIA", foo)would need foo to be cast first to union
inet_addr*snprintf(buf, len, "%pIA", (union inet_addr *)foo);
You don't have to, compiler doesn't check the new specifier, and it is safe even without any casting.
What's more, the existing %pIS user (sctp) is already converted to union inet_addr, see patch 6/7.
David Miller
maintainerFrom: Cong Wang <[email protected]>
Date: Mon, 22 Jul 2013 15:05:06 +0800
Quoted 7 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.
Quoted 8 lines
This patchset introduce a new type union
inet_addras a union of IPv4 and IPv6 address, and 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_addrto unioninet_addr.Signed-off-by Cong Wang <[email protected]>
I'm sorry I really don't like these changes at all.
You're creating bloat in places that don't need a full sockaddr_in{,6}.
There is a reason some of these pieces of code used custom types, to minimize the overhead.
I'm not applying these patches, sorry.
Quoted 5 lines · David Miller
You're creating bloat in places that don't need a full sockaddr_in{,6}.
There is a reason some of these pieces of code used custom types, to minimize the overhead.
Do you mean the inetpeer part? I can drop it if you think it harms performance. Actually it only increases the struct by 8 bytes, if I do calculation correctly.
Thanks.