Lines Matching refs:pctx

86 static void pdp_context_delete(struct pdp_ctx *pctx);
153 static bool gtp_check_ms_ipv4(struct sk_buff *skb, struct pdp_ctx *pctx, in gtp_check_ms_ipv4() argument
164 return iph->daddr == pctx->ms_addr_ip4.s_addr; in gtp_check_ms_ipv4()
166 return iph->saddr == pctx->ms_addr_ip4.s_addr; in gtp_check_ms_ipv4()
172 static bool gtp_check_ms(struct sk_buff *skb, struct pdp_ctx *pctx, in gtp_check_ms() argument
177 return gtp_check_ms_ipv4(skb, pctx, hdrlen, role); in gtp_check_ms()
182 static int gtp_rx(struct pdp_ctx *pctx, struct sk_buff *skb, in gtp_rx() argument
185 if (!gtp_check_ms(skb, pctx, hdrlen, role)) { in gtp_rx()
186 netdev_dbg(pctx->dev, "No PDP ctx for this MS\n"); in gtp_rx()
192 !net_eq(sock_net(pctx->sk), dev_net(pctx->dev)))) { in gtp_rx()
193 pctx->dev->stats.rx_length_errors++; in gtp_rx()
197 netdev_dbg(pctx->dev, "forwarding packet from GGSN to uplink\n"); in gtp_rx()
206 skb->dev = pctx->dev; in gtp_rx()
208 dev_sw_netstats_rx_add(pctx->dev, skb->len); in gtp_rx()
214 pctx->dev->stats.rx_dropped++; in gtp_rx()
224 struct pdp_ctx *pctx; in gtp0_udp_encap_recv() local
237 pctx = gtp0_pdp_find(gtp, be64_to_cpu(gtp0->tid)); in gtp0_udp_encap_recv()
238 if (!pctx) { in gtp0_udp_encap_recv()
243 return gtp_rx(pctx, skb, hdrlen, gtp->role); in gtp0_udp_encap_recv()
251 struct pdp_ctx *pctx; in gtp1u_udp_encap_recv() local
279 pctx = gtp1_pdp_find(gtp, ntohl(gtp1->tid)); in gtp1u_udp_encap_recv()
280 if (!pctx) { in gtp1u_udp_encap_recv()
285 return gtp_rx(pctx, skb, hdrlen, gtp->role); in gtp1u_udp_encap_recv()
405 static inline void gtp0_push_header(struct sk_buff *skb, struct pdp_ctx *pctx) in gtp0_push_header() argument
415 gtp0->seq = htons((atomic_inc_return(&pctx->tx_seq) - 1) % 0xffff); in gtp0_push_header()
416 gtp0->flow = htons(pctx->u.v0.flow); in gtp0_push_header()
419 gtp0->tid = cpu_to_be64(pctx->u.v0.tid); in gtp0_push_header()
422 static inline void gtp1_push_header(struct sk_buff *skb, struct pdp_ctx *pctx) in gtp1_push_header() argument
438 gtp1->tid = htonl(pctx->u.v1.o_tei); in gtp1_push_header()
450 struct pdp_ctx *pctx; member
457 switch (pktinfo->pctx->gtp_version) { in gtp_push_header()
460 gtp0_push_header(skb, pktinfo->pctx); in gtp_push_header()
464 gtp1_push_header(skb, pktinfo->pctx); in gtp_push_header()
471 struct pdp_ctx *pctx, struct rtable *rt, in gtp_set_pktinfo_ipv4() argument
477 pktinfo->pctx = pctx; in gtp_set_pktinfo_ipv4()
487 struct pdp_ctx *pctx; in gtp_build_skb_ip4() local
499 pctx = ipv4_pdp_find(gtp, iph->saddr); in gtp_build_skb_ip4()
501 pctx = ipv4_pdp_find(gtp, iph->daddr); in gtp_build_skb_ip4()
503 if (!pctx) { in gtp_build_skb_ip4()
508 netdev_dbg(dev, "found PDP context %p\n", pctx); in gtp_build_skb_ip4()
510 rt = ip4_route_output_gtp(&fl4, pctx->sk, pctx->peer_addr_ip4.s_addr); in gtp_build_skb_ip4()
513 &pctx->peer_addr_ip4.s_addr); in gtp_build_skb_ip4()
520 &pctx->peer_addr_ip4.s_addr); in gtp_build_skb_ip4()
530 switch (pctx->gtp_version) { in gtp_build_skb_ip4()
552 gtp_set_pktinfo_ipv4(pktinfo, pctx->sk, iph, pctx, rt, &fl4, dev); in gtp_build_skb_ip4()
599 !net_eq(sock_net(pktinfo.pctx->sk), in gtp_dev_xmit()
713 struct pdp_ctx *pctx; in gtp_dellink() local
717 hlist_for_each_entry_rcu(pctx, &gtp->tid_hash[i], hlist_tid) in gtp_dellink()
718 pdp_context_delete(pctx); in gtp_dellink()
913 static void ipv4_pdp_fill(struct pdp_ctx *pctx, struct genl_info *info) in ipv4_pdp_fill() argument
915 pctx->gtp_version = nla_get_u32(info->attrs[GTPA_VERSION]); in ipv4_pdp_fill()
916 pctx->af = AF_INET; in ipv4_pdp_fill()
917 pctx->peer_addr_ip4.s_addr = in ipv4_pdp_fill()
919 pctx->ms_addr_ip4.s_addr = in ipv4_pdp_fill()
922 switch (pctx->gtp_version) { in ipv4_pdp_fill()
928 pctx->u.v0.tid = nla_get_u64(info->attrs[GTPA_TID]); in ipv4_pdp_fill()
929 pctx->u.v0.flow = nla_get_u16(info->attrs[GTPA_FLOW]); in ipv4_pdp_fill()
932 pctx->u.v1.i_tei = nla_get_u32(info->attrs[GTPA_I_TEI]); in ipv4_pdp_fill()
933 pctx->u.v1.o_tei = nla_get_u32(info->attrs[GTPA_O_TEI]); in ipv4_pdp_fill()
943 struct pdp_ctx *pctx, *pctx_tid = NULL; in gtp_pdp_add() local
954 pctx = ipv4_pdp_find(gtp, ms_addr); in gtp_pdp_add()
955 if (pctx) in gtp_pdp_add()
972 if (pctx && pctx_tid) in gtp_pdp_add()
974 if (!pctx) in gtp_pdp_add()
975 pctx = pctx_tid; in gtp_pdp_add()
977 ipv4_pdp_fill(pctx, info); in gtp_pdp_add()
979 if (pctx->gtp_version == GTP_V0) in gtp_pdp_add()
981 pctx->u.v0.tid, pctx); in gtp_pdp_add()
982 else if (pctx->gtp_version == GTP_V1) in gtp_pdp_add()
984 pctx->u.v1.i_tei, pctx->u.v1.o_tei, pctx); in gtp_pdp_add()
986 return pctx; in gtp_pdp_add()
990 pctx = kmalloc(sizeof(*pctx), GFP_ATOMIC); in gtp_pdp_add()
991 if (pctx == NULL) in gtp_pdp_add()
995 pctx->sk = sk; in gtp_pdp_add()
996 pctx->dev = gtp->dev; in gtp_pdp_add()
997 ipv4_pdp_fill(pctx, info); in gtp_pdp_add()
998 atomic_set(&pctx->tx_seq, 0); in gtp_pdp_add()
1000 switch (pctx->gtp_version) { in gtp_pdp_add()
1007 hash_tid = gtp0_hashfn(pctx->u.v0.tid) % gtp->hash_size; in gtp_pdp_add()
1010 hash_tid = gtp1u_hashfn(pctx->u.v1.i_tei) % gtp->hash_size; in gtp_pdp_add()
1014 hlist_add_head_rcu(&pctx->hlist_addr, &gtp->addr_hash[hash_ms]); in gtp_pdp_add()
1015 hlist_add_head_rcu(&pctx->hlist_tid, &gtp->tid_hash[hash_tid]); in gtp_pdp_add()
1017 switch (pctx->gtp_version) { in gtp_pdp_add()
1020 pctx->u.v0.tid, &pctx->peer_addr_ip4, in gtp_pdp_add()
1021 &pctx->ms_addr_ip4, pctx); in gtp_pdp_add()
1025 pctx->u.v1.i_tei, pctx->u.v1.o_tei, in gtp_pdp_add()
1026 &pctx->peer_addr_ip4, &pctx->ms_addr_ip4, pctx); in gtp_pdp_add()
1030 return pctx; in gtp_pdp_add()
1035 struct pdp_ctx *pctx = container_of(head, struct pdp_ctx, rcu_head); in pdp_context_free() local
1037 sock_put(pctx->sk); in pdp_context_free()
1038 kfree(pctx); in pdp_context_free()
1041 static void pdp_context_delete(struct pdp_ctx *pctx) in pdp_context_delete() argument
1043 hlist_del_rcu(&pctx->hlist_tid); in pdp_context_delete()
1044 hlist_del_rcu(&pctx->hlist_addr); in pdp_context_delete()
1045 call_rcu(&pctx->rcu_head, pdp_context_free); in pdp_context_delete()
1048 static int gtp_tunnel_notify(struct pdp_ctx *pctx, u8 cmd, gfp_t allocation);
1053 struct pdp_ctx *pctx; in gtp_genl_new_pdp() local
1102 pctx = gtp_pdp_add(gtp, sk, info); in gtp_genl_new_pdp()
1103 if (IS_ERR(pctx)) { in gtp_genl_new_pdp()
1104 err = PTR_ERR(pctx); in gtp_genl_new_pdp()
1106 gtp_tunnel_notify(pctx, GTP_CMD_NEWPDP, GFP_KERNEL); in gtp_genl_new_pdp()
1142 struct pdp_ctx *pctx; in gtp_find_pdp() local
1145 pctx = gtp_find_pdp_by_link(net, nla); in gtp_find_pdp()
1147 pctx = ERR_PTR(-EINVAL); in gtp_find_pdp()
1149 if (!pctx) in gtp_find_pdp()
1150 pctx = ERR_PTR(-ENOENT); in gtp_find_pdp()
1152 return pctx; in gtp_find_pdp()
1157 struct pdp_ctx *pctx; in gtp_genl_del_pdp() local
1165 pctx = gtp_find_pdp(sock_net(skb->sk), info->attrs); in gtp_genl_del_pdp()
1166 if (IS_ERR(pctx)) { in gtp_genl_del_pdp()
1167 err = PTR_ERR(pctx); in gtp_genl_del_pdp()
1171 if (pctx->gtp_version == GTP_V0) in gtp_genl_del_pdp()
1172 netdev_dbg(pctx->dev, "GTPv0-U: deleting tunnel id = %llx (pdp %p)\n", in gtp_genl_del_pdp()
1173 pctx->u.v0.tid, pctx); in gtp_genl_del_pdp()
1174 else if (pctx->gtp_version == GTP_V1) in gtp_genl_del_pdp()
1175 netdev_dbg(pctx->dev, "GTPv1-U: deleting tunnel id = %x/%x (pdp %p)\n", in gtp_genl_del_pdp()
1176 pctx->u.v1.i_tei, pctx->u.v1.o_tei, pctx); in gtp_genl_del_pdp()
1178 gtp_tunnel_notify(pctx, GTP_CMD_DELPDP, GFP_ATOMIC); in gtp_genl_del_pdp()
1179 pdp_context_delete(pctx); in gtp_genl_del_pdp()
1197 int flags, u32 type, struct pdp_ctx *pctx) in gtp_genl_fill_info() argument
1206 if (nla_put_u32(skb, GTPA_VERSION, pctx->gtp_version) || in gtp_genl_fill_info()
1207 nla_put_u32(skb, GTPA_LINK, pctx->dev->ifindex) || in gtp_genl_fill_info()
1208 nla_put_be32(skb, GTPA_PEER_ADDRESS, pctx->peer_addr_ip4.s_addr) || in gtp_genl_fill_info()
1209 nla_put_be32(skb, GTPA_MS_ADDRESS, pctx->ms_addr_ip4.s_addr)) in gtp_genl_fill_info()
1212 switch (pctx->gtp_version) { in gtp_genl_fill_info()
1214 if (nla_put_u64_64bit(skb, GTPA_TID, pctx->u.v0.tid, GTPA_PAD) || in gtp_genl_fill_info()
1215 nla_put_u16(skb, GTPA_FLOW, pctx->u.v0.flow)) in gtp_genl_fill_info()
1219 if (nla_put_u32(skb, GTPA_I_TEI, pctx->u.v1.i_tei) || in gtp_genl_fill_info()
1220 nla_put_u32(skb, GTPA_O_TEI, pctx->u.v1.o_tei)) in gtp_genl_fill_info()
1233 static int gtp_tunnel_notify(struct pdp_ctx *pctx, u8 cmd, gfp_t allocation) in gtp_tunnel_notify() argument
1242 ret = gtp_genl_fill_info(msg, 0, 0, 0, cmd, pctx); in gtp_tunnel_notify()
1248 ret = genlmsg_multicast_netns(&gtp_genl_family, dev_net(pctx->dev), msg, in gtp_tunnel_notify()
1255 struct pdp_ctx *pctx = NULL; in gtp_genl_get_pdp() local
1264 pctx = gtp_find_pdp(sock_net(skb->sk), info->attrs); in gtp_genl_get_pdp()
1265 if (IS_ERR(pctx)) { in gtp_genl_get_pdp()
1266 err = PTR_ERR(pctx); in gtp_genl_get_pdp()
1277 0, info->nlhdr->nlmsg_type, pctx); in gtp_genl_get_pdp()
1297 struct pdp_ctx *pctx; in gtp_genl_dump_pdp() local
1314 hlist_for_each_entry_rcu(pctx, &gtp->tid_hash[i], in gtp_genl_dump_pdp()
1321 cb->nlh->nlmsg_type, pctx)) { in gtp_genl_dump_pdp()