^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include <linux/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <net/checksum.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <net/dst_cache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <net/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <net/ip6_fib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <net/ip6_route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <net/lwtunnel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <net/protocol.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <uapi/linux/ila.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "ila.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct ila_lwt {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) struct ila_params p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct dst_cache dst_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) u32 connected : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) u32 lwt_output : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static inline struct ila_lwt *ila_lwt_lwtunnel(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct lwtunnel_state *lwt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) return (struct ila_lwt *)lwt->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static inline struct ila_params *ila_params_lwtunnel(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct lwtunnel_state *lwt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) return &ila_lwt_lwtunnel(lwt)->p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static int ila_output(struct net *net, struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct dst_entry *orig_dst = skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct rt6_info *rt = (struct rt6_info *)orig_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct ila_lwt *ilwt = ila_lwt_lwtunnel(orig_dst->lwtstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct dst_entry *dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) int err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (skb->protocol != htons(ETH_P_IPV6))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) if (ilwt->lwt_output)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) ila_update_ipv6_locator(skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) ila_params_lwtunnel(orig_dst->lwtstate),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) if (rt->rt6i_flags & (RTF_GATEWAY | RTF_CACHE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /* Already have a next hop address in route, no need for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * dest cache route.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) return orig_dst->lwtstate->orig_output(net, sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) dst = dst_cache_get(&ilwt->dst_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if (unlikely(!dst)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct ipv6hdr *ip6h = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct flowi6 fl6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /* Lookup a route for the new destination. Take into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * account that the base route may already have a gateway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) memset(&fl6, 0, sizeof(fl6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) fl6.flowi6_oif = orig_dst->dev->ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) fl6.flowi6_iif = LOOPBACK_IFINDEX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) fl6.daddr = *rt6_nexthop((struct rt6_info *)orig_dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) &ip6h->daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) dst = ip6_route_output(net, NULL, &fl6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (dst->error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) err = -EHOSTUNREACH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) dst_release(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if (IS_ERR(dst)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) err = PTR_ERR(dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (ilwt->connected)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) dst_cache_set_ip6(&ilwt->dst_cache, dst, &fl6.saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) skb_dst_set(skb, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return dst_output(net, sk, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static int ila_input(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) struct dst_entry *dst = skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct ila_lwt *ilwt = ila_lwt_lwtunnel(dst->lwtstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (skb->protocol != htons(ETH_P_IPV6))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (!ilwt->lwt_output)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) ila_update_ipv6_locator(skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) ila_params_lwtunnel(dst->lwtstate),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return dst->lwtstate->orig_input(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static const struct nla_policy ila_nl_policy[ILA_ATTR_MAX + 1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) [ILA_ATTR_LOCATOR] = { .type = NLA_U64, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) [ILA_ATTR_CSUM_MODE] = { .type = NLA_U8, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) [ILA_ATTR_IDENT_TYPE] = { .type = NLA_U8, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) [ILA_ATTR_HOOK_TYPE] = { .type = NLA_U8, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static int ila_build_state(struct net *net, struct nlattr *nla,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) unsigned int family, const void *cfg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct lwtunnel_state **ts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct ila_lwt *ilwt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct ila_params *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct nlattr *tb[ILA_ATTR_MAX + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct lwtunnel_state *newts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) const struct fib6_config *cfg6 = cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct ila_addr *iaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) u8 ident_type = ILA_ATYPE_USE_FORMAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) u8 hook_type = ILA_HOOK_ROUTE_OUTPUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) u8 csum_mode = ILA_CSUM_NO_ACTION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) bool lwt_output = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) u8 eff_ident_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (family != AF_INET6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) ret = nla_parse_nested_deprecated(tb, ILA_ATTR_MAX, nla,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) ila_nl_policy, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (!tb[ILA_ATTR_LOCATOR])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) iaddr = (struct ila_addr *)&cfg6->fc_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (tb[ILA_ATTR_IDENT_TYPE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) ident_type = nla_get_u8(tb[ILA_ATTR_IDENT_TYPE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (ident_type == ILA_ATYPE_USE_FORMAT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) /* Infer identifier type from type field in formatted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * identifier.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (cfg6->fc_dst_len < 8 * sizeof(struct ila_locator) + 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) /* Need to have full locator and at least type field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * included in destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) eff_ident_type = iaddr->ident.type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) eff_ident_type = ident_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) switch (eff_ident_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) case ILA_ATYPE_IID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /* Don't allow ILA for IID type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) case ILA_ATYPE_LUID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) case ILA_ATYPE_VIRT_V4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) case ILA_ATYPE_VIRT_UNI_V6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) case ILA_ATYPE_VIRT_MULTI_V6:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) case ILA_ATYPE_NONLOCAL_ADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /* These ILA formats are not supported yet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (tb[ILA_ATTR_HOOK_TYPE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) hook_type = nla_get_u8(tb[ILA_ATTR_HOOK_TYPE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) switch (hook_type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) case ILA_HOOK_ROUTE_OUTPUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) lwt_output = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) case ILA_HOOK_ROUTE_INPUT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) lwt_output = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) if (tb[ILA_ATTR_CSUM_MODE])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) csum_mode = nla_get_u8(tb[ILA_ATTR_CSUM_MODE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (csum_mode == ILA_CSUM_NEUTRAL_MAP &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) ila_csum_neutral_set(iaddr->ident)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) /* Don't allow translation if checksum neutral bit is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * configured and it's set in the SIR address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) newts = lwtunnel_state_alloc(sizeof(*ilwt));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (!newts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) ilwt = ila_lwt_lwtunnel(newts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) ret = dst_cache_init(&ilwt->dst_cache, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) kfree(newts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) ilwt->lwt_output = !!lwt_output;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) p = ila_params_lwtunnel(newts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) p->csum_mode = csum_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) p->ident_type = ident_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) p->locator.v64 = (__force __be64)nla_get_u64(tb[ILA_ATTR_LOCATOR]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) /* Precompute checksum difference for translation since we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) * know both the old locator and the new one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) p->locator_match = iaddr->loc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) ila_init_saved_csum(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) newts->type = LWTUNNEL_ENCAP_ILA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) newts->flags |= LWTUNNEL_STATE_OUTPUT_REDIRECT |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) LWTUNNEL_STATE_INPUT_REDIRECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (cfg6->fc_dst_len == 8 * sizeof(struct in6_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) ilwt->connected = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) *ts = newts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) static void ila_destroy_state(struct lwtunnel_state *lwt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) dst_cache_destroy(&ila_lwt_lwtunnel(lwt)->dst_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) static int ila_fill_encap_info(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) struct lwtunnel_state *lwtstate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct ila_params *p = ila_params_lwtunnel(lwtstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) struct ila_lwt *ilwt = ila_lwt_lwtunnel(lwtstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if (nla_put_u64_64bit(skb, ILA_ATTR_LOCATOR, (__force u64)p->locator.v64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) ILA_ATTR_PAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (nla_put_u8(skb, ILA_ATTR_CSUM_MODE, (__force u8)p->csum_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) if (nla_put_u8(skb, ILA_ATTR_IDENT_TYPE, (__force u8)p->ident_type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (nla_put_u8(skb, ILA_ATTR_HOOK_TYPE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) ilwt->lwt_output ? ILA_HOOK_ROUTE_OUTPUT :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) ILA_HOOK_ROUTE_INPUT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) static int ila_encap_nlsize(struct lwtunnel_state *lwtstate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) return nla_total_size_64bit(sizeof(u64)) + /* ILA_ATTR_LOCATOR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) nla_total_size(sizeof(u8)) + /* ILA_ATTR_CSUM_MODE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) nla_total_size(sizeof(u8)) + /* ILA_ATTR_IDENT_TYPE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) nla_total_size(sizeof(u8)) + /* ILA_ATTR_HOOK_TYPE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static int ila_encap_cmp(struct lwtunnel_state *a, struct lwtunnel_state *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) struct ila_params *a_p = ila_params_lwtunnel(a);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) struct ila_params *b_p = ila_params_lwtunnel(b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) return (a_p->locator.v64 != b_p->locator.v64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static const struct lwtunnel_encap_ops ila_encap_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) .build_state = ila_build_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) .destroy_state = ila_destroy_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) .output = ila_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) .input = ila_input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) .fill_encap = ila_fill_encap_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) .get_encap_size = ila_encap_nlsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) .cmp_encap = ila_encap_cmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) int ila_lwt_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) return lwtunnel_encap_add_ops(&ila_encap_ops, LWTUNNEL_ENCAP_ILA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) void ila_lwt_fini(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) lwtunnel_encap_del_ops(&ila_encap_ops, LWTUNNEL_ENCAP_ILA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) }