Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e7696d

Browse files
lxindavem330
authored andcommitted
sctp: get netns from asoc and ep base
Commit 3124346 ("sctp: cache netns in sctp_ep_common") set netns in asoc and ep base since they're created, and it will never change. It's a better way to get netns from asoc and ep base, comparing to calling sock_net(). This patch is to replace them. v1->v2: - no change. Suggested-by: Marcelo Ricardo Leitner <[email protected]> Signed-off-by: Xin Long <[email protected]> Acked-by: Neil Horman <[email protected]> Acked-by: Marcelo Ricardo Leitner <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 26c97a2 commit 4e7696d

14 files changed

+49
-62
lines changed

net/sctp/associola.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,6 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
584584
const gfp_t gfp,
585585
const int peer_state)
586586
{
587-
struct net *net = sock_net(asoc->base.sk);
588587
struct sctp_transport *peer;
589588
struct sctp_sock *sp;
590589
unsigned short port;
@@ -614,7 +613,7 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
614613
return peer;
615614
}
616615

617-
peer = sctp_transport_new(net, addr, gfp);
616+
peer = sctp_transport_new(asoc->base.net, addr, gfp);
618617
if (!peer)
619618
return NULL;
620619

@@ -974,7 +973,7 @@ static void sctp_assoc_bh_rcv(struct work_struct *work)
974973
struct sctp_association *asoc =
975974
container_of(work, struct sctp_association,
976975
base.inqueue.immediate);
977-
struct net *net = sock_net(asoc->base.sk);
976+
struct net *net = asoc->base.net;
978977
union sctp_subtype subtype;
979978
struct sctp_endpoint *ep;
980979
struct sctp_chunk *chunk;
@@ -1442,7 +1441,8 @@ void sctp_assoc_sync_pmtu(struct sctp_association *asoc)
14421441
/* Should we send a SACK to update our peer? */
14431442
static inline bool sctp_peer_needs_update(struct sctp_association *asoc)
14441443
{
1445-
struct net *net = sock_net(asoc->base.sk);
1444+
struct net *net = asoc->base.net;
1445+
14461446
switch (asoc->state) {
14471447
case SCTP_STATE_ESTABLISHED:
14481448
case SCTP_STATE_SHUTDOWN_PENDING:
@@ -1576,7 +1576,7 @@ int sctp_assoc_set_bind_addr_from_ep(struct sctp_association *asoc,
15761576
if (asoc->peer.ipv6_address)
15771577
flags |= SCTP_ADDR6_PEERSUPP;
15781578

1579-
return sctp_bind_addr_copy(sock_net(asoc->base.sk),
1579+
return sctp_bind_addr_copy(asoc->base.net,
15801580
&asoc->base.bind_addr,
15811581
&asoc->ep->base.bind_addr,
15821582
scope, gfp, flags);

net/sctp/chunk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
225225
if (msg_len >= first_len) {
226226
msg->can_delay = 0;
227227
if (msg_len > first_len)
228-
SCTP_INC_STATS(sock_net(asoc->base.sk),
228+
SCTP_INC_STATS(asoc->base.net,
229229
SCTP_MIB_FRAGUSRMSGS);
230230
} else {
231231
/* Which may be the only one... */

net/sctp/endpointola.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ struct sctp_endpoint *sctp_endpoint_is_match(struct sctp_endpoint *ep,
244244
struct sctp_endpoint *retval = NULL;
245245

246246
if ((htons(ep->base.bind_addr.port) == laddr->v4.sin_port) &&
247-
net_eq(sock_net(ep->base.sk), net)) {
247+
net_eq(ep->base.net, net)) {
248248
if (sctp_bind_addr_match(&ep->base.bind_addr, laddr,
249249
sctp_sk(ep->base.sk)))
250250
retval = ep;
@@ -292,8 +292,8 @@ bool sctp_endpoint_is_peeled_off(struct sctp_endpoint *ep,
292292
const union sctp_addr *paddr)
293293
{
294294
struct sctp_sockaddr_entry *addr;
295+
struct net *net = ep->base.net;
295296
struct sctp_bind_addr *bp;
296-
struct net *net = sock_net(ep->base.sk);
297297

298298
bp = &ep->base.bind_addr;
299299
/* This function is called with the socket lock held,
@@ -384,7 +384,7 @@ static void sctp_endpoint_bh_rcv(struct work_struct *work)
384384
if (asoc && sctp_chunk_is_data(chunk))
385385
asoc->peer.last_data_from = chunk->transport;
386386
else {
387-
SCTP_INC_STATS(sock_net(ep->base.sk), SCTP_MIB_INCTRLCHUNKS);
387+
SCTP_INC_STATS(ep->base.net, SCTP_MIB_INCTRLCHUNKS);
388388
if (asoc)
389389
asoc->stats.ictrlchunks++;
390390
}

net/sctp/input.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ int sctp_hash_transport(struct sctp_transport *t)
937937
if (t->asoc->temp)
938938
return 0;
939939

940-
arg.net = sock_net(t->asoc->base.sk);
940+
arg.net = t->asoc->base.net;
941941
arg.paddr = &t->ipaddr;
942942
arg.lport = htons(t->asoc->base.bind_addr.port);
943943

@@ -1004,12 +1004,11 @@ struct sctp_transport *sctp_epaddr_lookup_transport(
10041004
const struct sctp_endpoint *ep,
10051005
const union sctp_addr *paddr)
10061006
{
1007-
struct net *net = sock_net(ep->base.sk);
10081007
struct rhlist_head *tmp, *list;
10091008
struct sctp_transport *t;
10101009
struct sctp_hash_cmp_arg arg = {
10111010
.paddr = paddr,
1012-
.net = net,
1011+
.net = ep->base.net,
10131012
.lport = htons(ep->base.bind_addr.port),
10141013
};
10151014

net/sctp/output.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static enum sctp_xmit sctp_packet_bundle_sack(struct sctp_packet *pkt,
282282
sctp_chunk_free(sack);
283283
goto out;
284284
}
285-
SCTP_INC_STATS(sock_net(asoc->base.sk),
285+
SCTP_INC_STATS(asoc->base.net,
286286
SCTP_MIB_OUTCTRLCHUNKS);
287287
asoc->stats.octrlchunks++;
288288
asoc->peer.sack_needed = 0;

net/sctp/outqueue.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ void sctp_outq_free(struct sctp_outq *q)
279279
/* Put a new chunk in an sctp_outq. */
280280
void sctp_outq_tail(struct sctp_outq *q, struct sctp_chunk *chunk, gfp_t gfp)
281281
{
282-
struct net *net = sock_net(q->asoc->base.sk);
282+
struct net *net = q->asoc->base.net;
283283

284284
pr_debug("%s: outq:%p, chunk:%p[%s]\n", __func__, q, chunk,
285285
chunk && chunk->chunk_hdr ?
@@ -533,7 +533,7 @@ void sctp_retransmit_mark(struct sctp_outq *q,
533533
void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport,
534534
enum sctp_retransmit_reason reason)
535535
{
536-
struct net *net = sock_net(q->asoc->base.sk);
536+
struct net *net = q->asoc->base.net;
537537

538538
switch (reason) {
539539
case SCTP_RTXR_T3_RTX:
@@ -1884,6 +1884,6 @@ void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 ctsn)
18841884

18851885
if (ftsn_chunk) {
18861886
list_add_tail(&ftsn_chunk->list, &q->control_chunk_list);
1887-
SCTP_INC_STATS(sock_net(asoc->base.sk), SCTP_MIB_OUTCTRLCHUNKS);
1887+
SCTP_INC_STATS(asoc->base.net, SCTP_MIB_OUTCTRLCHUNKS);
18881888
}
18891889
}

net/sctp/sm_make_chunk.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,7 +2307,6 @@ int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk,
23072307
const union sctp_addr *peer_addr,
23082308
struct sctp_init_chunk *peer_init, gfp_t gfp)
23092309
{
2310-
struct net *net = sock_net(asoc->base.sk);
23112310
struct sctp_transport *transport;
23122311
struct list_head *pos, *temp;
23132312
union sctp_params param;
@@ -2363,8 +2362,8 @@ int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk,
23632362
* also give us an option to silently ignore the packet, which
23642363
* is what we'll do here.
23652364
*/
2366-
if (!net->sctp.addip_noauth &&
2367-
(asoc->peer.asconf_capable && !asoc->peer.auth_capable)) {
2365+
if (!asoc->base.net->sctp.addip_noauth &&
2366+
(asoc->peer.asconf_capable && !asoc->peer.auth_capable)) {
23682367
asoc->peer.addip_disabled_mask |= (SCTP_PARAM_ADD_IP |
23692368
SCTP_PARAM_DEL_IP |
23702369
SCTP_PARAM_SET_PRIMARY);
@@ -2491,9 +2490,9 @@ static int sctp_process_param(struct sctp_association *asoc,
24912490
const union sctp_addr *peer_addr,
24922491
gfp_t gfp)
24932492
{
2494-
struct net *net = sock_net(asoc->base.sk);
24952493
struct sctp_endpoint *ep = asoc->ep;
24962494
union sctp_addr_param *addr_param;
2495+
struct net *net = asoc->base.net;
24972496
struct sctp_transport *t;
24982497
enum sctp_scope scope;
24992498
union sctp_addr addr;

net/sctp/sm_sideeffect.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,6 @@ static void sctp_do_8_2_transport_strike(struct sctp_cmd_seq *commands,
516516
struct sctp_transport *transport,
517517
int is_hb)
518518
{
519-
struct net *net = sock_net(asoc->base.sk);
520-
521519
/* The check for association's overall error counter exceeding the
522520
* threshold is done in the state function.
523521
*/
@@ -544,10 +542,10 @@ static void sctp_do_8_2_transport_strike(struct sctp_cmd_seq *commands,
544542
* is SCTP_ACTIVE, then mark this transport as Partially Failed,
545543
* see SCTP Quick Failover Draft, section 5.1
546544
*/
547-
if (net->sctp.pf_enable &&
548-
(transport->state == SCTP_ACTIVE) &&
549-
(transport->error_count < transport->pathmaxrxt) &&
550-
(transport->error_count > transport->pf_retrans)) {
545+
if (asoc->base.net->sctp.pf_enable &&
546+
transport->state == SCTP_ACTIVE &&
547+
transport->error_count < transport->pathmaxrxt &&
548+
transport->error_count > transport->pf_retrans) {
551549

552550
sctp_assoc_control_transport(asoc, transport,
553551
SCTP_TRANSPORT_PF,
@@ -798,10 +796,8 @@ static int sctp_cmd_process_sack(struct sctp_cmd_seq *cmds,
798796
int err = 0;
799797

800798
if (sctp_outq_sack(&asoc->outqueue, chunk)) {
801-
struct net *net = sock_net(asoc->base.sk);
802-
803799
/* There are no more TSNs awaiting SACK. */
804-
err = sctp_do_sm(net, SCTP_EVENT_T_OTHER,
800+
err = sctp_do_sm(asoc->base.net, SCTP_EVENT_T_OTHER,
805801
SCTP_ST_OTHER(SCTP_EVENT_NO_PENDING_TSN),
806802
asoc->state, asoc->ep, asoc, NULL,
807803
GFP_ATOMIC);
@@ -834,7 +830,7 @@ static void sctp_cmd_assoc_update(struct sctp_cmd_seq *cmds,
834830
struct sctp_association *asoc,
835831
struct sctp_association *new)
836832
{
837-
struct net *net = sock_net(asoc->base.sk);
833+
struct net *net = asoc->base.net;
838834
struct sctp_chunk *abort;
839835

840836
if (!sctp_assoc_update(asoc, new))

net/sctp/sm_statefuns.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,7 @@ static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc,
13201320
struct sctp_chunk *init,
13211321
struct sctp_cmd_seq *commands)
13221322
{
1323-
struct net *net = sock_net(new_asoc->base.sk);
1323+
struct net *net = new_asoc->base.net;
13241324
struct sctp_transport *new_addr;
13251325
int ret = 1;
13261326

net/sctp/socket.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,7 @@ static int sctp_do_bind(struct sock *sk, union sctp_addr *addr, int len)
436436
static int sctp_send_asconf(struct sctp_association *asoc,
437437
struct sctp_chunk *chunk)
438438
{
439-
struct net *net = sock_net(asoc->base.sk);
440-
int retval = 0;
439+
int retval = 0;
441440

442441
/* If there is an outstanding ASCONF chunk, queue it for later
443442
* transmission.
@@ -449,7 +448,7 @@ static int sctp_send_asconf(struct sctp_association *asoc,
449448

450449
/* Hold the chunk until an ASCONF_ACK is received. */
451450
sctp_chunk_hold(chunk);
452-
retval = sctp_primitive_ASCONF(net, asoc, chunk);
451+
retval = sctp_primitive_ASCONF(asoc->base.net, asoc, chunk);
453452
if (retval)
454453
sctp_chunk_free(chunk);
455454
else
@@ -2428,9 +2427,8 @@ static int sctp_apply_peer_addr_params(struct sctp_paddrparams *params,
24282427
int error;
24292428

24302429
if (params->spp_flags & SPP_HB_DEMAND && trans) {
2431-
struct net *net = sock_net(trans->asoc->base.sk);
2432-
2433-
error = sctp_primitive_REQUESTHEARTBEAT(net, trans->asoc, trans);
2430+
error = sctp_primitive_REQUESTHEARTBEAT(trans->asoc->base.net,
2431+
trans->asoc, trans);
24342432
if (error)
24352433
return error;
24362434
}
@@ -5364,7 +5362,7 @@ struct sctp_transport *sctp_transport_get_next(struct net *net,
53645362
if (!sctp_transport_hold(t))
53655363
continue;
53665364

5367-
if (net_eq(sock_net(t->asoc->base.sk), net) &&
5365+
if (net_eq(t->asoc->base.net, net) &&
53685366
t->asoc->peer.primary_path == t)
53695367
break;
53705368

0 commit comments

Comments
 (0)