Skip to content

Commit 4cdadcb

Browse files
ebiedermdavem330
authored andcommitted
sctp: Make the endpoint hashtable handle multiple network namespaces
- Use struct net in the hash calculation - Use sock_net(endpoint.base.sk) in the endpoint lookups. - On receive calculate the network namespace from skb->dev. Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com> Acked-by: Vlad Yasevich <vyasevich@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f1f4376 commit 4cdadcb

4 files changed

Lines changed: 18 additions & 11 deletions

File tree

‎include/net/sctp/sctp.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,9 +638,9 @@ static inline int sctp_phashfn(struct net *net, __u16 lport)
638638
}
639639

640640
/* This is the hash function for the endpoint hash table. */
641-
static inline int sctp_ep_hashfn(__u16 lport)
641+
static inline int sctp_ep_hashfn(struct net *net, __u16 lport)
642642
{
643-
return lport & (sctp_ep_hashsize - 1);
643+
return (net_hash_mix(net) + lport) & (sctp_ep_hashsize - 1);
644644
}
645645

646646
/* This is the hash function for the association hash table. */

‎include/net/sctp/structs.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,7 @@ struct sctp_association *sctp_endpoint_lookup_assoc(
14261426
int sctp_endpoint_is_peeled_off(struct sctp_endpoint *,
14271427
const union sctp_addr *);
14281428
struct sctp_endpoint *sctp_endpoint_is_match(struct sctp_endpoint *,
1429-
const union sctp_addr *);
1429+
struct net *, const union sctp_addr *);
14301430
int sctp_has_association(const union sctp_addr *laddr,
14311431
const union sctp_addr *paddr);
14321432

‎net/sctp/endpointola.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,13 @@ void sctp_endpoint_put(struct sctp_endpoint *ep)
302302

303303
/* Is this the endpoint we are looking for? */
304304
struct sctp_endpoint *sctp_endpoint_is_match(struct sctp_endpoint *ep,
305+
struct net *net,
305306
const union sctp_addr *laddr)
306307
{
307308
struct sctp_endpoint *retval = NULL;
308309

309-
if (htons(ep->base.bind_addr.port) == laddr->v4.sin_port) {
310+
if ((htons(ep->base.bind_addr.port) == laddr->v4.sin_port) &&
311+
net_eq(sock_net(ep->base.sk), net)) {
310312
if (sctp_bind_addr_match(&ep->base.bind_addr, laddr,
311313
sctp_sk(ep->base.sk)))
312314
retval = ep;

‎net/sctp/input.c‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ static struct sctp_association *__sctp_rcv_lookup(struct sk_buff *skb,
7070
const union sctp_addr *laddr,
7171
const union sctp_addr *paddr,
7272
struct sctp_transport **transportp);
73-
static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(const union sctp_addr *laddr);
73+
static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(struct net *net,
74+
const union sctp_addr *laddr);
7475
static struct sctp_association *__sctp_lookup_association(
7576
const union sctp_addr *local,
7677
const union sctp_addr *peer,
@@ -129,6 +130,7 @@ int sctp_rcv(struct sk_buff *skb)
129130
union sctp_addr dest;
130131
int family;
131132
struct sctp_af *af;
133+
struct net *net = dev_net(skb->dev);
132134

133135
if (skb->pkt_type!=PACKET_HOST)
134136
goto discard_it;
@@ -181,7 +183,7 @@ int sctp_rcv(struct sk_buff *skb)
181183
asoc = __sctp_rcv_lookup(skb, &src, &dest, &transport);
182184

183185
if (!asoc)
184-
ep = __sctp_rcv_lookup_endpoint(&dest);
186+
ep = __sctp_rcv_lookup_endpoint(net, &dest);
185187

186188
/* Retrieve the common input handling substructure. */
187189
rcvr = asoc ? &asoc->base : &ep->base;
@@ -723,12 +725,13 @@ static int sctp_rcv_ootb(struct sk_buff *skb)
723725
/* Insert endpoint into the hash table. */
724726
static void __sctp_hash_endpoint(struct sctp_endpoint *ep)
725727
{
728+
struct net *net = sock_net(ep->base.sk);
726729
struct sctp_ep_common *epb;
727730
struct sctp_hashbucket *head;
728731

729732
epb = &ep->base;
730733

731-
epb->hashent = sctp_ep_hashfn(epb->bind_addr.port);
734+
epb->hashent = sctp_ep_hashfn(net, epb->bind_addr.port);
732735
head = &sctp_ep_hashtable[epb->hashent];
733736

734737
sctp_write_lock(&head->lock);
@@ -747,12 +750,13 @@ void sctp_hash_endpoint(struct sctp_endpoint *ep)
747750
/* Remove endpoint from the hash table. */
748751
static void __sctp_unhash_endpoint(struct sctp_endpoint *ep)
749752
{
753+
struct net *net = sock_net(ep->base.sk);
750754
struct sctp_hashbucket *head;
751755
struct sctp_ep_common *epb;
752756

753757
epb = &ep->base;
754758

755-
epb->hashent = sctp_ep_hashfn(epb->bind_addr.port);
759+
epb->hashent = sctp_ep_hashfn(net, epb->bind_addr.port);
756760

757761
head = &sctp_ep_hashtable[epb->hashent];
758762

@@ -770,20 +774,21 @@ void sctp_unhash_endpoint(struct sctp_endpoint *ep)
770774
}
771775

772776
/* Look up an endpoint. */
773-
static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(const union sctp_addr *laddr)
777+
static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(struct net *net,
778+
const union sctp_addr *laddr)
774779
{
775780
struct sctp_hashbucket *head;
776781
struct sctp_ep_common *epb;
777782
struct sctp_endpoint *ep;
778783
struct hlist_node *node;
779784
int hash;
780785

781-
hash = sctp_ep_hashfn(ntohs(laddr->v4.sin_port));
786+
hash = sctp_ep_hashfn(net, ntohs(laddr->v4.sin_port));
782787
head = &sctp_ep_hashtable[hash];
783788
read_lock(&head->lock);
784789
sctp_for_each_hentry(epb, node, &head->chain) {
785790
ep = sctp_ep(epb);
786-
if (sctp_endpoint_is_match(ep, laddr))
791+
if (sctp_endpoint_is_match(ep, net, laddr))
787792
goto hit;
788793
}
789794

0 commit comments

Comments
 (0)