tipc: some minor improvements
Subsystems (3)
[email protected]
maintainerv2 cover tipc: some minor improvements
From: Jon Maloy <[email protected]>
We add some improvements that will be useful in future commits.
---
v2: fixed sparse warning in patch #2
Jon Maloy (3):
tipc: refactor tipc_sk_bind() function
tipc: make node number calculation reproducible
tipc: update address terminology in code
net/tipc/addr.c | 7 ++- net/tipc/addr.h | 1 + net/tipc/core.h | 12 +++++ net/tipc/group.c | 3 +- net/tipc/group.h | 3 +- net/tipc/name_table.c | 11 +++-- net/tipc/net.c | 2 +- net/tipc/socket.c | 110 ++++++++++++++++++++---------------------- net/tipc/subscr.c | 5 +- net/tipc/subscr.h | 5 +- net/tipc/topsrv.c | 4 +- 11 files changed, 87 insertions(+), 76 deletions(-)
Signature · 1 line
2.25.4
[email protected]
maintainerPATCH v2 1/3 tipc: refactor tipc_sk_bind() function
From: Jon Maloy <[email protected]>
We refactor the tipc_sk_bind() function, so that the lock handling is handled separately from the logics. We also move some sanity tests to earlier in the call chain, to the function tipc_bind().
--- net/tipc/socket.c | 66 +++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 36 deletions(-)
net/tipc/socket.c +30 -36
@@ -1,8 +1,9 @@/* * net/tipc/socket.c: TIPC socket API * -* Copyright (c) 2001-2007, 2012-2017, Ericsson AB +* Copyright (c) 2001-2007, 2012-2019, Ericsson AB * Copyright (c) 2004-2008, 2010-2013, Wind River Systems +* Copyright (c) 2020, Red Hat Inc * All rights reserved. * * Redistribution and use in source and binary forms, with or without
@@ -644,10 +645,10 @@ static int tipc_release(struct socket *sock) }/** -* tipc_bind - associate or disassocate TIPC name(s) with a socket +* __tipc_bind - associate or disassocate TIPC name(s) with a socket * @sock: socket structure -* @uaddr: socket address describing name(s) and desired operation -* @uaddr_len: size of socket address data structure +* @skaddr: socket address describing name(s) and desired operation +* @alen: size of socket address data structure * * Name and name sequence binding is indicated using a positive scope value; * a negative scope value unbinds the specified name. Specifying no name
@@ -658,44 +659,33 @@ static int tipc_release(struct socket *sock)* NOTE: This routine doesn't need to take the socket lock since it doesn't * access any non-constant socket information. */ - -int tipc_sk_bind (struct socket *sock,struct sockaddr *uaddr,int uaddr_len) +static int __tipc_bind (struct socket *sock,struct sockaddr *skaddr,int alen) { -struct sock *sk = sock->sk; -struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; -struct tipc_sock *tsk =tipc_sk (sk); -int res = -EINVAL ; +struct sockaddr_tipc *addr = (struct sockaddr_tipc *)skaddr; +struct tipc_sock *tsk =tipc_sk (sock->sk); -lock_sock (sk); -if (unlikely (!uaddr_len)) { - res =tipc_sk_withdraw (tsk,0 ,NULL ); - goto exit; - } -if (tsk->group) { - res = -EACCES ; - goto exit; - } -if (uaddr_len <sizeof (struct sockaddr_tipc )) { - res = -EINVAL ; - goto exit; - } -if (addr->family !=AF_TIPC ) { - res = -EAFNOSUPPORT ; - goto exit; - } +if (unlikely (!alen)) +return tipc_sk_withdraw (tsk,0 ,NULL );if (addr->addrtype ==TIPC_ADDR_NAME ) addr->addr.nameseq.upper = addr->addr.nameseq.lower; -else if (addr->addrtype !=TIPC_ADDR_NAMESEQ ) { - res = -EAFNOSUPPORT ; - goto exit; - } - res = (addr->scope >=0 ) ? -tipc_sk_publish (tsk, addr->scope, &addr->addr.nameseq) : -tipc_sk_withdraw (tsk, -addr->scope, &addr->addr.nameseq); -exit: -release_sock (sk); +if (tsk->group) +return -EACCES ; + +if (addr->scope >=0 ) +return tipc_sk_publish (tsk, addr->scope, &addr->addr.nameseq); +else +return tipc_sk_withdraw (tsk, -addr->scope, &addr->addr.nameseq); +} + +int tipc_sk_bind (struct socket *sock,struct sockaddr *skaddr,int alen) +{ +int res; + +lock_sock (sock->sk); + res =__tipc_bind (sock, skaddr, alen); +release_sock (sock->sk);return res; }
@@ -706,6 +696,10 @@ static int tipc_bind(struct socket *sock, struct sockaddr *skaddr, int alen)if (alen) {if (alen <sizeof (struct sockaddr_tipc ))return -EINVAL ; +if (addr->family !=AF_TIPC ) +return -EAFNOSUPPORT ; +if (addr->addrtype >TIPC_SERVICE_ADDR ) +return -EAFNOSUPPORT ;if (addr->addr.nameseq.type <TIPC_RESERVED_TYPES ) {pr_warn_once ("Can't bind to reserved service type %u\n" , addr->addr.nameseq.type);
Signature · 1 line
2.25.4
[email protected]
maintainerPATCH v2 2/3 tipc: make node number calculation reproducible
In reply to [email protected]From: Jon Maloy <[email protected]>
The 32-bit node number, aka node hash or node address, is calculated based on the 128-bit node identity when it is not set explicitly by the user. In future commits we will need to perform this hash operation on peer nodes while feeling safe that we obtain the same result.
We do this by interpreting the initial hash as a network byte order number. Whenever we need to use the number locally on a node we must therefore translate it to host byte order to obtain an architecure independent result.
Furthermore, given the context where we use this number, we must not allow it to be zero unless the node identity also is zero. Hence, in the rare cases when the xor-ed hash value may end up as zero we replace it with a fix number, knowing that the code anyway is capable of handling hash collisions.
---
v2: fixed sparse warning reported by kernel test robot <[email protected]>
--- net/tipc/addr.c | 7 +++---- net/tipc/addr.h | 1 + net/tipc/core.h | 12 ++++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-)
net/tipc/addr.c +3 -4
@@ -55,12 +55,11 @@ bool tipc_in_scope(bool legacy_format, u32 domain, u32 addr)void tipc_set_node_id (struct net *net,u8 *id) {struct tipc_net *tn =tipc_net (net); -u32 *tmp = (u32 *)id;memcpy (tn->node_id, id,NODE_ID_LEN );tipc_nodeid2string (tn->node_id_string, id); - tn->trial_addr = tmp[0 ] ^ tmp[1 ] ^ tmp[2 ] ^ tmp[3 ]; -pr_info ("Own node identity %s, cluster identity %u\n" , + tn->trial_addr =hash128to32 (id); +pr_info ("Node identity %s, cluster identity %u\n" ,tipc_own_id_string (net), tn->net_id); }
@@ -76,7 +75,7 @@ void tipc_set_node_addr(struct net *net, u32 addr) } tn->trial_addr = addr; tn->addr_trial_end = jiffies; -pr_info ("32-bit node address hash set to %x\n" , addr); +pr_info ("Node number set to %u\n" , addr); }char *tipc_nodeid2string (char *str,u8 *id)
net/tipc/addr.h +1 -0
@@ -3,6 +3,7 @@* * Copyright (c) 2000-2006, 2018, Ericsson AB * Copyright (c) 2004-2005, Wind River Systems +* Copyright (c) 2020, Red Hat Inc * All rights reserved. * * Redistribution and use in source and binary forms, with or without
net/tipc/core.h +12 -0
@@ -3,6 +3,7 @@* * Copyright (c) 2005-2006, 2013-2018 Ericsson AB * Copyright (c) 2005-2007, 2010-2013, Wind River Systems +* Copyright (c) 2020, Red Hat Inc * All rights reserved. * * Redistribution and use in source and binary forms, with or without
@@ -210,6 +211,17 @@ static inline u32 tipc_net_hash_mixes(struct net *net, int tn_rand)return net_hash_mix (&init_net) ^net_hash_mix (net) ^ tn_rand; } +static inline u32 hash128to32 (char *bytes) +{ +__be32 *tmp = (__be32 *)bytes; +u32 res; + + res =ntohl (tmp[0 ] ^ tmp[1 ] ^ tmp[2 ] ^ tmp[3 ]); +if (likely (res)) +return res; +return ntohl (tmp[0 ] | tmp[1 ] | tmp[2 ] | tmp[3 ]); +} +#ifdef CONFIG_SYSCTL int tipc_register_sysctl (void );void tipc_unregister_sysctl (void );
Signature · 1 line
2.25.4
[email protected]
maintainerPATCH v2 3/3 tipc: update address terminology in code
In reply to [email protected]From: Jon Maloy <[email protected]>
We update the terminology in the code so that deprecated structure names and macros are replaced with those currently recommended in the user API.
struct tipc_portid -> struct tipc_socket_addr
struct tipc_name -> struct tipc_service_addr
struct tipc_name_seq -> struct tipc_service_range
TIPC_ADDR_ID -> TIPC_SOCKET_ADDR TIPC_ADDR_NAME -> TIPC_SERVICE_ADDR TIPC_ADDR_NAMESEQ -> TIPC_SERVICE_RANGE TIPC_CFG_SRV -> TIPC_NODE_STATE
--- net/tipc/group.c | 3 ++- net/tipc/group.h | 3 ++- net/tipc/name_table.c | 11 ++++++----- net/tipc/net.c | 2 +- net/tipc/socket.c | 44 +++++++++++++++++++++---------------------- net/tipc/subscr.c | 5 +++-- net/tipc/subscr.h | 5 +++-- net/tipc/topsrv.c | 4 ++-- 8 files changed, 41 insertions(+), 36 deletions(-)
net/tipc/group.c +2 -1
@@ -2,6 +2,7 @@* net/tipc/group.c: TIPC group messaging code * * Copyright (c) 2017, Ericsson AB +* Copyright (c) 2020, Red Hat Inc * All rights reserved. * * Redistribution and use in source and binary forms, with or without
@@ -359,7 +360,7 @@ struct tipc_nlist *tipc_group_dests(struct tipc_group *grp)return &grp->dests; } -void tipc_group_self (struct tipc_group *grp,struct tipc_name_seq *seq, +void tipc_group_self (struct tipc_group *grp,struct tipc_service_range *seq,int *scope) { seq->type = grp->type;
net/tipc/group.h +2 -1
@@ -2,6 +2,7 @@* net/tipc/group.h: Include file for TIPC group unicast/multicast functions * * Copyright (c) 2017, Ericsson AB +* Copyright (c) 2020, Red Hat Inc * All rights reserved. * * Redistribution and use in source and binary forms, with or without
@@ -50,7 +51,7 @@ void tipc_group_delete(struct net *net, struct tipc_group *grp);void tipc_group_add_member (struct tipc_group *grp,u32 node,u32 port,u32 instance);struct tipc_nlist *tipc_group_dests (struct tipc_group *grp); -void tipc_group_self (struct tipc_group *grp,struct tipc_name_seq *seq, +void tipc_group_self (struct tipc_group *grp,struct tipc_service_range *seq,int *scope);u32 tipc_group_exclude (struct tipc_group *grp); void tipc_group_filter_msg(struct tipc_group *grp,
net/tipc/name_table.c +6 -5
@@ -3,6 +3,7 @@* * Copyright (c) 2000-2006, 2014-2018, Ericsson AB * Copyright (c) 2004-2008, 2010-2014, Wind River Systems +* Copyright (c) 2020, Red Hat Inc * All rights reserved. * * Redistribution and use in source and binary forms, with or without
@@ -403,12 +404,12 @@ static void tipc_service_subscribe(struct tipc_service *service,struct publication *p, *first, *tmp;struct list_head publ_list;struct service_range *sr; -struct tipc_name_seq ns; +struct tipc_service_range r;u32 filter; - ns.type =tipc_sub_read (sb, seq.type); - ns.lower =tipc_sub_read (sb, seq.lower); - ns.upper =tipc_sub_read (sb, seq.upper); + r.type =tipc_sub_read (sb, seq.type); + r.lower =tipc_sub_read (sb, seq.lower); + r.upper =tipc_sub_read (sb, seq.upper); filter =tipc_sub_read (sb, filter);tipc_sub_get (sub);
@@ -418,7 +419,7 @@ static void tipc_service_subscribe(struct tipc_service *service,return ;INIT_LIST_HEAD (&publ_list); - service_range_foreach_match(sr, service, ns.lower, ns.upper) { + service_range_foreach_match(sr, service, r.lower, r.upper) { first =NULL ;list_for_each_entry (p, &sr->all_publ, all_publ) {if (filter &TIPC_SUB_PORTS )
net/tipc/net.c +1 -1
@@ -132,7 +132,7 @@ static void tipc_net_finalize(struct net *net, u32 addr)tipc_named_reinit (net);tipc_sk_reinit (net);tipc_mon_reinit_self (net); -tipc_nametbl_publish (net,TIPC_CFG_SRV , addr, addr, +tipc_nametbl_publish (net,TIPC_NODE_STATE , addr, addr,TIPC_CLUSTER_SCOPE ,0 , addr); }
net/tipc/socket.c +22 -22
164 lines not on this page · raw message
net/tipc/subscr.c +3 -2
@@ -3,6 +3,7 @@* * Copyright (c) 2000-2017, Ericsson AB * Copyright (c) 2005-2007, 2010-2013, Wind River Systems +* Copyright (c) 2020, Red Hat Inc * All rights reserved. * * Redistribution and use in source and binary forms, with or without
@@ -60,7 +61,7 @@ static void tipc_sub_send_event(struct tipc_subscription *sub,* * Returns 1 if there is overlap, otherwise 0. */ -int tipc_sub_check_overlap (struct tipc_name_seq *seq,u32 found_lower, +int tipc_sub_check_overlap (struct tipc_service_range *seq,u32 found_lower,u32 found_upper) {if (found_lower < seq->lower)
@@ -79,7 +80,7 @@ void tipc_sub_report_overlap(struct tipc_subscription *sub, {struct tipc_subscr *s = &sub->evt.s;u32 filter =tipc_sub_read (s, filter); -struct tipc_name_seq seq; +struct tipc_service_range seq; seq.type =tipc_sub_read (s, seq.type); seq.lower =tipc_sub_read (s, seq.lower);
net/tipc/subscr.h +3 -2
@@ -3,6 +3,7 @@* * Copyright (c) 2003-2017, Ericsson AB * Copyright (c) 2005-2007, 2012-2013, Wind River Systems +* Copyright (c) 2020, Red Hat Inc * All rights reserved. * * Redistribution and use in source and binary forms, with or without
@@ -71,8 +72,8 @@ struct tipc_subscription *tipc_sub_subscribe(struct net *net, int conid);void tipc_sub_unsubscribe (struct tipc_subscription *sub); -int tipc_sub_check_overlap (struct tipc_name_seq *seq,u32 found_lower, -u32 found_upper); +int tipc_sub_check_overlap (struct tipc_service_range *seq, +u32 found_lower,u32 found_upper); void tipc_sub_report_overlap(struct tipc_subscription *sub, u32 found_lower, u32 found_upper, u32 event, u32 port, u32 node,
net/tipc/topsrv.c +2 -2
@@ -519,8 +519,8 @@ static int tipc_topsrv_create_listener(struct tipc_topsrv *srv) goto err; saddr.family =AF_TIPC ; - saddr.addrtype =TIPC_ADDR_NAMESEQ ; - saddr.addr.nameseq.type =TIPC_TOP_SRV ; + saddr.addrtype =TIPC_SERVICE_RANGE ; + saddr.addr.nameseq.type =TIPC_TOP_SRV ; saddr.addr.nameseq.lower =TIPC_TOP_SRV ; saddr.addr.nameseq.upper =TIPC_TOP_SRV ; saddr.scope =TIPC_NODE_SCOPE ;
Signature · 1 line
2.25.4
Quoted 3 lines · On Wed, 25 Nov 2020 13:29:12 -0500 [email protected] wrote:
From: Jon Maloy <[email protected]>
We add some improvements that will be useful in future commits.
Applied, thanks!