Commit 351596aa authored by Tom Herbert's avatar Tom Herbert Committed by David S. Miller

ila: Add struct definitions and helpers

Add structures for identifiers, locators, and an ila address which
is composed of a locator and identifier and in6_addr can be cast to
it. This includes a three bit type field and enums for the types defined
in ILA I-D.

In ILA lwt don't allow user to set a translation for a non-ILA
address (type of identifier is zero meaning it is an IID). This also
requires that the destination prefix is at least 65 bytes (64
bit locator and first byte of identifier).
Signed-off-by: default avatarTom Herbert <tom@herbertland.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent a843311d
...@@ -23,9 +23,70 @@ ...@@ -23,9 +23,70 @@
#include <net/protocol.h> #include <net/protocol.h>
#include <uapi/linux/ila.h> #include <uapi/linux/ila.h>
struct ila_locator {
union {
__u8 v8[8];
__be16 v16[4];
__be32 v32[2];
__be64 v64;
};
};
struct ila_identifier {
union {
struct {
#if defined(__LITTLE_ENDIAN_BITFIELD)
u8 __space:5;
u8 type:3;
#elif defined(__BIG_ENDIAN_BITFIELD)
u8 type:3;
u8 __space:5;
#else
#error "Adjust your <asm/byteorder.h> defines"
#endif
u8 __space2[7];
};
__u8 v8[8];
__be16 v16[4];
__be32 v32[2];
__be64 v64;
};
};
enum {
ILA_ATYPE_IID = 0,
ILA_ATYPE_LUID,
ILA_ATYPE_VIRT_V4,
ILA_ATYPE_VIRT_UNI_V6,
ILA_ATYPE_VIRT_MULTI_V6,
ILA_ATYPE_RSVD_1,
ILA_ATYPE_RSVD_2,
ILA_ATYPE_RSVD_3,
};
struct ila_addr {
union {
struct in6_addr addr;
struct {
struct ila_locator loc;
struct ila_identifier ident;
};
};
};
static inline struct ila_addr *ila_a2i(struct in6_addr *addr)
{
return (struct ila_addr *)addr;
}
static inline bool ila_addr_is_ila(struct ila_addr *iaddr)
{
return (iaddr->ident.type != ILA_ATYPE_IID);
}
struct ila_params { struct ila_params {
__be64 locator; struct ila_locator locator;
__be64 locator_match; struct ila_locator locator_match;
__wsum csum_diff; __wsum csum_diff;
}; };
...@@ -38,7 +99,7 @@ static inline __wsum compute_csum_diff8(const __be32 *from, const __be32 *to) ...@@ -38,7 +99,7 @@ static inline __wsum compute_csum_diff8(const __be32 *from, const __be32 *to)
return csum_partial(diff, sizeof(diff), 0); return csum_partial(diff, sizeof(diff), 0);
} }
void update_ipv6_locator(struct sk_buff *skb, struct ila_params *p); void ila_update_ipv6_locator(struct sk_buff *skb, struct ila_params *p);
int ila_lwt_init(void); int ila_lwt_init(void);
void ila_lwt_fini(void); void ila_lwt_fini(void);
......
...@@ -15,17 +15,20 @@ ...@@ -15,17 +15,20 @@
static __wsum get_csum_diff(struct ipv6hdr *ip6h, struct ila_params *p) static __wsum get_csum_diff(struct ipv6hdr *ip6h, struct ila_params *p)
{ {
if (*(__be64 *)&ip6h->daddr == p->locator_match) struct ila_addr *iaddr = ila_a2i(&ip6h->daddr);
if (iaddr->loc.v64 == p->locator_match.v64)
return p->csum_diff; return p->csum_diff;
else else
return compute_csum_diff8((__be32 *)&ip6h->daddr, return compute_csum_diff8((__be32 *)&iaddr->loc,
(__be32 *)&p->locator); (__be32 *)&p->locator);
} }
void update_ipv6_locator(struct sk_buff *skb, struct ila_params *p) void ila_update_ipv6_locator(struct sk_buff *skb, struct ila_params *p)
{ {
__wsum diff; __wsum diff;
struct ipv6hdr *ip6h = ipv6_hdr(skb); struct ipv6hdr *ip6h = ipv6_hdr(skb);
struct ila_addr *iaddr = ila_a2i(&ip6h->daddr);
size_t nhoff = sizeof(struct ipv6hdr); size_t nhoff = sizeof(struct ipv6hdr);
/* First update checksum */ /* First update checksum */
...@@ -68,7 +71,7 @@ void update_ipv6_locator(struct sk_buff *skb, struct ila_params *p) ...@@ -68,7 +71,7 @@ void update_ipv6_locator(struct sk_buff *skb, struct ila_params *p)
} }
/* Now change destination address */ /* Now change destination address */
*(__be64 *)&ip6h->daddr = p->locator; iaddr->loc = p->locator;
} }
static int __init ila_init(void) static int __init ila_init(void)
......
...@@ -26,7 +26,7 @@ static int ila_output(struct net *net, struct sock *sk, struct sk_buff *skb) ...@@ -26,7 +26,7 @@ static int ila_output(struct net *net, struct sock *sk, struct sk_buff *skb)
if (skb->protocol != htons(ETH_P_IPV6)) if (skb->protocol != htons(ETH_P_IPV6))
goto drop; goto drop;
update_ipv6_locator(skb, ila_params_lwtunnel(dst->lwtstate)); ila_update_ipv6_locator(skb, ila_params_lwtunnel(dst->lwtstate));
return dst->lwtstate->orig_output(net, sk, skb); return dst->lwtstate->orig_output(net, sk, skb);
...@@ -42,7 +42,7 @@ static int ila_input(struct sk_buff *skb) ...@@ -42,7 +42,7 @@ static int ila_input(struct sk_buff *skb)
if (skb->protocol != htons(ETH_P_IPV6)) if (skb->protocol != htons(ETH_P_IPV6))
goto drop; goto drop;
update_ipv6_locator(skb, ila_params_lwtunnel(dst->lwtstate)); ila_update_ipv6_locator(skb, ila_params_lwtunnel(dst->lwtstate));
return dst->lwtstate->orig_input(skb); return dst->lwtstate->orig_input(skb);
...@@ -64,11 +64,26 @@ static int ila_build_state(struct net_device *dev, struct nlattr *nla, ...@@ -64,11 +64,26 @@ static int ila_build_state(struct net_device *dev, struct nlattr *nla,
size_t encap_len = sizeof(*p); size_t encap_len = sizeof(*p);
struct lwtunnel_state *newts; struct lwtunnel_state *newts;
const struct fib6_config *cfg6 = cfg; const struct fib6_config *cfg6 = cfg;
struct ila_addr *iaddr;
int ret; int ret;
if (family != AF_INET6) if (family != AF_INET6)
return -EINVAL; return -EINVAL;
if (cfg6->fc_dst_len < sizeof(struct ila_locator) + 1) {
/* Need to have full locator and at least type field
* included in destination
*/
return -EINVAL;
}
iaddr = (struct ila_addr *)&cfg6->fc_dst;
if (!ila_addr_is_ila(iaddr)) {
/* Don't allow setting a translation for a non-ILA address */
return -EINVAL;
}
ret = nla_parse_nested(tb, ILA_ATTR_MAX, nla, ret = nla_parse_nested(tb, ILA_ATTR_MAX, nla,
ila_nl_policy); ila_nl_policy);
if (ret < 0) if (ret < 0)
...@@ -84,16 +99,14 @@ static int ila_build_state(struct net_device *dev, struct nlattr *nla, ...@@ -84,16 +99,14 @@ static int ila_build_state(struct net_device *dev, struct nlattr *nla,
newts->len = encap_len; newts->len = encap_len;
p = ila_params_lwtunnel(newts); p = ila_params_lwtunnel(newts);
p->locator = (__force __be64)nla_get_u64(tb[ILA_ATTR_LOCATOR]); p->locator.v64 = (__force __be64)nla_get_u64(tb[ILA_ATTR_LOCATOR]);
if (cfg6->fc_dst_len > sizeof(__be64)) { /* Precompute checksum difference for translation since we
/* Precompute checksum difference for translation since we * know both the old locator and the new one.
* know both the old locator and the new one. */
*/ p->locator_match = iaddr->loc;
p->locator_match = *(__be64 *)&cfg6->fc_dst; p->csum_diff = compute_csum_diff8(
p->csum_diff = compute_csum_diff8( (__be32 *)&p->locator_match, (__be32 *)&p->locator);
(__be32 *)&p->locator_match, (__be32 *)&p->locator);
}
newts->type = LWTUNNEL_ENCAP_ILA; newts->type = LWTUNNEL_ENCAP_ILA;
newts->flags |= LWTUNNEL_STATE_OUTPUT_REDIRECT | newts->flags |= LWTUNNEL_STATE_OUTPUT_REDIRECT |
...@@ -109,7 +122,7 @@ static int ila_fill_encap_info(struct sk_buff *skb, ...@@ -109,7 +122,7 @@ static int ila_fill_encap_info(struct sk_buff *skb,
{ {
struct ila_params *p = ila_params_lwtunnel(lwtstate); struct ila_params *p = ila_params_lwtunnel(lwtstate);
if (nla_put_u64_64bit(skb, ILA_ATTR_LOCATOR, (__force u64)p->locator, if (nla_put_u64_64bit(skb, ILA_ATTR_LOCATOR, (__force u64)p->locator.v64,
ILA_ATTR_PAD)) ILA_ATTR_PAD))
goto nla_put_failure; goto nla_put_failure;
...@@ -130,7 +143,7 @@ static int ila_encap_cmp(struct lwtunnel_state *a, struct lwtunnel_state *b) ...@@ -130,7 +143,7 @@ static int ila_encap_cmp(struct lwtunnel_state *a, struct lwtunnel_state *b)
struct ila_params *a_p = ila_params_lwtunnel(a); struct ila_params *a_p = ila_params_lwtunnel(a);
struct ila_params *b_p = ila_params_lwtunnel(b); struct ila_params *b_p = ila_params_lwtunnel(b);
return (a_p->locator != b_p->locator); return (a_p->locator.v64 != b_p->locator.v64);
} }
static const struct lwtunnel_encap_ops ila_encap_ops = { static const struct lwtunnel_encap_ops ila_encap_ops = {
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment