Commit 50a3499a authored by Jon Maloy's avatar Jon Maloy Committed by David S. Miller

tipc: simplify signature of tipc_namtbl_publish()

Using the new address structure tipc_uaddr, we simplify the signature
of function tipc_sk_publish() and tipc_namtbl_publish() so that fewer
parameters need to be passed around.
Signed-off-by: default avatarJon Maloy <jmaloy@redhat.com>
Acked-by: default avatarYing Xue <ying.xue@windriver.com>
Acked-by: default avatarHoang Le <hoang.h.le@dektech.com.au>
Acked-by: default avatarTung Nguyen <tung.q.nguyen@dektech.com.au>
Acked-by: default avatarXin Long <lucien.xin@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7823f04f
...@@ -740,9 +740,8 @@ void tipc_nametbl_build_group(struct net *net, struct tipc_group *grp, ...@@ -740,9 +740,8 @@ void tipc_nametbl_build_group(struct net *net, struct tipc_group *grp,
/* tipc_nametbl_publish - add service binding to name table /* tipc_nametbl_publish - add service binding to name table
*/ */
struct publication *tipc_nametbl_publish(struct net *net, u32 type, u32 lower, struct publication *tipc_nametbl_publish(struct net *net, struct tipc_uaddr *ua,
u32 upper, u32 scope, u32 port, struct tipc_socket_addr *sk, u32 key)
u32 key)
{ {
struct name_table *nt = tipc_name_table(net); struct name_table *nt = tipc_name_table(net);
struct tipc_net *tn = tipc_net(net); struct tipc_net *tn = tipc_net(net);
...@@ -757,8 +756,9 @@ struct publication *tipc_nametbl_publish(struct net *net, u32 type, u32 lower, ...@@ -757,8 +756,9 @@ struct publication *tipc_nametbl_publish(struct net *net, u32 type, u32 lower,
goto exit; goto exit;
} }
p = tipc_nametbl_insert_publ(net, type, lower, upper, scope, p = tipc_nametbl_insert_publ(net, ua->sr.type, ua->sr.lower,
tipc_own_addr(net), port, key); ua->sr.upper, ua->scope,
sk->node, sk->ref, key);
if (p) { if (p) {
nt->local_publ_count++; nt->local_publ_count++;
skb = tipc_named_publish(net, p); skb = tipc_named_publish(net, p);
......
...@@ -42,6 +42,7 @@ struct tipc_subscription; ...@@ -42,6 +42,7 @@ struct tipc_subscription;
struct tipc_plist; struct tipc_plist;
struct tipc_nlist; struct tipc_nlist;
struct tipc_group; struct tipc_group;
struct tipc_uaddr;
/* /*
* TIPC name types reserved for internal TIPC use (both current and planned) * TIPC name types reserved for internal TIPC use (both current and planned)
...@@ -120,9 +121,8 @@ void tipc_nametbl_lookup_dst_nodes(struct net *net, u32 type, u32 lower, ...@@ -120,9 +121,8 @@ void tipc_nametbl_lookup_dst_nodes(struct net *net, u32 type, u32 lower,
bool tipc_nametbl_lookup(struct net *net, u32 type, u32 instance, u32 domain, bool tipc_nametbl_lookup(struct net *net, u32 type, u32 instance, u32 domain,
struct list_head *dsts, int *dstcnt, u32 exclude, struct list_head *dsts, int *dstcnt, u32 exclude,
bool all); bool all);
struct publication *tipc_nametbl_publish(struct net *net, u32 type, u32 lower, struct publication *tipc_nametbl_publish(struct net *net, struct tipc_uaddr *ua,
u32 upper, u32 scope, u32 port, struct tipc_socket_addr *sk, u32 key);
u32 key);
int tipc_nametbl_withdraw(struct net *net, u32 type, u32 lower, u32 upper, int tipc_nametbl_withdraw(struct net *net, u32 type, u32 lower, u32 upper,
u32 key); u32 key);
struct publication *tipc_nametbl_insert_publ(struct net *net, u32 type, struct publication *tipc_nametbl_insert_publ(struct net *net, u32 type,
......
...@@ -125,6 +125,11 @@ int tipc_net_init(struct net *net, u8 *node_id, u32 addr) ...@@ -125,6 +125,11 @@ int tipc_net_init(struct net *net, u8 *node_id, u32 addr)
static void tipc_net_finalize(struct net *net, u32 addr) static void tipc_net_finalize(struct net *net, u32 addr)
{ {
struct tipc_net *tn = tipc_net(net); struct tipc_net *tn = tipc_net(net);
struct tipc_socket_addr sk = {0, addr};
struct tipc_uaddr ua;
tipc_uaddr(&ua, TIPC_SERVICE_RANGE, TIPC_CLUSTER_SCOPE,
TIPC_NODE_STATE, addr, addr);
if (cmpxchg(&tn->node_addr, 0, addr)) if (cmpxchg(&tn->node_addr, 0, addr))
return; return;
...@@ -132,8 +137,7 @@ static void tipc_net_finalize(struct net *net, u32 addr) ...@@ -132,8 +137,7 @@ static void tipc_net_finalize(struct net *net, u32 addr)
tipc_named_reinit(net); tipc_named_reinit(net);
tipc_sk_reinit(net); tipc_sk_reinit(net);
tipc_mon_reinit_self(net); tipc_mon_reinit_self(net);
tipc_nametbl_publish(net, TIPC_NODE_STATE, addr, addr, tipc_nametbl_publish(net, &ua, &sk, addr);
TIPC_CLUSTER_SCOPE, 0, addr);
} }
void tipc_net_finalize_work(struct work_struct *work) void tipc_net_finalize_work(struct work_struct *work)
......
...@@ -398,21 +398,23 @@ static void tipc_node_write_unlock_fast(struct tipc_node *n) ...@@ -398,21 +398,23 @@ static void tipc_node_write_unlock_fast(struct tipc_node *n)
static void tipc_node_write_unlock(struct tipc_node *n) static void tipc_node_write_unlock(struct tipc_node *n)
__releases(n->lock) __releases(n->lock)
{ {
struct tipc_socket_addr sk;
struct net *net = n->net; struct net *net = n->net;
u32 addr = 0;
u32 flags = n->action_flags; u32 flags = n->action_flags;
u32 link_id = 0;
u32 bearer_id;
struct list_head *publ_list; struct list_head *publ_list;
struct tipc_uaddr ua;
u32 bearer_id;
if (likely(!flags)) { if (likely(!flags)) {
write_unlock_bh(&n->lock); write_unlock_bh(&n->lock);
return; return;
} }
addr = n->addr; tipc_uaddr(&ua, TIPC_SERVICE_RANGE, TIPC_NODE_SCOPE,
link_id = n->link_id; TIPC_LINK_STATE, n->addr, n->addr);
bearer_id = link_id & 0xffff; sk.ref = n->link_id;
sk.node = n->addr;
bearer_id = n->link_id & 0xffff;
publ_list = &n->publ_list; publ_list = &n->publ_list;
n->action_flags &= ~(TIPC_NOTIFY_NODE_DOWN | TIPC_NOTIFY_NODE_UP | n->action_flags &= ~(TIPC_NOTIFY_NODE_DOWN | TIPC_NOTIFY_NODE_UP |
...@@ -421,20 +423,19 @@ static void tipc_node_write_unlock(struct tipc_node *n) ...@@ -421,20 +423,19 @@ static void tipc_node_write_unlock(struct tipc_node *n)
write_unlock_bh(&n->lock); write_unlock_bh(&n->lock);
if (flags & TIPC_NOTIFY_NODE_DOWN) if (flags & TIPC_NOTIFY_NODE_DOWN)
tipc_publ_notify(net, publ_list, addr, n->capabilities); tipc_publ_notify(net, publ_list, n->addr, n->capabilities);
if (flags & TIPC_NOTIFY_NODE_UP) if (flags & TIPC_NOTIFY_NODE_UP)
tipc_named_node_up(net, addr, n->capabilities); tipc_named_node_up(net, n->addr, n->capabilities);
if (flags & TIPC_NOTIFY_LINK_UP) { if (flags & TIPC_NOTIFY_LINK_UP) {
tipc_mon_peer_up(net, addr, bearer_id); tipc_mon_peer_up(net, n->addr, bearer_id);
tipc_nametbl_publish(net, TIPC_LINK_STATE, addr, addr, tipc_nametbl_publish(net, &ua, &sk, n->link_id);
TIPC_NODE_SCOPE, link_id, link_id);
} }
if (flags & TIPC_NOTIFY_LINK_DOWN) { if (flags & TIPC_NOTIFY_LINK_DOWN) {
tipc_mon_peer_down(net, addr, bearer_id); tipc_mon_peer_down(net, n->addr, bearer_id);
tipc_nametbl_withdraw(net, TIPC_LINK_STATE, addr, tipc_nametbl_withdraw(net, TIPC_LINK_STATE, n->addr,
addr, link_id); n->addr, n->link_id);
} }
} }
......
...@@ -111,7 +111,6 @@ struct tipc_sock { ...@@ -111,7 +111,6 @@ struct tipc_sock {
struct sock sk; struct sock sk;
u32 conn_type; u32 conn_type;
u32 conn_instance; u32 conn_instance;
int published;
u32 max_pkt; u32 max_pkt;
u32 maxnagle; u32 maxnagle;
u32 portid; u32 portid;
...@@ -141,6 +140,7 @@ struct tipc_sock { ...@@ -141,6 +140,7 @@ struct tipc_sock {
bool expect_ack; bool expect_ack;
bool nodelay; bool nodelay;
bool group_is_open; bool group_is_open;
bool published;
}; };
static int tipc_sk_backlog_rcv(struct sock *sk, struct sk_buff *skb); static int tipc_sk_backlog_rcv(struct sock *sk, struct sk_buff *skb);
...@@ -151,8 +151,7 @@ static int tipc_release(struct socket *sock); ...@@ -151,8 +151,7 @@ static int tipc_release(struct socket *sock);
static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags, static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags,
bool kern); bool kern);
static void tipc_sk_timeout(struct timer_list *t); static void tipc_sk_timeout(struct timer_list *t);
static int tipc_sk_publish(struct tipc_sock *tsk, uint scope, static int tipc_sk_publish(struct tipc_sock *tsk, struct tipc_uaddr *ua);
struct tipc_service_range const *seq);
static int tipc_sk_withdraw(struct tipc_sock *tsk, uint scope, static int tipc_sk_withdraw(struct tipc_sock *tsk, uint scope,
struct tipc_service_range const *seq); struct tipc_service_range const *seq);
static int tipc_sk_leave(struct tipc_sock *tsk); static int tipc_sk_leave(struct tipc_sock *tsk);
...@@ -677,22 +676,31 @@ static int tipc_release(struct socket *sock) ...@@ -677,22 +676,31 @@ static int tipc_release(struct socket *sock)
*/ */
static int __tipc_bind(struct socket *sock, struct sockaddr *skaddr, int alen) static int __tipc_bind(struct socket *sock, struct sockaddr *skaddr, int alen)
{ {
struct sockaddr_tipc *addr = (struct sockaddr_tipc *)skaddr; struct tipc_uaddr *ua = (struct tipc_uaddr *)skaddr;
struct tipc_sock *tsk = tipc_sk(sock->sk); struct tipc_sock *tsk = tipc_sk(sock->sk);
bool unbind = false;
if (unlikely(!alen)) if (unlikely(!alen))
return tipc_sk_withdraw(tsk, 0, NULL); return tipc_sk_withdraw(tsk, 0, NULL);
if (addr->addrtype == TIPC_SERVICE_ADDR) if (ua->addrtype == TIPC_SERVICE_ADDR) {
addr->addr.nameseq.upper = addr->addr.nameseq.lower; ua->addrtype = TIPC_SERVICE_RANGE;
ua->sr.upper = ua->sr.lower;
}
if (ua->scope < 0) {
unbind = true;
ua->scope = -ua->scope;
}
/* Users may still use deprecated TIPC_ZONE_SCOPE */
if (ua->scope != TIPC_NODE_SCOPE)
ua->scope = TIPC_CLUSTER_SCOPE;
if (tsk->group) if (tsk->group)
return -EACCES; return -EACCES;
if (addr->scope >= 0) if (unbind)
return tipc_sk_publish(tsk, addr->scope, &addr->addr.nameseq); return tipc_sk_withdraw(tsk, ua->scope, &ua->sr);
else return tipc_sk_publish(tsk, ua);
return tipc_sk_withdraw(tsk, -addr->scope, &addr->addr.nameseq);
} }
int tipc_sk_bind(struct socket *sock, struct sockaddr *skaddr, int alen) int tipc_sk_bind(struct socket *sock, struct sockaddr *skaddr, int alen)
...@@ -707,18 +715,17 @@ int tipc_sk_bind(struct socket *sock, struct sockaddr *skaddr, int alen) ...@@ -707,18 +715,17 @@ int tipc_sk_bind(struct socket *sock, struct sockaddr *skaddr, int alen)
static int tipc_bind(struct socket *sock, struct sockaddr *skaddr, int alen) static int tipc_bind(struct socket *sock, struct sockaddr *skaddr, int alen)
{ {
struct sockaddr_tipc *addr = (struct sockaddr_tipc *)skaddr; struct tipc_uaddr *ua = (struct tipc_uaddr *)skaddr;
u32 atype = ua->addrtype;
if (alen) { if (alen) {
if (alen < sizeof(struct sockaddr_tipc)) if (!tipc_uaddr_valid(ua, alen))
return -EINVAL; return -EINVAL;
if (addr->family != AF_TIPC) if (atype == TIPC_SOCKET_ADDR)
return -EAFNOSUPPORT; return -EAFNOSUPPORT;
if (addr->addrtype > TIPC_SERVICE_ADDR) if (ua->sr.type < TIPC_RESERVED_TYPES) {
return -EAFNOSUPPORT;
if (addr->addr.nameseq.type < TIPC_RESERVED_TYPES) {
pr_warn_once("Can't bind to reserved service type %u\n", pr_warn_once("Can't bind to reserved service type %u\n",
addr->addr.nameseq.type); ua->sr.type);
return -EACCES; return -EACCES;
} }
} }
...@@ -2891,31 +2898,28 @@ static void tipc_sk_timeout(struct timer_list *t) ...@@ -2891,31 +2898,28 @@ static void tipc_sk_timeout(struct timer_list *t)
sock_put(sk); sock_put(sk);
} }
static int tipc_sk_publish(struct tipc_sock *tsk, uint scope, static int tipc_sk_publish(struct tipc_sock *tsk, struct tipc_uaddr *ua)
struct tipc_service_range const *seq)
{ {
struct sock *sk = &tsk->sk; struct sock *sk = &tsk->sk;
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
struct publication *publ; struct tipc_socket_addr skaddr;
struct publication *p;
u32 key; u32 key;
if (scope != TIPC_NODE_SCOPE)
scope = TIPC_CLUSTER_SCOPE;
if (tipc_sk_connected(sk)) if (tipc_sk_connected(sk))
return -EINVAL; return -EINVAL;
key = tsk->portid + tsk->pub_count + 1; key = tsk->portid + tsk->pub_count + 1;
if (key == tsk->portid) if (key == tsk->portid)
return -EADDRINUSE; return -EADDRINUSE;
skaddr.ref = tsk->portid;
publ = tipc_nametbl_publish(net, seq->type, seq->lower, seq->upper, skaddr.node = tipc_own_addr(net);
scope, tsk->portid, key); p = tipc_nametbl_publish(net, ua, &skaddr, key);
if (unlikely(!publ)) if (unlikely(!p))
return -EINVAL; return -EINVAL;
list_add(&publ->binding_sock, &tsk->publications); list_add(&p->binding_sock, &tsk->publications);
tsk->pub_count++; tsk->pub_count++;
tsk->published = 1; tsk->published = true;
return 0; return 0;
} }
...@@ -3067,13 +3071,15 @@ static int tipc_sk_join(struct tipc_sock *tsk, struct tipc_group_req *mreq) ...@@ -3067,13 +3071,15 @@ static int tipc_sk_join(struct tipc_sock *tsk, struct tipc_group_req *mreq)
struct net *net = sock_net(&tsk->sk); struct net *net = sock_net(&tsk->sk);
struct tipc_group *grp = tsk->group; struct tipc_group *grp = tsk->group;
struct tipc_msg *hdr = &tsk->phdr; struct tipc_msg *hdr = &tsk->phdr;
struct tipc_service_range seq; struct tipc_uaddr ua;
int rc; int rc;
if (mreq->type < TIPC_RESERVED_TYPES) if (mreq->type < TIPC_RESERVED_TYPES)
return -EACCES; return -EACCES;
if (mreq->scope > TIPC_NODE_SCOPE) if (mreq->scope > TIPC_NODE_SCOPE)
return -EINVAL; return -EINVAL;
if (mreq->scope != TIPC_NODE_SCOPE)
mreq->scope = TIPC_CLUSTER_SCOPE;
if (grp) if (grp)
return -EACCES; return -EACCES;
grp = tipc_group_create(net, tsk->portid, mreq, &tsk->group_is_open); grp = tipc_group_create(net, tsk->portid, mreq, &tsk->group_is_open);
...@@ -3083,11 +3089,10 @@ static int tipc_sk_join(struct tipc_sock *tsk, struct tipc_group_req *mreq) ...@@ -3083,11 +3089,10 @@ static int tipc_sk_join(struct tipc_sock *tsk, struct tipc_group_req *mreq)
msg_set_lookup_scope(hdr, mreq->scope); msg_set_lookup_scope(hdr, mreq->scope);
msg_set_nametype(hdr, mreq->type); msg_set_nametype(hdr, mreq->type);
msg_set_dest_droppable(hdr, true); msg_set_dest_droppable(hdr, true);
seq.type = mreq->type;
seq.lower = mreq->instance;
seq.upper = seq.lower;
tipc_nametbl_build_group(net, grp, mreq->type, mreq->scope); tipc_nametbl_build_group(net, grp, mreq->type, mreq->scope);
rc = tipc_sk_publish(tsk, mreq->scope, &seq); tipc_uaddr(&ua, TIPC_SERVICE_RANGE, mreq->scope,
mreq->type, mreq->instance, mreq->instance);
rc = tipc_sk_publish(tsk, &ua);
if (rc) { if (rc) {
tipc_group_delete(net, grp); tipc_group_delete(net, grp);
tsk->group = NULL; tsk->group = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment