~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/ipv4/fou_bpf.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /net/ipv4/fou_bpf.c (Version linux-6.11.5) and /net/ipv4/fou_bpf.c (Version linux-6.4.16)


  1 // SPDX-License-Identifier: GPL-2.0-only            1 // SPDX-License-Identifier: GPL-2.0-only
  2 /* Unstable Fou Helpers for TC-BPF hook             2 /* Unstable Fou Helpers for TC-BPF hook
  3  *                                                  3  *
  4  * These are called from SCHED_CLS BPF program      4  * These are called from SCHED_CLS BPF programs. Note that it is
  5  * allowed to break compatibility for these fu      5  * allowed to break compatibility for these functions since the interface they
  6  * are exposed through to BPF programs is expl      6  * are exposed through to BPF programs is explicitly unstable.
  7  */                                                 7  */
  8                                                     8 
  9 #include <linux/bpf.h>                              9 #include <linux/bpf.h>
 10 #include <linux/btf_ids.h>                         10 #include <linux/btf_ids.h>
 11                                                    11 
 12 #include <net/dst_metadata.h>                      12 #include <net/dst_metadata.h>
 13 #include <net/fou.h>                               13 #include <net/fou.h>
 14                                                    14 
 15 struct bpf_fou_encap {                             15 struct bpf_fou_encap {
 16         __be16 sport;                              16         __be16 sport;
 17         __be16 dport;                              17         __be16 dport;
 18 };                                                 18 };
 19                                                    19 
 20 enum bpf_fou_encap_type {                          20 enum bpf_fou_encap_type {
 21         FOU_BPF_ENCAP_FOU,                         21         FOU_BPF_ENCAP_FOU,
 22         FOU_BPF_ENCAP_GUE,                         22         FOU_BPF_ENCAP_GUE,
 23 };                                                 23 };
 24                                                    24 
 25 __bpf_kfunc_start_defs();                      !!  25 __diag_push();
                                                   >>  26 __diag_ignore_all("-Wmissing-prototypes",
                                                   >>  27                   "Global functions as their definitions will be in BTF");
 26                                                    28 
 27 /* bpf_skb_set_fou_encap - Set FOU encap param     29 /* bpf_skb_set_fou_encap - Set FOU encap parameters
 28  *                                                 30  *
 29  * This function allows for using GUE or FOU e     31  * This function allows for using GUE or FOU encapsulation together with an
 30  * ipip device in collect-metadata mode.           32  * ipip device in collect-metadata mode.
 31  *                                                 33  *
 32  * It is meant to be used in BPF tc-hooks and      34  * It is meant to be used in BPF tc-hooks and after a call to the
 33  * bpf_skb_set_tunnel_key helper, responsible      35  * bpf_skb_set_tunnel_key helper, responsible for setting IP addresses.
 34  *                                                 36  *
 35  * Parameters:                                     37  * Parameters:
 36  * @skb_ctx     Pointer to ctx (__sk_buff) in      38  * @skb_ctx     Pointer to ctx (__sk_buff) in TC program. Cannot be NULL
 37  * @encap       Pointer to a `struct bpf_fou_e     39  * @encap       Pointer to a `struct bpf_fou_encap` storing UDP src and
 38  *              dst ports. If sport is set to      40  *              dst ports. If sport is set to 0 the kernel will auto-assign a
 39  *              port. This is similar to using     41  *              port. This is similar to using `encap-sport auto`.
 40  *              Cannot be NULL                     42  *              Cannot be NULL
 41  * @type        Encapsulation type for the pac     43  * @type        Encapsulation type for the packet. Their definitions are
 42  *              specified in `enum bpf_fou_enc     44  *              specified in `enum bpf_fou_encap_type`
 43  */                                                45  */
 44 __bpf_kfunc int bpf_skb_set_fou_encap(struct _     46 __bpf_kfunc int bpf_skb_set_fou_encap(struct __sk_buff *skb_ctx,
 45                                       struct b     47                                       struct bpf_fou_encap *encap, int type)
 46 {                                                  48 {
 47         struct sk_buff *skb = (struct sk_buff      49         struct sk_buff *skb = (struct sk_buff *)skb_ctx;
 48         struct ip_tunnel_info *info = skb_tunn     50         struct ip_tunnel_info *info = skb_tunnel_info(skb);
 49                                                    51 
 50         if (unlikely(!encap))                      52         if (unlikely(!encap))
 51                 return -EINVAL;                    53                 return -EINVAL;
 52                                                    54 
 53         if (unlikely(!info || !(info->mode & I     55         if (unlikely(!info || !(info->mode & IP_TUNNEL_INFO_TX)))
 54                 return -EINVAL;                    56                 return -EINVAL;
 55                                                    57 
 56         switch (type) {                            58         switch (type) {
 57         case FOU_BPF_ENCAP_FOU:                    59         case FOU_BPF_ENCAP_FOU:
 58                 info->encap.type = TUNNEL_ENCA     60                 info->encap.type = TUNNEL_ENCAP_FOU;
 59                 break;                             61                 break;
 60         case FOU_BPF_ENCAP_GUE:                    62         case FOU_BPF_ENCAP_GUE:
 61                 info->encap.type = TUNNEL_ENCA     63                 info->encap.type = TUNNEL_ENCAP_GUE;
 62                 break;                             64                 break;
 63         default:                                   65         default:
 64                 info->encap.type = TUNNEL_ENCA     66                 info->encap.type = TUNNEL_ENCAP_NONE;
 65         }                                          67         }
 66                                                    68 
 67         if (test_bit(IP_TUNNEL_CSUM_BIT, info- !!  69         if (info->key.tun_flags & TUNNEL_CSUM)
 68                 info->encap.flags |= TUNNEL_EN     70                 info->encap.flags |= TUNNEL_ENCAP_FLAG_CSUM;
 69                                                    71 
 70         info->encap.sport = encap->sport;          72         info->encap.sport = encap->sport;
 71         info->encap.dport = encap->dport;          73         info->encap.dport = encap->dport;
 72                                                    74 
 73         return 0;                                  75         return 0;
 74 }                                                  76 }
 75                                                    77 
 76 /* bpf_skb_get_fou_encap - Get FOU encap param     78 /* bpf_skb_get_fou_encap - Get FOU encap parameters
 77  *                                                 79  *
 78  * This function allows for reading encap meta     80  * This function allows for reading encap metadata from a packet received
 79  * on an ipip device in collect-metadata mode.     81  * on an ipip device in collect-metadata mode.
 80  *                                                 82  *
 81  * Parameters:                                     83  * Parameters:
 82  * @skb_ctx     Pointer to ctx (__sk_buff) in      84  * @skb_ctx     Pointer to ctx (__sk_buff) in TC program. Cannot be NULL
 83  * @encap       Pointer to a struct bpf_fou_en     85  * @encap       Pointer to a struct bpf_fou_encap storing UDP source and
 84  *              destination port. Cannot be NU     86  *              destination port. Cannot be NULL
 85  */                                                87  */
 86 __bpf_kfunc int bpf_skb_get_fou_encap(struct _     88 __bpf_kfunc int bpf_skb_get_fou_encap(struct __sk_buff *skb_ctx,
 87                                       struct b     89                                       struct bpf_fou_encap *encap)
 88 {                                                  90 {
 89         struct sk_buff *skb = (struct sk_buff      91         struct sk_buff *skb = (struct sk_buff *)skb_ctx;
 90         struct ip_tunnel_info *info = skb_tunn     92         struct ip_tunnel_info *info = skb_tunnel_info(skb);
 91                                                    93 
 92         if (unlikely(!info))                       94         if (unlikely(!info))
 93                 return -EINVAL;                    95                 return -EINVAL;
 94                                                    96 
 95         encap->sport = info->encap.sport;          97         encap->sport = info->encap.sport;
 96         encap->dport = info->encap.dport;          98         encap->dport = info->encap.dport;
 97                                                    99 
 98         return 0;                                 100         return 0;
 99 }                                                 101 }
100                                                   102 
101 __bpf_kfunc_end_defs();                        !! 103 __diag_pop()
102                                                   104 
103 BTF_KFUNCS_START(fou_kfunc_set)                !! 105 BTF_SET8_START(fou_kfunc_set)
104 BTF_ID_FLAGS(func, bpf_skb_set_fou_encap)         106 BTF_ID_FLAGS(func, bpf_skb_set_fou_encap)
105 BTF_ID_FLAGS(func, bpf_skb_get_fou_encap)         107 BTF_ID_FLAGS(func, bpf_skb_get_fou_encap)
106 BTF_KFUNCS_END(fou_kfunc_set)                  !! 108 BTF_SET8_END(fou_kfunc_set)
107                                                   109 
108 static const struct btf_kfunc_id_set fou_bpf_k    110 static const struct btf_kfunc_id_set fou_bpf_kfunc_set = {
109         .owner = THIS_MODULE,                     111         .owner = THIS_MODULE,
110         .set   = &fou_kfunc_set,                  112         .set   = &fou_kfunc_set,
111 };                                                113 };
112                                                   114 
113 int register_fou_bpf(void)                        115 int register_fou_bpf(void)
114 {                                                 116 {
115         return register_btf_kfunc_id_set(BPF_P    117         return register_btf_kfunc_id_set(BPF_PROG_TYPE_SCHED_CLS,
116                                          &fou_    118                                          &fou_bpf_kfunc_set);
117 }                                                 119 }
118                                                   120 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php