xref: /linux/include/net/pfcp.h (revision bf36793fa260cb68cc817f311f1f683788261796)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _PFCP_H_
3 #define _PFCP_H_
4 
5 #include <uapi/linux/if_ether.h>
6 #include <net/dst_metadata.h>
7 #include <linux/netdevice.h>
8 #include <uapi/linux/ipv6.h>
9 #include <net/udp_tunnel.h>
10 #include <uapi/linux/udp.h>
11 #include <uapi/linux/ip.h>
12 #include <linux/string.h>
13 #include <linux/types.h>
14 #include <linux/bits.h>
15 
16 #define PFCP_PORT 8805
17 
18 /* PFCP protocol header */
19 struct pfcphdr {
20 	u8	flags;
21 	u8	message_type;
22 	__be16	message_length;
23 };
24 
25 /* PFCP header flags */
26 #define PFCP_SEID_FLAG		BIT(0)
27 #define PFCP_MP_FLAG		BIT(1)
28 
29 #define PFCP_VERSION_MASK	GENMASK(4, 0)
30 
31 #define PFCP_HLEN (sizeof(struct udphdr) + sizeof(struct pfcphdr))
32 
33 /* PFCP node related messages */
34 struct pfcphdr_node {
35 	u8	seq_number[3];
36 	u8	reserved;
37 };
38 
39 /* PFCP session related messages */
40 struct pfcphdr_session {
41 	__be64	seid;
42 	u8	seq_number[3];
43 #ifdef __LITTLE_ENDIAN_BITFIELD
44 	u8	message_priority:4,
45 		reserved:4;
46 #elif defined(__BIG_ENDIAN_BITFIELD)
47 	u8	reserved:4,
48 		message_priprity:4;
49 #else
50 #error "Please fix <asm/byteorder>"
51 #endif
52 };
53 
54 struct pfcp_metadata {
55 	u8 type;
56 	__be64 seid;
57 } __packed;
58 
59 enum {
60 	PFCP_TYPE_NODE		= 0,
61 	PFCP_TYPE_SESSION	= 1,
62 };
63 
64 #define PFCP_HEADROOM (sizeof(struct iphdr) + sizeof(struct udphdr) + \
65 		       sizeof(struct pfcphdr) + sizeof(struct ethhdr))
66 #define PFCP6_HEADROOM (sizeof(struct ipv6hdr) + sizeof(struct udphdr) + \
67 			sizeof(struct pfcphdr) + sizeof(struct ethhdr))
68 
69 static inline struct pfcphdr *pfcp_hdr(struct sk_buff *skb)
70 {
71 	return (struct pfcphdr *)(udp_hdr(skb) + 1);
72 }
73 
74 static inline struct pfcphdr_node *pfcp_hdr_node(struct sk_buff *skb)
75 {
76 	return (struct pfcphdr_node *)(pfcp_hdr(skb) + 1);
77 }
78 
79 static inline struct pfcphdr_session *pfcp_hdr_session(struct sk_buff *skb)
80 {
81 	return (struct pfcphdr_session *)(pfcp_hdr(skb) + 1);
82 }
83 
84 static inline bool netif_is_pfcp(const struct net_device *dev)
85 {
86 	return dev->rtnl_link_ops &&
87 	       !strcmp(dev->rtnl_link_ops->kind, "pfcp");
88 }
89 
90 #endif
91