@@ -141,31 +141,33 @@ static u32 ipv6_hashfn(const struct in6_addr *ip6)
141
141
}
142
142
143
143
/* Resolve a PDP context structure based on the 64bit TID. */
144
- static struct pdp_ctx * gtp0_pdp_find (struct gtp_dev * gtp , u64 tid )
144
+ static struct pdp_ctx * gtp0_pdp_find (struct gtp_dev * gtp , u64 tid , u16 family )
145
145
{
146
146
struct hlist_head * head ;
147
147
struct pdp_ctx * pdp ;
148
148
149
149
head = & gtp -> tid_hash [gtp0_hashfn (tid ) % gtp -> hash_size ];
150
150
151
151
hlist_for_each_entry_rcu (pdp , head , hlist_tid ) {
152
- if (pdp -> gtp_version == GTP_V0 &&
152
+ if (pdp -> af == family &&
153
+ pdp -> gtp_version == GTP_V0 &&
153
154
pdp -> u .v0 .tid == tid )
154
155
return pdp ;
155
156
}
156
157
return NULL ;
157
158
}
158
159
159
160
/* Resolve a PDP context structure based on the 32bit TEI. */
160
- static struct pdp_ctx * gtp1_pdp_find (struct gtp_dev * gtp , u32 tid )
161
+ static struct pdp_ctx * gtp1_pdp_find (struct gtp_dev * gtp , u32 tid , u16 family )
161
162
{
162
163
struct hlist_head * head ;
163
164
struct pdp_ctx * pdp ;
164
165
165
166
head = & gtp -> tid_hash [gtp1u_hashfn (tid ) % gtp -> hash_size ];
166
167
167
168
hlist_for_each_entry_rcu (pdp , head , hlist_tid ) {
168
- if (pdp -> gtp_version == GTP_V1 &&
169
+ if (pdp -> af == family &&
170
+ pdp -> gtp_version == GTP_V1 &&
169
171
pdp -> u .v1 .i_tei == tid )
170
172
return pdp ;
171
173
}
@@ -305,15 +307,8 @@ static int gtp_inner_proto(struct sk_buff *skb, unsigned int hdrlen,
305
307
}
306
308
307
309
static int gtp_rx (struct pdp_ctx * pctx , struct sk_buff * skb ,
308
- unsigned int hdrlen , unsigned int role )
310
+ unsigned int hdrlen , unsigned int role , __u16 inner_proto )
309
311
{
310
- __u16 inner_proto ;
311
-
312
- if (gtp_inner_proto (skb , hdrlen , & inner_proto ) < 0 ) {
313
- netdev_dbg (pctx -> dev , "GTP packet does not encapsulate an IP packet\n" );
314
- return -1 ;
315
- }
316
-
317
312
if (!gtp_check_ms (skb , pctx , hdrlen , role , inner_proto )) {
318
313
netdev_dbg (pctx -> dev , "No PDP ctx for this MS\n" );
319
314
return 1 ;
@@ -562,13 +557,29 @@ static int gtp0_handle_echo_resp(struct gtp_dev *gtp, struct sk_buff *skb)
562
557
msg , 0 , GTP_GENL_MCGRP , GFP_ATOMIC );
563
558
}
564
559
560
+ static int gtp_proto_to_family (__u16 proto )
561
+ {
562
+ switch (proto ) {
563
+ case ETH_P_IP :
564
+ return AF_INET ;
565
+ case ETH_P_IPV6 :
566
+ return AF_INET6 ;
567
+ default :
568
+ WARN_ON_ONCE (1 );
569
+ break ;
570
+ }
571
+
572
+ return AF_UNSPEC ;
573
+ }
574
+
565
575
/* 1 means pass up to the stack, -1 means drop and 0 means decapsulated. */
566
576
static int gtp0_udp_encap_recv (struct gtp_dev * gtp , struct sk_buff * skb )
567
577
{
568
578
unsigned int hdrlen = sizeof (struct udphdr ) +
569
579
sizeof (struct gtp0_header );
570
580
struct gtp0_header * gtp0 ;
571
581
struct pdp_ctx * pctx ;
582
+ __u16 inner_proto ;
572
583
573
584
if (!pskb_may_pull (skb , hdrlen ))
574
585
return -1 ;
@@ -591,13 +602,19 @@ static int gtp0_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb)
591
602
if (gtp0 -> type != GTP_TPDU )
592
603
return 1 ;
593
604
594
- pctx = gtp0_pdp_find (gtp , be64_to_cpu (gtp0 -> tid ));
605
+ if (gtp_inner_proto (skb , hdrlen , & inner_proto ) < 0 ) {
606
+ netdev_dbg (gtp -> dev , "GTP packet does not encapsulate an IP packet\n" );
607
+ return -1 ;
608
+ }
609
+
610
+ pctx = gtp0_pdp_find (gtp , be64_to_cpu (gtp0 -> tid ),
611
+ gtp_proto_to_family (inner_proto ));
595
612
if (!pctx ) {
596
613
netdev_dbg (gtp -> dev , "No PDP ctx to decap skb=%p\n" , skb );
597
614
return 1 ;
598
615
}
599
616
600
- return gtp_rx (pctx , skb , hdrlen , gtp -> role );
617
+ return gtp_rx (pctx , skb , hdrlen , gtp -> role , inner_proto );
601
618
}
602
619
603
620
/* msg_type has to be GTP_ECHO_REQ or GTP_ECHO_RSP */
@@ -768,6 +785,7 @@ static int gtp1u_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb)
768
785
sizeof (struct gtp1_header );
769
786
struct gtp1_header * gtp1 ;
770
787
struct pdp_ctx * pctx ;
788
+ __u16 inner_proto ;
771
789
772
790
if (!pskb_may_pull (skb , hdrlen ))
773
791
return -1 ;
@@ -803,9 +821,15 @@ static int gtp1u_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb)
803
821
if (!pskb_may_pull (skb , hdrlen ))
804
822
return -1 ;
805
823
824
+ if (gtp_inner_proto (skb , hdrlen , & inner_proto ) < 0 ) {
825
+ netdev_dbg (gtp -> dev , "GTP packet does not encapsulate an IP packet\n" );
826
+ return -1 ;
827
+ }
828
+
806
829
gtp1 = (struct gtp1_header * )(skb -> data + sizeof (struct udphdr ));
807
830
808
- pctx = gtp1_pdp_find (gtp , ntohl (gtp1 -> tid ));
831
+ pctx = gtp1_pdp_find (gtp , ntohl (gtp1 -> tid ),
832
+ gtp_proto_to_family (inner_proto ));
809
833
if (!pctx ) {
810
834
netdev_dbg (gtp -> dev , "No PDP ctx to decap skb=%p\n" , skb );
811
835
return 1 ;
@@ -815,7 +839,7 @@ static int gtp1u_udp_encap_recv(struct gtp_dev *gtp, struct sk_buff *skb)
815
839
gtp_parse_exthdrs (skb , & hdrlen ) < 0 )
816
840
return -1 ;
817
841
818
- return gtp_rx (pctx , skb , hdrlen , gtp -> role );
842
+ return gtp_rx (pctx , skb , hdrlen , gtp -> role , inner_proto );
819
843
}
820
844
821
845
static void __gtp_encap_destroy (struct sock * sk )
@@ -1843,10 +1867,12 @@ static struct pdp_ctx *gtp_pdp_add(struct gtp_dev *gtp, struct sock *sk,
1843
1867
found = true;
1844
1868
if (version == GTP_V0 )
1845
1869
pctx_tid = gtp0_pdp_find (gtp ,
1846
- nla_get_u64 (info -> attrs [GTPA_TID ]));
1870
+ nla_get_u64 (info -> attrs [GTPA_TID ]),
1871
+ family );
1847
1872
else if (version == GTP_V1 )
1848
1873
pctx_tid = gtp1_pdp_find (gtp ,
1849
- nla_get_u32 (info -> attrs [GTPA_I_TEI ]));
1874
+ nla_get_u32 (info -> attrs [GTPA_I_TEI ]),
1875
+ family );
1850
1876
if (pctx_tid )
1851
1877
found = true;
1852
1878
@@ -2034,6 +2060,12 @@ static struct pdp_ctx *gtp_find_pdp_by_link(struct net *net,
2034
2060
struct nlattr * nla [])
2035
2061
{
2036
2062
struct gtp_dev * gtp ;
2063
+ int family ;
2064
+
2065
+ if (nla [GTPA_FAMILY ])
2066
+ family = nla_get_u8 (nla [GTPA_FAMILY ]);
2067
+ else
2068
+ family = AF_INET ;
2037
2069
2038
2070
gtp = gtp_find_dev (net , nla );
2039
2071
if (!gtp )
@@ -2042,10 +2074,16 @@ static struct pdp_ctx *gtp_find_pdp_by_link(struct net *net,
2042
2074
if (nla [GTPA_MS_ADDRESS ]) {
2043
2075
__be32 ip = nla_get_be32 (nla [GTPA_MS_ADDRESS ]);
2044
2076
2077
+ if (family != AF_INET )
2078
+ return ERR_PTR (- EINVAL );
2079
+
2045
2080
return ipv4_pdp_find (gtp , ip );
2046
2081
} else if (nla [GTPA_MS_ADDR6 ]) {
2047
2082
struct in6_addr addr = nla_get_in6_addr (nla [GTPA_MS_ADDR6 ]);
2048
2083
2084
+ if (family != AF_INET6 )
2085
+ return ERR_PTR (- EINVAL );
2086
+
2049
2087
if (addr .s6_addr32 [2 ] ||
2050
2088
addr .s6_addr32 [3 ])
2051
2089
return ERR_PTR (- EADDRNOTAVAIL );
@@ -2054,10 +2092,13 @@ static struct pdp_ctx *gtp_find_pdp_by_link(struct net *net,
2054
2092
} else if (nla [GTPA_VERSION ]) {
2055
2093
u32 gtp_version = nla_get_u32 (nla [GTPA_VERSION ]);
2056
2094
2057
- if (gtp_version == GTP_V0 && nla [GTPA_TID ])
2058
- return gtp0_pdp_find (gtp , nla_get_u64 (nla [GTPA_TID ]));
2059
- else if (gtp_version == GTP_V1 && nla [GTPA_I_TEI ])
2060
- return gtp1_pdp_find (gtp , nla_get_u32 (nla [GTPA_I_TEI ]));
2095
+ if (gtp_version == GTP_V0 && nla [GTPA_TID ]) {
2096
+ return gtp0_pdp_find (gtp , nla_get_u64 (nla [GTPA_TID ]),
2097
+ family );
2098
+ } else if (gtp_version == GTP_V1 && nla [GTPA_I_TEI ]) {
2099
+ return gtp1_pdp_find (gtp , nla_get_u32 (nla [GTPA_I_TEI ]),
2100
+ family );
2101
+ }
2061
2102
}
2062
2103
2063
2104
return ERR_PTR (- EINVAL );
0 commit comments