pfcp.h 1.9 KB

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