Skip to content

Commit 0fc87aa

Browse files
Jon Paul Maloydavem330
authored andcommitted
tipc: remove source file port.c
In this commit, we move the remaining functions in port.c to socket.c, and give them new names that correspond to their new location. We then remove the file port.c. There are only cosmetic changes to the moved functions. Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Reviewed-by: Erik Hugne <erik.hugne@ericsson.com> Reviewed-by: Ying Xue <ying.xue@windriver.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6c9808c commit 0fc87aa

3 files changed

Lines changed: 97 additions & 130 deletions

File tree

‎net/tipc/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ obj-$(CONFIG_TIPC) := tipc.o
77
tipc-y += addr.o bcast.o bearer.o config.o \
88
core.o link.o discover.o msg.o \
99
name_distr.o subscr.o name_table.o net.o \
10-
netlink.o node.o node_subscr.o port.o ref.o \
10+
netlink.o node.o node_subscr.o ref.o \
1111
socket.o log.o eth_media.o server.o
1212

1313
tipc-$(CONFIG_TIPC_MEDIA_IB) += ib_media.o

‎net/tipc/port.c‎

Lines changed: 0 additions & 123 deletions
This file was deleted.

‎net/tipc/socket.c‎

Lines changed: 96 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ static int tipc_release(struct socket *sock);
5757
static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags);
5858
static int tipc_wait_for_sndmsg(struct socket *sock, long *timeo_p);
5959
static void tipc_sk_timeout(unsigned long ref);
60+
static int tipc_sk_publish(struct tipc_port *port, uint scope,
61+
struct tipc_name_seq const *seq);
62+
static int tipc_sk_withdraw(struct tipc_port *port, uint scope,
63+
struct tipc_name_seq const *seq);
6064

6165
static const struct proto_ops packet_ops;
6266
static const struct proto_ops stream_ops;
@@ -138,6 +142,38 @@ static void reject_rx_queue(struct sock *sk)
138142
}
139143
}
140144

145+
/* tipc_sk_peer_msg - verify if message was sent by connected port's peer
146+
*
147+
* Handles cases where the node's network address has changed from
148+
* the default of <0.0.0> to its configured setting.
149+
*/
150+
static bool tipc_sk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg)
151+
{
152+
u32 peer_port = tipc_port_peerport(&tsk->port);
153+
u32 orig_node;
154+
u32 peer_node;
155+
156+
if (unlikely(!tsk->port.connected))
157+
return false;
158+
159+
if (unlikely(msg_origport(msg) != peer_port))
160+
return false;
161+
162+
orig_node = msg_orignode(msg);
163+
peer_node = tipc_port_peernode(&tsk->port);
164+
165+
if (likely(orig_node == peer_node))
166+
return true;
167+
168+
if (!orig_node && (peer_node == tipc_own_addr))
169+
return true;
170+
171+
if (!peer_node && (orig_node == tipc_own_addr))
172+
return true;
173+
174+
return false;
175+
}
176+
141177
/**
142178
* tipc_sk_create - create a TIPC socket
143179
* @net: network namespace (must be default network)
@@ -356,7 +392,7 @@ static int tipc_release(struct socket *sock)
356392
}
357393
}
358394

359-
tipc_withdraw(port, 0, NULL);
395+
tipc_sk_withdraw(port, 0, NULL);
360396
tipc_ref_discard(port->ref);
361397
k_cancel_timer(&port->timer);
362398
if (port->connected) {
@@ -407,7 +443,7 @@ static int tipc_bind(struct socket *sock, struct sockaddr *uaddr,
407443

408444
lock_sock(sk);
409445
if (unlikely(!uaddr_len)) {
410-
res = tipc_withdraw(&tsk->port, 0, NULL);
446+
res = tipc_sk_withdraw(&tsk->port, 0, NULL);
411447
goto exit;
412448
}
413449

@@ -435,8 +471,8 @@ static int tipc_bind(struct socket *sock, struct sockaddr *uaddr,
435471
}
436472

437473
res = (addr->scope > 0) ?
438-
tipc_publish(&tsk->port, addr->scope, &addr->addr.nameseq) :
439-
tipc_withdraw(&tsk->port, -addr->scope, &addr->addr.nameseq);
474+
tipc_sk_publish(&tsk->port, addr->scope, &addr->addr.nameseq) :
475+
tipc_sk_withdraw(&tsk->port, -addr->scope, &addr->addr.nameseq);
440476
exit:
441477
release_sock(sk);
442478
return res;
@@ -663,7 +699,7 @@ static int tipc_sk_proto_rcv(struct tipc_sock *tsk, u32 *dnode,
663699
int conn_cong;
664700

665701
/* Ignore if connection cannot be validated: */
666-
if (!port->connected || !tipc_port_peer_msg(port, msg))
702+
if (!tipc_sk_peer_msg(tsk, msg))
667703
goto exit;
668704

669705
port->probing_state = TIPC_CONN_OK;
@@ -1444,7 +1480,7 @@ static int filter_connect(struct tipc_sock *tsk, struct sk_buff **buf)
14441480
switch ((int)sock->state) {
14451481
case SS_CONNECTED:
14461482
/* Accept only connection-based messages sent by peer */
1447-
if (msg_connected(msg) && tipc_port_peer_msg(port, msg)) {
1483+
if (tipc_sk_peer_msg(tsk, msg)) {
14481484
if (unlikely(msg_errcode(msg))) {
14491485
sock->state = SS_DISCONNECTING;
14501486
port->connected = 0;
@@ -2027,6 +2063,60 @@ static void tipc_sk_timeout(unsigned long ref)
20272063
tipc_sk_put(tsk);
20282064
}
20292065

2066+
static int tipc_sk_publish(struct tipc_port *port, uint scope,
2067+
struct tipc_name_seq const *seq)
2068+
{
2069+
struct publication *publ;
2070+
u32 key;
2071+
2072+
if (port->connected)
2073+
return -EINVAL;
2074+
key = port->ref + port->pub_count + 1;
2075+
if (key == port->ref)
2076+
return -EADDRINUSE;
2077+
2078+
publ = tipc_nametbl_publish(seq->type, seq->lower, seq->upper,
2079+
scope, port->ref, key);
2080+
if (unlikely(!publ))
2081+
return -EINVAL;
2082+
2083+
list_add(&publ->pport_list, &port->publications);
2084+
port->pub_count++;
2085+
port->published = 1;
2086+
return 0;
2087+
}
2088+
2089+
static int tipc_sk_withdraw(struct tipc_port *port, uint scope,
2090+
struct tipc_name_seq const *seq)
2091+
{
2092+
struct publication *publ;
2093+
struct publication *safe;
2094+
int rc = -EINVAL;
2095+
2096+
list_for_each_entry_safe(publ, safe, &port->publications, pport_list) {
2097+
if (seq) {
2098+
if (publ->scope != scope)
2099+
continue;
2100+
if (publ->type != seq->type)
2101+
continue;
2102+
if (publ->lower != seq->lower)
2103+
continue;
2104+
if (publ->upper != seq->upper)
2105+
break;
2106+
tipc_nametbl_withdraw(publ->type, publ->lower,
2107+
publ->ref, publ->key);
2108+
rc = 0;
2109+
break;
2110+
}
2111+
tipc_nametbl_withdraw(publ->type, publ->lower,
2112+
publ->ref, publ->key);
2113+
rc = 0;
2114+
}
2115+
if (list_empty(&port->publications))
2116+
port->published = 0;
2117+
return rc;
2118+
}
2119+
20302120
static int tipc_sk_show(struct tipc_port *port, char *buf,
20312121
int len, int full_id)
20322122
{

0 commit comments

Comments
 (0)