Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
1
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
ffc90e9
Documentation
LICENSES
arch
block
certs
crypto
drivers
accel
accessibility
acpi
amba
android
ata
atm
auxdisplay
base
bcma
block
bluetooth
bus
cache
cdrom
cdx
char
clk
clocksource
comedi
connector
counter
cpufreq
cpuidle
crypto
cxl
dax
dca
devfreq
dio
dma-buf
dma
dpll
edac
eisa
extcon
firewire
firmware
fpga
fsi
gnss
gpio
gpu
greybus
hid
hsi
hte
hv
hwmon
hwspinlock
hwtracing
i2c
i3c
idle
iio
infiniband
input
interconnect
iommu
ipack
irqchip
isdn
leds
macintosh
mailbox
mcb
md
media
memory
memstick
message
mfd
misc
mmc
most
mtd
mux
net
arcnet
bonding
caif
can
dsa
ethernet
fddi
fjes
hamradio
hippi
hyperv
ieee802154
ipa
ipvlan
mctp
mdio
netdevsim
pcs
phy
plip
ppp
pse-pd
slip
team
thunderbolt
usb
vmxnet3
vxlan
wan
wireguard
wireless
wwan
xen-netback
Kconfig
LICENSE.SRC
Makefile
Space.c
amt.c
bareudp.c
dummy.c
eql.c
geneve.c
gtp.c
ifb.c
loopback.c
macsec.c
macvlan.c
macvtap.c
mdio.c
mhi_net.c
mii.c
net_failover.c
netconsole.c
netkit.c
nlmon.c
ntb_netdev.c
pfcp.c
rionet.c
sb1000.c
sungem_phy.c
tap.c
tun.c
veth.c
virtio_net.c
vrf.c
vsockmon.c
xen-netfront.c
nfc
ntb
nubus
nvdimm
nvme
nvmem
of
opp
parisc
parport
pci
pcmcia
peci
perf
phy
pinctrl
platform
pmdomain
pnp
power
powercap
pps
ps3
ptp
pwm
rapidio
ras
regulator
remoteproc
reset
rpmsg
rtc
s390
sbus
scsi
sh
siox
slimbus
soc
soundwire
spi
spmi
ssb
staging
target
tc
tee
thermal
thunderbolt
tty
ufs
uio
usb
vdpa
vfio
vhost
video
virt
virtio
w1
watchdog
xen
zorro
Kconfig
Makefile
fs
include
init
io_uring
ipc
kernel
lib
mm
net
rust
samples
scripts
security
sound
tools
usr
virt
.clang-format
.clippy.toml
.cocciconfig
.editorconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
.rustfmt.toml
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
drivers
/
net
/
pfcp.c
Copy path
Blame
Blame
Latest commit
History
History
306 lines (238 loc) · 6.37 KB
Breadcrumbs
linux
/
drivers
/
net
/
pfcp.c
Top
File metadata and controls
Code
Blame
306 lines (238 loc) · 6.37 KB
Raw
// SPDX-License-Identifier: GPL-2.0-or-later /* * PFCP according to 3GPP TS 29.244 * * Copyright (C) 2022, Intel Corporation. */ #include <linux/module.h> #include <linux/netdevice.h> #include <linux/rculist.h> #include <linux/skbuff.h> #include <linux/types.h> #include <net/udp.h> #include <net/udp_tunnel.h> #include <net/pfcp.h> struct pfcp_dev { struct list_head list; struct socket *sock; struct net_device *dev; struct net *net; struct gro_cells gro_cells; }; static unsigned int pfcp_net_id __read_mostly; struct pfcp_net { struct list_head pfcp_dev_list; }; static void pfcp_session_recv(struct pfcp_dev *pfcp, struct sk_buff *skb, struct pfcp_metadata *md) { struct pfcphdr_session *unparsed = pfcp_hdr_session(skb); md->seid = unparsed->seid; md->type = PFCP_TYPE_SESSION; } static void pfcp_node_recv(struct pfcp_dev *pfcp, struct sk_buff *skb, struct pfcp_metadata *md) { md->type = PFCP_TYPE_NODE; } static int pfcp_encap_recv(struct sock *sk, struct sk_buff *skb) { IP_TUNNEL_DECLARE_FLAGS(flags) = { }; struct metadata_dst *tun_dst; struct pfcp_metadata *md; struct pfcphdr *unparsed; struct pfcp_dev *pfcp; if (unlikely(!pskb_may_pull(skb, PFCP_HLEN))) goto drop; pfcp = rcu_dereference_sk_user_data(sk); if (unlikely(!pfcp)) goto drop; unparsed = pfcp_hdr(skb); ip_tunnel_flags_zero(flags); tun_dst = udp_tun_rx_dst(skb, sk->sk_family, flags, 0, sizeof(*md)); if (unlikely(!tun_dst)) goto drop; md = ip_tunnel_info_opts(&tun_dst->u.tun_info); if (unlikely(!md)) goto drop; if (unparsed->flags & PFCP_SEID_FLAG) pfcp_session_recv(pfcp, skb, md); else pfcp_node_recv(pfcp, skb, md); __set_bit(IP_TUNNEL_PFCP_OPT_BIT, tun_dst->u.tun_info.key.tun_flags); tun_dst->u.tun_info.options_len = sizeof(*md); if (unlikely(iptunnel_pull_header(skb, PFCP_HLEN, skb->protocol, !net_eq(sock_net(sk), dev_net(pfcp->dev))))) goto drop; skb_dst_set(skb, (struct dst_entry *)tun_dst); skb_reset_network_header(skb); skb_reset_mac_header(skb); skb->dev = pfcp->dev; gro_cells_receive(&pfcp->gro_cells, skb); return 0; drop: kfree_skb(skb); return 0; } static void pfcp_del_sock(struct pfcp_dev *pfcp) { udp_tunnel_sock_release(pfcp->sock); pfcp->sock = NULL; } static void pfcp_dev_uninit(struct net_device *dev) { struct pfcp_dev *pfcp = netdev_priv(dev); gro_cells_destroy(&pfcp->gro_cells); pfcp_del_sock(pfcp); } static int pfcp_dev_init(struct net_device *dev) { struct pfcp_dev *pfcp = netdev_priv(dev); pfcp->dev = dev; return gro_cells_init(&pfcp->gro_cells, dev); } static const struct net_device_ops pfcp_netdev_ops = { .ndo_init = pfcp_dev_init, .ndo_uninit = pfcp_dev_uninit, .ndo_get_stats64 = dev_get_tstats64, }; static const struct device_type pfcp_type = { .name = "pfcp", }; static void pfcp_link_setup(struct net_device *dev) { dev->netdev_ops = &pfcp_netdev_ops; dev->needs_free_netdev = true; SET_NETDEV_DEVTYPE(dev, &pfcp_type); dev->hard_header_len = 0; dev->addr_len = 0; dev->type = ARPHRD_NONE; dev->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST; dev->priv_flags |= IFF_NO_QUEUE; netif_keep_dst(dev); } static struct socket *pfcp_create_sock(struct pfcp_dev *pfcp) { struct udp_tunnel_sock_cfg tuncfg = {}; struct udp_port_cfg udp_conf = { .local_ip.s_addr = htonl(INADDR_ANY), .family = AF_INET, }; struct net *net = pfcp->net; struct socket *sock; int err; udp_conf.local_udp_port = htons(PFCP_PORT); err = udp_sock_create(net, &udp_conf, &sock); if (err) return ERR_PTR(err); tuncfg.sk_user_data = pfcp; tuncfg.encap_rcv = pfcp_encap_recv; tuncfg.encap_type = 1; setup_udp_tunnel_sock(net, sock, &tuncfg); return sock; } static int pfcp_add_sock(struct pfcp_dev *pfcp) { pfcp->sock = pfcp_create_sock(pfcp); return PTR_ERR_OR_ZERO(pfcp->sock); } static int pfcp_newlink(struct net *net, struct net_device *dev, struct nlattr *tb[], struct nlattr *data[], struct netlink_ext_ack *extack) { struct pfcp_dev *pfcp = netdev_priv(dev); struct pfcp_net *pn; int err; pfcp->net = net; err = pfcp_add_sock(pfcp); if (err) { netdev_dbg(dev, "failed to add pfcp socket %d\n", err); goto exit_err; } err = register_netdevice(dev); if (err) { netdev_dbg(dev, "failed to register pfcp netdev %d\n", err); goto exit_del_pfcp_sock; } pn = net_generic(net, pfcp_net_id); list_add(&pfcp->list, &pn->pfcp_dev_list); netdev_dbg(dev, "registered new PFCP interface\n"); return 0; exit_del_pfcp_sock: pfcp_del_sock(pfcp); exit_err: pfcp->net = NULL; return err; } static void pfcp_dellink(struct net_device *dev, struct list_head *head) { struct pfcp_dev *pfcp = netdev_priv(dev); list_del(&pfcp->list); unregister_netdevice_queue(dev, head); } static struct rtnl_link_ops pfcp_link_ops __read_mostly = { .kind = "pfcp", .priv_size = sizeof(struct pfcp_dev), .setup = pfcp_link_setup, .newlink = pfcp_newlink, .dellink = pfcp_dellink, }; static int __net_init pfcp_net_init(struct net *net) { struct pfcp_net *pn = net_generic(net, pfcp_net_id); INIT_LIST_HEAD(&pn->pfcp_dev_list); return 0; } static void __net_exit pfcp_net_exit(struct net *net) { struct pfcp_net *pn = net_generic(net, pfcp_net_id); struct pfcp_dev *pfcp, *pfcp_next; struct net_device *dev; LIST_HEAD(list); rtnl_lock(); for_each_netdev(net, dev) if (dev->rtnl_link_ops == &pfcp_link_ops) pfcp_dellink(dev, &list); list_for_each_entry_safe(pfcp, pfcp_next, &pn->pfcp_dev_list, list) pfcp_dellink(pfcp->dev, &list); unregister_netdevice_many(&list); rtnl_unlock(); } static struct pernet_operations pfcp_net_ops = { .init = pfcp_net_init, .exit = pfcp_net_exit, .id = &pfcp_net_id, .size = sizeof(struct pfcp_net), }; static int __init pfcp_init(void) { int err; err = register_pernet_subsys(&pfcp_net_ops); if (err) goto exit_err; err = rtnl_link_register(&pfcp_link_ops); if (err) goto exit_unregister_subsys; return 0; exit_unregister_subsys: unregister_pernet_subsys(&pfcp_net_ops); exit_err: pr_err("loading PFCP module failed: err %d\n", err); return err; } late_initcall(pfcp_init); static void __exit pfcp_exit(void) { rtnl_link_unregister(&pfcp_link_ops); unregister_pernet_subsys(&pfcp_net_ops); pr_info("PFCP module unloaded\n"); } module_exit(pfcp_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Wojciech Drewek <wojciech.drewek@intel.com>"); MODULE_DESCRIPTION("Interface driver for PFCP encapsulated traffic"); MODULE_ALIAS_RTNL_LINK("pfcp");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
You can’t perform that action at this time.