History

Merge branch 'bpf-next'

Daniel Borkmann says: ==================== BPF updates Couple of misc updates to BPF, besides others this series adds bpf_csum_diff() to be used with L3 csums, allows for managing tunnel options for collect meta data mode, and enabling ipv6 traffic class for collect meta data in vxlan specifically (geneve already supports it). For more details, please see individual patches. The series requires net to be merged into net-next first to avoid any further pending merge conflicts. ====================

David S. Miller committed 10 years ago

Commit d24ad3f2 parents 810813c 14006157 files · +165 −45Browse files

Unified · Split

7 files
  1. drivers/net/geneve.c +4 −6
  2. drivers/net/vxlan.c +21 −17
  3. include/net/checksum.h +5 −0
  4. include/net/ip_tunnels.h +15 −0
  5. include/uapi/linux/bpf.h +13 −0
  6. net/core/filter.c +101 −18
  7. net/ipv4/ip_gre.c +6 −4
drivers/net/geneve.c+4−6
@@ -775,10 +775,10 @@ static struct rtable *geneve_get_v4_rt(struct sk_buff *skb, · 774 unmodified lines
775775 struct flowi4 *fl4,
776776 struct ip_tunnel_info *info)
777777 {
778+ bool use_cache = ip_tunnel_dst_cache_usable(skb, info);
778779 struct geneve_dev *geneve = netdev_priv(dev);
779780 struct dst_cache *dst_cache;
780781 struct rtable *rt = NULL;
781− bool use_cache = true;
782782 __u8 tos;
783783
784784 memset(fl4, 0, sizeof(*fl4));
@@ -804,7 +804,6 @@ static struct rtable *geneve_get_v4_rt(struct sk_buff *skb, · 19 unmodified lines
804804 dst_cache = &geneve->dst_cache;
805805 }
806806
807− use_cache = use_cache && !skb->mark;
808807 if (use_cache) {
809808 rt = dst_cache_get_ip4(dst_cache, &fl4->saddr);
810809 if (rt)
@@ -832,11 +831,11 @@ static struct dst_entry *geneve_get_v6_dst(struct sk_buff *skb, · 21 unmodified lines
832831 struct flowi6 *fl6,
833832 struct ip_tunnel_info *info)
834833 {
834+ bool use_cache = ip_tunnel_dst_cache_usable(skb, info);
835835 struct geneve_dev *geneve = netdev_priv(dev);
836836 struct geneve_sock *gs6 = geneve->sock6;
837837 struct dst_entry *dst = NULL;
838838 struct dst_cache *dst_cache;
839− bool use_cache = true;
840839 __u8 prio;
841840
842841 memset(fl6, 0, sizeof(*fl6));
@@ -862,7 +861,6 @@ static struct dst_entry *geneve_get_v6_dst(struct sk_buff *skb, · 19 unmodified lines
862861 dst_cache = &geneve->dst_cache;
863862 }
864863
865− use_cache = use_cache && !skb->mark;
866864 if (use_cache) {
867865 dst = dst_cache_get_ip6(dst_cache, &fl6->saddr);
868866 if (dst)
@@ -940,7 +938,7 @@ static netdev_tx_t geneve_xmit_skb(struct sk_buff *skb, struct net_device *dev, · 71 unmodified lines
940938 u8 vni[3];
941939
942940 tunnel_id_to_vni(key->tun_id, vni);
943− if (key->tun_flags & TUNNEL_GENEVE_OPT)
941+ if (info->options_len)
944942 opts = ip_tunnel_info_opts(info);
945943
946944 if (key->tun_flags & TUNNEL_CSUM)
@@ -1027,7 +1025,7 @@ static netdev_tx_t geneve6_xmit_skb(struct sk_buff *skb, struct net_device *dev, · 80 unmodified lines
10271025 u8 vni[3];
10281026
10291027 tunnel_id_to_vni(key->tun_id, vni);
1030− if (key->tun_flags & TUNNEL_GENEVE_OPT)
1028+ if (info->options_len)
10311029 opts = ip_tunnel_info_opts(info);
10321030
10331031 if (key->tun_flags & TUNNEL_CSUM)
drivers/net/vxlan.c+21−17
@@ -1756,17 +1756,15 @@ static struct rtable *vxlan_get_route(struct vxlan_dev *vxlan, · 1755 unmodified lines
17561756 struct sk_buff *skb, int oif, u8 tos,
17571757 __be32 daddr, __be32 *saddr,
17581758 struct dst_cache *dst_cache,
1759− struct ip_tunnel_info *info)
1759+ const struct ip_tunnel_info *info)
17601760 {
1761+ bool use_cache = ip_tunnel_dst_cache_usable(skb, info);
17611762 struct rtable *rt = NULL;
1762− bool use_cache = false;
17631763 struct flowi4 fl4;
17641764
1765− /* when the ip_tunnel_info is availble, the tos used for lookup is
1766− * packet independent, so we can use the cache
1767− */
1768− if (!skb->mark && (!tos || info)) {
1769− use_cache = true;
1765+ if (tos && !info)
1766+ use_cache = false;
1767+ if (use_cache) {
17701768 rt = dst_cache_get_ip4(dst_cache, saddr);
17711769 if (rt)
17721770 return rt;
@@ -1791,16 +1789,20 @@ static struct rtable *vxlan_get_route(struct vxlan_dev *vxlan, · 18 unmodified lines
17911789
17921790 #if IS_ENABLED(CONFIG_IPV6)
17931791 static struct dst_entry *vxlan6_get_route(struct vxlan_dev *vxlan,
1794− struct sk_buff *skb, int oif,
1792+ struct sk_buff *skb, int oif, u8 tos,
17951793 const struct in6_addr *daddr,
17961794 struct in6_addr *saddr,
1797− struct dst_cache *dst_cache)
1795+ struct dst_cache *dst_cache,
1796+ const struct ip_tunnel_info *info)
17981797 {
1798+ bool use_cache = ip_tunnel_dst_cache_usable(skb, info);
17991799 struct dst_entry *ndst;
18001800 struct flowi6 fl6;
18011801 int err;
18021802
1803− if (!skb->mark) {
1803+ if (tos && !info)
1804+ use_cache = false;
1805+ if (use_cache) {
18041806 ndst = dst_cache_get_ip6(dst_cache, saddr);
18051807 if (ndst)
18061808 return ndst;
@@ -1808,6 +1810,7 @@ static struct dst_entry *vxlan6_get_route(struct vxlan_dev *vxlan, · 1 unmodified line
18081810
18091811 memset(&fl6, 0, sizeof(fl6));
18101812 fl6.flowi6_oif = oif;
1813+ fl6.flowi6_tos = RT_TOS(tos);
18111814 fl6.daddr = *daddr;
18121815 fl6.saddr = vxlan->cfg.saddr.sin6.sin6_addr;
18131816 fl6.flowi6_mark = skb->mark;
@@ -1820,7 +1823,7 @@ static struct dst_entry *vxlan6_get_route(struct vxlan_dev *vxlan, · 6 unmodified lines
18201823 return ERR_PTR(err);
18211824
18221825 *saddr = fl6.saddr;
1823− if (!skb->mark)
1826+ if (use_cache)
18241827 dst_cache_set_ip6(dst_cache, ndst, saddr);
18251828 return ndst;
18261829 }
@@ -2016,9 +2019,9 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, · 189 unmodified lines
20162019 sk = vxlan->vn6_sock->sock->sk;
20172020
20182021 ndst = vxlan6_get_route(vxlan, skb,
2019− rdst ? rdst->remote_ifindex : 0,
2022+ rdst ? rdst->remote_ifindex : 0, tos,
20202023 &dst->sin6.sin6_addr, &saddr,
2021− dst_cache);
2024+ dst_cache, info);
20222025 if (IS_ERR(ndst)) {
20232026 netdev_dbg(dev, "no route to %pI6\n",
20242027 &dst->sin6.sin6_addr);
@@ -2053,6 +2056,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, · 28 unmodified lines
20532056 if (!info)
20542057 udp_sum = !(flags & VXLAN_F_UDP_ZERO_CSUM6_TX);
20552058
2059+ tos = ip_tunnel_ecn_encap(tos, old_iph, skb);
20562060 ttl = ttl ? : ip6_dst_hoplimit(ndst);
20572061 skb_scrub_packet(skb, xnet);
20582062 err = vxlan_build_skb(skb, ndst, sizeof(struct ipv6hdr),
@@ -2062,8 +2066,8 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, · 3 unmodified lines
20622066 return;
20632067 }
20642068 udp_tunnel6_xmit_skb(ndst, sk, skb, dev,
2065− &saddr, &dst->sin6.sin6_addr,
2066− 0, ttl, src_port, dst_port, !udp_sum);
2069+ &saddr, &dst->sin6.sin6_addr, tos, ttl,
2070+ src_port, dst_port, !udp_sum);
20672071 #endif
20682072 }
20692073
@@ -2385,9 +2389,9 @@ static int vxlan_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb) · 315 unmodified lines
23852389
23862390 if (!vxlan->vn6_sock)
23872391 return -EINVAL;
2388− ndst = vxlan6_get_route(vxlan, skb, 0,
2392+ ndst = vxlan6_get_route(vxlan, skb, 0, info->key.tos,
23892393 &info->key.u.ipv6.dst,
2390− &info->key.u.ipv6.src, NULL);
2394+ &info->key.u.ipv6.src, NULL, info);
23912395 if (IS_ERR(ndst))
23922396 return PTR_ERR(ndst);
23932397 dst_release(ndst);
include/net/checksum.h+5−0
@@ -120,6 +120,11 @@ static inline __wsum csum_partial_ext(const void *buff, int len, __wsum sum) · 119 unmodified lines
120120
121121 #define CSUM_MANGLED_0 ((__force __sum16)0xffff)
122122
123+static inline void csum_replace_by_diff(__sum16 *sum, __wsum diff)
124+{
125+ *sum = csum_fold(csum_add(diff, ~csum_unfold(*sum)));
126+}
127+
123128 static inline void csum_replace4(__sum16 *sum, __be32 from, __be32 to)
124129 {
125130 __wsum tmp = csum_sub(~csum_unfold(*sum), (__force __wsum)from);
include/net/ip_tunnels.h+15−0
@@ -140,6 +140,7 @@ struct ip_tunnel { · 139 unmodified lines
140140 #define TUNNEL_CRIT_OPT __cpu_to_be16(0x0400)
141141 #define TUNNEL_GENEVE_OPT __cpu_to_be16(0x0800)
142142 #define TUNNEL_VXLAN_OPT __cpu_to_be16(0x1000)
143+#define TUNNEL_NOCACHE __cpu_to_be16(0x2000)
143144
144145 #define TUNNEL_OPTIONS_PRESENT (TUNNEL_GENEVE_OPT | TUNNEL_VXLAN_OPT)
145146
@@ -206,6 +207,20 @@ static inline void ip_tunnel_key_init(struct ip_tunnel_key *key, · 60 unmodified lines
206207 0, sizeof(*key) - IP_TUNNEL_KEY_SIZE);
207208 }
208209
210+static inline bool
211+ip_tunnel_dst_cache_usable(const struct sk_buff *skb,
212+ const struct ip_tunnel_info *info)
213+{
214+ if (skb->mark)
215+ return false;
216+ if (!info)
217+ return true;
218+ if (info->key.tun_flags & TUNNEL_NOCACHE)
219+ return false;
220+
221+ return true;
222+}
223+
209224 static inline unsigned short ip_tunnel_info_af(const struct ip_tunnel_info
210225 *tun_info)
211226 {
include/uapi/linux/bpf.h+13−0
@@ -298,6 +298,17 @@ enum bpf_func_id { · 297 unmodified lines
298298 * Return: csum result
299299 */
300300 BPF_FUNC_csum_diff,
301+
302+ /**
303+ * bpf_skb_[gs]et_tunnel_opt(skb, opt, size)
304+ * retrieve or populate tunnel options metadata
305+ * @skb: pointer to skb
306+ * @opt: pointer to raw tunnel option data
307+ * @size: size of @opt
308+ * Return: 0 on success for set, option size for get
309+ */
310+ BPF_FUNC_skb_get_tunnel_opt,
311+ BPF_FUNC_skb_set_tunnel_opt,
301312 __BPF_FUNC_MAX_ID,
302313 };
303314
@@ -305,6 +316,7 @@ enum bpf_func_id { · 1 unmodified line
305316
306317 /* BPF_FUNC_skb_store_bytes flags. */
307318 #define BPF_F_RECOMPUTE_CSUM (1ULL << 0)
319+#define BPF_F_INVALIDATE_HASH (1ULL << 1)
308320
309321 /* BPF_FUNC_l3_csum_replace and BPF_FUNC_l4_csum_replace flags.
310322 * First 4 bits are for passing the header field size.
@@ -329,6 +341,7 @@ enum bpf_func_id { · 18 unmodified lines
329341
330342 /* BPF_FUNC_skb_set_tunnel_key flags. */
331343 #define BPF_F_ZERO_CSUM_TX (1ULL << 1)
344+#define BPF_F_DONT_FRAGMENT (1ULL << 2)
332345
333346 /* user accessible mirror of in-kernel sk_buff.
334347 * new fields can only be added to the end of this structure
net/core/filter.c+101−18
@@ -1353,7 +1353,7 @@ static u64 bpf_skb_store_bytes(u64 r1, u64 r2, u64 r3, u64 r4, u64 flags) · 1352 unmodified lines
13531353 unsigned int len = (unsigned int) r4;
13541354 void *ptr;
13551355
1356− if (unlikely(flags & ~(BPF_F_RECOMPUTE_CSUM)))
1356+ if (unlikely(flags & ~(BPF_F_RECOMPUTE_CSUM | BPF_F_INVALIDATE_HASH)))
13571357 return -EINVAL;
13581358
13591359 /* bpf verifier guarantees that:
@@ -1384,11 +1384,13 @@ static u64 bpf_skb_store_bytes(u64 r1, u64 r2, u64 r3, u64 r4, u64 flags) · 24 unmodified lines
13841384
13851385 if (flags & BPF_F_RECOMPUTE_CSUM)
13861386 skb_postpush_rcsum(skb, ptr, len);
1387+ if (flags & BPF_F_INVALIDATE_HASH)
1388+ skb_clear_hash(skb);
13871389
13881390 return 0;
13891391 }
13901392
1391−const struct bpf_func_proto bpf_skb_store_bytes_proto = {
1393+static const struct bpf_func_proto bpf_skb_store_bytes_proto = {
13921394 .func = bpf_skb_store_bytes,
13931395 .gpl_only = false,
13941396 .ret_type = RET_INTEGER,
@@ -1419,7 +1421,7 @@ static u64 bpf_skb_load_bytes(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5) · 24 unmodified lines
14191421 return 0;
14201422 }
14211423
1422−const struct bpf_func_proto bpf_skb_load_bytes_proto = {
1424+static const struct bpf_func_proto bpf_skb_load_bytes_proto = {
14231425 .func = bpf_skb_load_bytes,
14241426 .gpl_only = false,
14251427 .ret_type = RET_INTEGER,
@@ -1447,6 +1449,12 @@ static u64 bpf_l3_csum_replace(u64 r1, u64 r2, u64 from, u64 to, u64 flags) · 21 unmodified lines
14471449 return -EFAULT;
14481450
14491451 switch (flags & BPF_F_HDR_FIELD_MASK) {
1452+ case 0:
1453+ if (unlikely(from != 0))
1454+ return -EINVAL;
1455+
1456+ csum_replace_by_diff(ptr, to);
1457+ break;
14501458 case 2:
14511459 csum_replace2(ptr, from, to);
14521460 break;
@@ -1464,7 +1472,7 @@ static u64 bpf_l3_csum_replace(u64 r1, u64 r2, u64 from, u64 to, u64 flags) · 11 unmodified lines
14641472 return 0;
14651473 }
14661474
1467−const struct bpf_func_proto bpf_l3_csum_replace_proto = {
1475+static const struct bpf_func_proto bpf_l3_csum_replace_proto = {
14681476 .func = bpf_l3_csum_replace,
14691477 .gpl_only = false,
14701478 .ret_type = RET_INTEGER,
@@ -1523,7 +1531,7 @@ static u64 bpf_l4_csum_replace(u64 r1, u64 r2, u64 from, u64 to, u64 flags) · 52 unmodified lines
15231531 return 0;
15241532 }
15251533
1526−const struct bpf_func_proto bpf_l4_csum_replace_proto = {
1534+static const struct bpf_func_proto bpf_l4_csum_replace_proto = {
15271535 .func = bpf_l4_csum_replace,
15281536 .gpl_only = false,
15291537 .ret_type = RET_INTEGER,
@@ -1562,7 +1570,7 @@ static u64 bpf_csum_diff(u64 r1, u64 from_size, u64 r3, u64 to_size, u64 seed) · 32 unmodified lines
15621570 return csum_partial(sp->diff, diff_size, seed);
15631571 }
15641572
1565−const struct bpf_func_proto bpf_csum_diff_proto = {
1573+static const struct bpf_func_proto bpf_csum_diff_proto = {
15661574 .func = bpf_csum_diff,
15671575 .gpl_only = false,
15681576 .ret_type = RET_INTEGER,
@@ -1600,7 +1608,7 @@ static u64 bpf_clone_redirect(u64 r1, u64 ifindex, u64 flags, u64 r4, u64 r5) · 31 unmodified lines
16001608 return dev_queue_xmit(skb2);
16011609 }
16021610
1603−const struct bpf_func_proto bpf_clone_redirect_proto = {
1611+static const struct bpf_func_proto bpf_clone_redirect_proto = {
16041612 .func = bpf_clone_redirect,
16051613 .gpl_only = false,
16061614 .ret_type = RET_INTEGER,
@@ -1652,7 +1660,7 @@ int skb_do_redirect(struct sk_buff *skb) · 45 unmodified lines
16521660 return dev_queue_xmit(skb);
16531661 }
16541662
1655−const struct bpf_func_proto bpf_redirect_proto = {
1663+static const struct bpf_func_proto bpf_redirect_proto = {
16561664 .func = bpf_redirect,
16571665 .gpl_only = false,
16581666 .ret_type = RET_INTEGER,
@@ -1791,7 +1799,7 @@ static u64 bpf_skb_get_tunnel_key(u64 r1, u64 r2, u64 size, u64 flags, u64 r5) · 132 unmodified lines
17911799 return 0;
17921800 }
17931801
1794−const struct bpf_func_proto bpf_skb_get_tunnel_key_proto = {
1802+static const struct bpf_func_proto bpf_skb_get_tunnel_key_proto = {
17951803 .func = bpf_skb_get_tunnel_key,
17961804 .gpl_only = false,
17971805 .ret_type = RET_INTEGER,
@@ -1801,6 +1809,32 @@ const struct bpf_func_proto bpf_skb_get_tunnel_key_proto = { · 3 unmodified lines
18011809 .arg4_type = ARG_ANYTHING,
18021810 };
18031811
1812+static u64 bpf_skb_get_tunnel_opt(u64 r1, u64 r2, u64 size, u64 r4, u64 r5)
1813+{
1814+ struct sk_buff *skb = (struct sk_buff *) (long) r1;
1815+ u8 *to = (u8 *) (long) r2;
1816+ const struct ip_tunnel_info *info = skb_tunnel_info(skb);
1817+
1818+ if (unlikely(!info ||
1819+ !(info->key.tun_flags & TUNNEL_OPTIONS_PRESENT)))
1820+ return -ENOENT;
1821+ if (unlikely(size < info->options_len))
1822+ return -ENOMEM;
1823+
1824+ ip_tunnel_info_opts_get(to, info);
1825+
1826+ return info->options_len;
1827+}
1828+
1829+static const struct bpf_func_proto bpf_skb_get_tunnel_opt_proto = {
1830+ .func = bpf_skb_get_tunnel_opt,
1831+ .gpl_only = false,
1832+ .ret_type = RET_INTEGER,
1833+ .arg1_type = ARG_PTR_TO_CTX,
1834+ .arg2_type = ARG_PTR_TO_STACK,
1835+ .arg3_type = ARG_CONST_STACK_SIZE,
1836+};
1837+
18041838 static struct metadata_dst __percpu *md_dst;
18051839
18061840 static u64 bpf_skb_set_tunnel_key(u64 r1, u64 r2, u64 size, u64 flags, u64 r5)
@@ -1811,7 +1845,8 @@ static u64 bpf_skb_set_tunnel_key(u64 r1, u64 r2, u64 size, u64 flags, u64 r5) · 4 unmodified lines
18111845 u8 compat[sizeof(struct bpf_tunnel_key)];
18121846 struct ip_tunnel_info *info;
18131847
1814− if (unlikely(flags & ~(BPF_F_TUNINFO_IPV6 | BPF_F_ZERO_CSUM_TX)))
1848+ if (unlikely(flags & ~(BPF_F_TUNINFO_IPV6 | BPF_F_ZERO_CSUM_TX |
1849+ BPF_F_DONT_FRAGMENT)))
18151850 return -EINVAL;
18161851 if (unlikely(size != sizeof(struct bpf_tunnel_key))) {
18171852 switch (size) {
@@ -1835,7 +1870,10 @@ static u64 bpf_skb_set_tunnel_key(u64 r1, u64 r2, u64 size, u64 flags, u64 r5) · 17 unmodified lines
18351870 info = &md->u.tun_info;
18361871 info->mode = IP_TUNNEL_INFO_TX;
18371872
1838− info->key.tun_flags = TUNNEL_KEY | TUNNEL_CSUM;
1873+ info->key.tun_flags = TUNNEL_KEY | TUNNEL_CSUM | TUNNEL_NOCACHE;
1874+ if (flags & BPF_F_DONT_FRAGMENT)
1875+ info->key.tun_flags |= TUNNEL_DONT_FRAGMENT;
1876+
18391877 info->key.tun_id = cpu_to_be64(from->tunnel_id);
18401878 info->key.tos = from->tunnel_tos;
18411879 info->key.ttl = from->tunnel_ttl;
@@ -1853,7 +1891,7 @@ static u64 bpf_skb_set_tunnel_key(u64 r1, u64 r2, u64 size, u64 flags, u64 r5) · 11 unmodified lines
18531891 return 0;
18541892 }
18551893
1856−const struct bpf_func_proto bpf_skb_set_tunnel_key_proto = {
1894+static const struct bpf_func_proto bpf_skb_set_tunnel_key_proto = {
18571895 .func = bpf_skb_set_tunnel_key,
18581896 .gpl_only = false,
18591897 .ret_type = RET_INTEGER,
@@ -1863,17 +1901,58 @@ const struct bpf_func_proto bpf_skb_set_tunnel_key_proto = { · 3 unmodified lines
18631901 .arg4_type = ARG_ANYTHING,
18641902 };
18651903
1866−static const struct bpf_func_proto *bpf_get_skb_set_tunnel_key_proto(void)
1904+#define BPF_TUNLEN_MAX 255
1905+
1906+static u64 bpf_skb_set_tunnel_opt(u64 r1, u64 r2, u64 size, u64 r4, u64 r5)
1907+{
1908+ struct sk_buff *skb = (struct sk_buff *) (long) r1;
1909+ u8 *from = (u8 *) (long) r2;
1910+ struct ip_tunnel_info *info = skb_tunnel_info(skb);
1911+ const struct metadata_dst *md = this_cpu_ptr(md_dst);
1912+
1913+ if (unlikely(info != &md->u.tun_info || (size & (sizeof(u32) - 1))))
1914+ return -EINVAL;
1915+ if (unlikely(size > BPF_TUNLEN_MAX))
1916+ return -ENOMEM;
1917+
1918+ ip_tunnel_info_opts_set(info, from, size);
1919+
1920+ return 0;
1921+}
1922+
1923+static const struct bpf_func_proto bpf_skb_set_tunnel_opt_proto = {
1924+ .func = bpf_skb_set_tunnel_opt,
1925+ .gpl_only = false,
1926+ .ret_type = RET_INTEGER,
1927+ .arg1_type = ARG_PTR_TO_CTX,
1928+ .arg2_type = ARG_PTR_TO_STACK,
1929+ .arg3_type = ARG_CONST_STACK_SIZE,
1930+};
1931+
1932+static const struct bpf_func_proto *
1933+bpf_get_skb_set_tunnel_proto(enum bpf_func_id which)
18671934 {
18681935 if (!md_dst) {
1869− /* race is not possible, since it's called from
1870− * verifier that is holding verifier mutex
1936+ BUILD_BUG_ON(FIELD_SIZEOF(struct ip_tunnel_info,
1937+ options_len) != 1);
1938+
1939+ /* Race is not possible, since it's called from verifier
1940+ * that is holding verifier mutex.
18711941 */
1872− md_dst = metadata_dst_alloc_percpu(0, GFP_KERNEL);
1942+ md_dst = metadata_dst_alloc_percpu(BPF_TUNLEN_MAX,
1943+ GFP_KERNEL);
18731944 if (!md_dst)
18741945 return NULL;
18751946 }
1876− return &bpf_skb_set_tunnel_key_proto;
1947+
1948+ switch (which) {
1949+ case BPF_FUNC_skb_set_tunnel_key:
1950+ return &bpf_skb_set_tunnel_key_proto;
1951+ case BPF_FUNC_skb_set_tunnel_opt:
1952+ return &bpf_skb_set_tunnel_opt_proto;
1953+ default:
1954+ return NULL;
1955+ }
18771956 }
18781957
18791958 static const struct bpf_func_proto *
@@ -1927,7 +2006,11 @@ tc_cls_act_func_proto(enum bpf_func_id func_id) · 47 unmodified lines
19272006 case BPF_FUNC_skb_get_tunnel_key:
19282007 return &bpf_skb_get_tunnel_key_proto;
19292008 case BPF_FUNC_skb_set_tunnel_key:
1930− return bpf_get_skb_set_tunnel_key_proto();
2009+ return bpf_get_skb_set_tunnel_proto(func_id);
2010+ case BPF_FUNC_skb_get_tunnel_opt:
2011+ return &bpf_skb_get_tunnel_opt_proto;
2012+ case BPF_FUNC_skb_set_tunnel_opt:
2013+ return bpf_get_skb_set_tunnel_proto(func_id);
19312014 case BPF_FUNC_redirect:
19322015 return &bpf_redirect_proto;
19332016 case BPF_FUNC_get_route_realm:
net/ipv4/ip_gre.c+6−4
@@ -527,11 +527,12 @@ static void gre_fb_xmit(struct sk_buff *skb, struct net_device *dev) · 526 unmodified lines
527527 {
528528 struct ip_tunnel_info *tun_info;
529529 const struct ip_tunnel_key *key;
530+ struct rtable *rt = NULL;
530531 struct flowi4 fl;
531− struct rtable *rt;
532532 int min_headroom;
533533 int tunnel_hlen;
534534 __be16 df, flags;
535+ bool use_cache;
535536 int err;
536537
537538 tun_info = skb_tunnel_info(skb);
@@ -540,13 +541,14 @@ static void gre_fb_xmit(struct sk_buff *skb, struct net_device *dev) · 2 unmodified lines
540541 goto err_free_skb;
541542
542543 key = &tun_info->key;
543− rt = !skb->mark ? dst_cache_get_ip4(&tun_info->dst_cache, &fl.saddr) :
544− NULL;
544+ use_cache = ip_tunnel_dst_cache_usable(skb, tun_info);
545+ if (use_cache)
546+ rt = dst_cache_get_ip4(&tun_info->dst_cache, &fl.saddr);
545547 if (!rt) {
546548 rt = gre_get_rt(skb, dev, &fl, key);
547549 if (IS_ERR(rt))
548550 goto err_free_skb;
549− if (!skb->mark)
551+ if (use_cache)
550552 dst_cache_set_ip4(&tun_info->dst_cache, &rt->dst,
551553 fl.saddr);
552554 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t