Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

pfcp: always set pfcp metadata

In PFCP receive path set metadata needed by flower code to do correct
classification based on this metadata.

Signed-off-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
Signed-off-by: Marcin Szycik <marcin.szycik@linux.intel.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Michal Swiatkowski and committed by
David S. Miller
6dd514f4 76c8764e

+282 -6
+80 -1
drivers/net/pfcp.c
··· 21 21 struct socket *sock; 22 22 struct net_device *dev; 23 23 struct net *net; 24 + 25 + struct gro_cells gro_cells; 24 26 }; 25 27 26 28 static unsigned int pfcp_net_id __read_mostly; ··· 30 28 struct pfcp_net { 31 29 struct list_head pfcp_dev_list; 32 30 }; 31 + 32 + static void 33 + pfcp_session_recv(struct pfcp_dev *pfcp, struct sk_buff *skb, 34 + struct pfcp_metadata *md) 35 + { 36 + struct pfcphdr_session *unparsed = pfcp_hdr_session(skb); 37 + 38 + md->seid = unparsed->seid; 39 + md->type = PFCP_TYPE_SESSION; 40 + } 41 + 42 + static void 43 + pfcp_node_recv(struct pfcp_dev *pfcp, struct sk_buff *skb, 44 + struct pfcp_metadata *md) 45 + { 46 + md->type = PFCP_TYPE_NODE; 47 + } 48 + 49 + static int pfcp_encap_recv(struct sock *sk, struct sk_buff *skb) 50 + { 51 + IP_TUNNEL_DECLARE_FLAGS(flags) = { }; 52 + struct metadata_dst *tun_dst; 53 + struct pfcp_metadata *md; 54 + struct pfcphdr *unparsed; 55 + struct pfcp_dev *pfcp; 56 + 57 + if (unlikely(!pskb_may_pull(skb, PFCP_HLEN))) 58 + goto drop; 59 + 60 + pfcp = rcu_dereference_sk_user_data(sk); 61 + if (unlikely(!pfcp)) 62 + goto drop; 63 + 64 + unparsed = pfcp_hdr(skb); 65 + 66 + ip_tunnel_flags_zero(flags); 67 + tun_dst = udp_tun_rx_dst(skb, sk->sk_family, flags, 0, 68 + sizeof(*md)); 69 + if (unlikely(!tun_dst)) 70 + goto drop; 71 + 72 + md = ip_tunnel_info_opts(&tun_dst->u.tun_info); 73 + if (unlikely(!md)) 74 + goto drop; 75 + 76 + if (unparsed->flags & PFCP_SEID_FLAG) 77 + pfcp_session_recv(pfcp, skb, md); 78 + else 79 + pfcp_node_recv(pfcp, skb, md); 80 + 81 + __set_bit(IP_TUNNEL_PFCP_OPT_BIT, flags); 82 + ip_tunnel_info_opts_set(&tun_dst->u.tun_info, md, sizeof(*md), 83 + flags); 84 + 85 + if (unlikely(iptunnel_pull_header(skb, PFCP_HLEN, skb->protocol, 86 + !net_eq(sock_net(sk), 87 + dev_net(pfcp->dev))))) 88 + goto drop; 89 + 90 + skb_dst_set(skb, (struct dst_entry *)tun_dst); 91 + 92 + skb_reset_network_header(skb); 93 + skb_reset_mac_header(skb); 94 + skb->dev = pfcp->dev; 95 + 96 + gro_cells_receive(&pfcp->gro_cells, skb); 97 + 98 + return 0; 99 + drop: 100 + kfree_skb(skb); 101 + return 0; 102 + } 33 103 34 104 static void pfcp_del_sock(struct pfcp_dev *pfcp) 35 105 { ··· 113 39 { 114 40 struct pfcp_dev *pfcp = netdev_priv(dev); 115 41 42 + gro_cells_destroy(&pfcp->gro_cells); 116 43 pfcp_del_sock(pfcp); 117 44 } 118 45 ··· 123 48 124 49 pfcp->dev = dev; 125 50 126 - return 0; 51 + return gro_cells_init(&pfcp->gro_cells, dev); 127 52 } 128 53 129 54 static const struct net_device_ops pfcp_netdev_ops = { ··· 168 93 err = udp_sock_create(net, &udp_conf, &sock); 169 94 if (err) 170 95 return ERR_PTR(err); 96 + 97 + tuncfg.sk_user_data = pfcp; 98 + tuncfg.encap_rcv = pfcp_encap_recv; 99 + tuncfg.encap_type = 1; 171 100 172 101 setup_udp_tunnel_sock(net, sock, &tuncfg); 173 102
+3
include/net/ip_tunnels.h
··· 216 216 __set_bit(IP_TUNNEL_VXLAN_OPT_BIT, present); 217 217 __set_bit(IP_TUNNEL_ERSPAN_OPT_BIT, present); 218 218 __set_bit(IP_TUNNEL_GTP_OPT_BIT, present); 219 + __set_bit(IP_TUNNEL_PFCP_OPT_BIT, present); 219 220 220 221 ip_tunnel_flags_or(flags, flags, present); 221 222 } ··· 229 228 __set_bit(IP_TUNNEL_VXLAN_OPT_BIT, present); 230 229 __set_bit(IP_TUNNEL_ERSPAN_OPT_BIT, present); 231 230 __set_bit(IP_TUNNEL_GTP_OPT_BIT, present); 231 + __set_bit(IP_TUNNEL_PFCP_OPT_BIT, present); 232 232 233 233 __ipt_flag_op(bitmap_andnot, flags, flags, present); 234 234 } ··· 242 240 __set_bit(IP_TUNNEL_VXLAN_OPT_BIT, present); 243 241 __set_bit(IP_TUNNEL_ERSPAN_OPT_BIT, present); 244 242 __set_bit(IP_TUNNEL_GTP_OPT_BIT, present); 243 + __set_bit(IP_TUNNEL_PFCP_OPT_BIT, present); 245 244 246 245 return ip_tunnel_flags_intersect(flags, present); 247 246 }
+73
include/net/pfcp.h
··· 2 2 #ifndef _PFCP_H_ 3 3 #define _PFCP_H_ 4 4 5 + #include <uapi/linux/if_ether.h> 6 + #include <net/dst_metadata.h> 5 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> 6 12 #include <linux/string.h> 7 13 #include <linux/types.h> 14 + #include <linux/bits.h> 8 15 9 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 + } 10 83 11 84 static inline bool netif_is_pfcp(const struct net_device *dev) 12 85 {
+3
include/uapi/linux/if_tunnel.h
··· 212 212 IP_TUNNEL_VTI_BIT, 213 213 IP_TUNNEL_SIT_ISATAP_BIT = IP_TUNNEL_VTI_BIT, 214 214 215 + /* Flags starting from here are not available via the old UAPI */ 216 + IP_TUNNEL_PFCP_OPT_BIT, /* OPTIONS_PRESENT */ 217 + 215 218 __IP_TUNNEL_FLAG_NUM, 216 219 }; 217 220
+14
include/uapi/linux/pkt_cls.h
··· 587 587 * TCA_FLOWER_KEY_ENC_OPT_GTP_ 588 588 * attributes 589 589 */ 590 + TCA_FLOWER_KEY_ENC_OPTS_PFCP, /* Nested 591 + * TCA_FLOWER_KEY_ENC_IPT_PFCP 592 + * attributes 593 + */ 590 594 __TCA_FLOWER_KEY_ENC_OPTS_MAX, 591 595 }; 592 596 ··· 639 635 640 636 #define TCA_FLOWER_KEY_ENC_OPT_GTP_MAX \ 641 637 (__TCA_FLOWER_KEY_ENC_OPT_GTP_MAX - 1) 638 + 639 + enum { 640 + TCA_FLOWER_KEY_ENC_OPT_PFCP_UNSPEC, 641 + TCA_FLOWER_KEY_ENC_OPT_PFCP_TYPE, /* u8 */ 642 + TCA_FLOWER_KEY_ENC_OPT_PFCP_SEID, /* be64 */ 643 + __TCA_FLOWER_KEY_ENC_OPT_PFCP_MAX, 644 + }; 645 + 646 + #define TCA_FLOWER_KEY_ENC_OPT_PFCP_MAX \ 647 + (__TCA_FLOWER_KEY_ENC_OPT_PFCP_MAX - 1) 642 648 643 649 enum { 644 650 TCA_FLOWER_KEY_MPLS_OPTS_UNSPEC,
+2 -5
net/core/net_test.c
··· 335 335 ip_tunnel_flags_1), 336 336 IP_TUNNEL_FLAGS_TEST("conflict", ip_tunnel_flags_2_src, true, 337 337 VTI_ISVTI, ip_tunnel_flags_2_exp), 338 - IP_TUNNEL_FLAGS_TEST("new", ip_tunnel_flags_3_src, 339 - /* This must be set to ``false`` once 340 - * ``__IP_TUNNEL_FLAG_NUM`` goes above 17. 341 - */ 342 - true, cpu_to_be16(BIT(IP_TUNNEL_VXLAN_OPT_BIT)), 338 + IP_TUNNEL_FLAGS_TEST("new", ip_tunnel_flags_3_src, false, 339 + cpu_to_be16(BIT(IP_TUNNEL_VXLAN_OPT_BIT)), 343 340 ip_tunnel_flags_3_exp), 344 341 }; 345 342
+107
net/sched/cls_flower.c
··· 28 28 #include <net/vxlan.h> 29 29 #include <net/erspan.h> 30 30 #include <net/gtp.h> 31 + #include <net/pfcp.h> 31 32 #include <net/tc_wrapper.h> 32 33 33 34 #include <net/dst.h> ··· 742 741 [TCA_FLOWER_KEY_ENC_OPTS_VXLAN] = { .type = NLA_NESTED }, 743 742 [TCA_FLOWER_KEY_ENC_OPTS_ERSPAN] = { .type = NLA_NESTED }, 744 743 [TCA_FLOWER_KEY_ENC_OPTS_GTP] = { .type = NLA_NESTED }, 744 + [TCA_FLOWER_KEY_ENC_OPTS_PFCP] = { .type = NLA_NESTED }, 745 745 }; 746 746 747 747 static const struct nla_policy ··· 770 768 gtp_opt_policy[TCA_FLOWER_KEY_ENC_OPT_GTP_MAX + 1] = { 771 769 [TCA_FLOWER_KEY_ENC_OPT_GTP_PDU_TYPE] = { .type = NLA_U8 }, 772 770 [TCA_FLOWER_KEY_ENC_OPT_GTP_QFI] = { .type = NLA_U8 }, 771 + }; 772 + 773 + static const struct nla_policy 774 + pfcp_opt_policy[TCA_FLOWER_KEY_ENC_OPT_PFCP_MAX + 1] = { 775 + [TCA_FLOWER_KEY_ENC_OPT_PFCP_TYPE] = { .type = NLA_U8 }, 776 + [TCA_FLOWER_KEY_ENC_OPT_PFCP_SEID] = { .type = NLA_U64 }, 773 777 }; 774 778 775 779 static const struct nla_policy ··· 1427 1419 return sizeof(*sinfo); 1428 1420 } 1429 1421 1422 + static int fl_set_pfcp_opt(const struct nlattr *nla, struct fl_flow_key *key, 1423 + int depth, int option_len, 1424 + struct netlink_ext_ack *extack) 1425 + { 1426 + struct nlattr *tb[TCA_FLOWER_KEY_ENC_OPT_PFCP_MAX + 1]; 1427 + struct pfcp_metadata *md; 1428 + int err; 1429 + 1430 + md = (struct pfcp_metadata *)&key->enc_opts.data[key->enc_opts.len]; 1431 + memset(md, 0xff, sizeof(*md)); 1432 + 1433 + if (!depth) 1434 + return sizeof(*md); 1435 + 1436 + if (nla_type(nla) != TCA_FLOWER_KEY_ENC_OPTS_PFCP) { 1437 + NL_SET_ERR_MSG_MOD(extack, "Non-pfcp option type for mask"); 1438 + return -EINVAL; 1439 + } 1440 + 1441 + err = nla_parse_nested(tb, TCA_FLOWER_KEY_ENC_OPT_PFCP_MAX, nla, 1442 + pfcp_opt_policy, extack); 1443 + if (err < 0) 1444 + return err; 1445 + 1446 + if (!option_len && !tb[TCA_FLOWER_KEY_ENC_OPT_PFCP_TYPE]) { 1447 + NL_SET_ERR_MSG_MOD(extack, "Missing tunnel key pfcp option type"); 1448 + return -EINVAL; 1449 + } 1450 + 1451 + if (tb[TCA_FLOWER_KEY_ENC_OPT_PFCP_TYPE]) 1452 + md->type = nla_get_u8(tb[TCA_FLOWER_KEY_ENC_OPT_PFCP_TYPE]); 1453 + 1454 + if (tb[TCA_FLOWER_KEY_ENC_OPT_PFCP_SEID]) 1455 + md->seid = nla_get_be64(tb[TCA_FLOWER_KEY_ENC_OPT_PFCP_SEID]); 1456 + 1457 + return sizeof(*md); 1458 + } 1459 + 1430 1460 static int fl_set_enc_opt(struct nlattr **tb, struct fl_flow_key *key, 1431 1461 struct fl_flow_key *mask, 1432 1462 struct netlink_ext_ack *extack) ··· 1619 1573 if (key->enc_opts.len != mask->enc_opts.len) { 1620 1574 NL_SET_ERR_MSG_MOD(extack, 1621 1575 "Key and mask miss aligned"); 1576 + return -EINVAL; 1577 + } 1578 + break; 1579 + case TCA_FLOWER_KEY_ENC_OPTS_PFCP: 1580 + if (key->enc_opts.dst_opt_type) { 1581 + NL_SET_ERR_MSG_MOD(extack, "Duplicate type for pfcp options"); 1582 + return -EINVAL; 1583 + } 1584 + option_len = 0; 1585 + key->enc_opts.dst_opt_type = IP_TUNNEL_PFCP_OPT_BIT; 1586 + option_len = fl_set_pfcp_opt(nla_opt_key, key, 1587 + key_depth, option_len, 1588 + extack); 1589 + if (option_len < 0) 1590 + return option_len; 1591 + 1592 + key->enc_opts.len += option_len; 1593 + /* At the same time we need to parse through the mask 1594 + * in order to verify exact and mask attribute lengths. 1595 + */ 1596 + mask->enc_opts.dst_opt_type = IP_TUNNEL_PFCP_OPT_BIT; 1597 + option_len = fl_set_pfcp_opt(nla_opt_msk, mask, 1598 + msk_depth, option_len, 1599 + extack); 1600 + if (option_len < 0) 1601 + return option_len; 1602 + 1603 + mask->enc_opts.len += option_len; 1604 + if (key->enc_opts.len != mask->enc_opts.len) { 1605 + NL_SET_ERR_MSG_MOD(extack, "Key and mask miss aligned"); 1622 1606 return -EINVAL; 1623 1607 } 1624 1608 break; ··· 3194 3118 return -EMSGSIZE; 3195 3119 } 3196 3120 3121 + static int fl_dump_key_pfcp_opt(struct sk_buff *skb, 3122 + struct flow_dissector_key_enc_opts *enc_opts) 3123 + { 3124 + struct pfcp_metadata *md; 3125 + struct nlattr *nest; 3126 + 3127 + nest = nla_nest_start_noflag(skb, TCA_FLOWER_KEY_ENC_OPTS_PFCP); 3128 + if (!nest) 3129 + goto nla_put_failure; 3130 + 3131 + md = (struct pfcp_metadata *)&enc_opts->data[0]; 3132 + if (nla_put_u8(skb, TCA_FLOWER_KEY_ENC_OPT_PFCP_TYPE, md->type)) 3133 + goto nla_put_failure; 3134 + 3135 + if (nla_put_be64(skb, TCA_FLOWER_KEY_ENC_OPT_PFCP_SEID, 3136 + md->seid, 0)) 3137 + goto nla_put_failure; 3138 + 3139 + nla_nest_end(skb, nest); 3140 + return 0; 3141 + 3142 + nla_put_failure: 3143 + nla_nest_cancel(skb, nest); 3144 + return -EMSGSIZE; 3145 + } 3146 + 3197 3147 static int fl_dump_key_ct(struct sk_buff *skb, 3198 3148 struct flow_dissector_key_ct *key, 3199 3149 struct flow_dissector_key_ct *mask) ··· 3322 3220 break; 3323 3221 case IP_TUNNEL_GTP_OPT_BIT: 3324 3222 err = fl_dump_key_gtp_opt(skb, enc_opts); 3223 + if (err) 3224 + goto nla_put_failure; 3225 + break; 3226 + case IP_TUNNEL_PFCP_OPT_BIT: 3227 + err = fl_dump_key_pfcp_opt(skb, enc_opts); 3325 3228 if (err) 3326 3229 goto nla_put_failure; 3327 3230 break;