2015-12-16 07:41:35 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Tom Herbert <tom@herbertland.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ILA_H
|
|
|
|
#define __ILA_H
|
|
|
|
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/ip.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/socket.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <net/checksum.h>
|
2018-06-28 05:39:01 +08:00
|
|
|
#include <net/genetlink.h>
|
2015-12-16 07:41:35 +08:00
|
|
|
#include <net/ip.h>
|
|
|
|
#include <net/protocol.h>
|
|
|
|
#include <uapi/linux/ila.h>
|
|
|
|
|
2016-04-24 02:46:55 +08:00
|
|
|
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)
|
2016-04-24 02:46:57 +08:00
|
|
|
u8 __space:4;
|
|
|
|
u8 csum_neutral:1;
|
2016-04-24 02:46:55 +08:00
|
|
|
u8 type:3;
|
|
|
|
#elif defined(__BIG_ENDIAN_BITFIELD)
|
|
|
|
u8 type:3;
|
2016-04-24 02:46:57 +08:00
|
|
|
u8 csum_neutral:1;
|
|
|
|
u8 __space:4;
|
2016-04-24 02:46:55 +08:00
|
|
|
#else
|
|
|
|
#error "Adjust your <asm/byteorder.h> defines"
|
|
|
|
#endif
|
|
|
|
u8 __space2[7];
|
|
|
|
};
|
|
|
|
__u8 v8[8];
|
|
|
|
__be16 v16[4];
|
|
|
|
__be32 v32[2];
|
|
|
|
__be64 v64;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-04-24 02:46:57 +08:00
|
|
|
#define CSUM_NEUTRAL_FLAG htonl(0x10000000)
|
|
|
|
|
2016-04-24 02:46:55 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-12-16 07:41:35 +08:00
|
|
|
struct ila_params {
|
2016-04-24 02:46:55 +08:00
|
|
|
struct ila_locator locator;
|
|
|
|
struct ila_locator locator_match;
|
2015-12-16 07:41:35 +08:00
|
|
|
__wsum csum_diff;
|
2016-04-24 02:46:57 +08:00
|
|
|
u8 csum_mode;
|
2017-11-06 07:58:24 +08:00
|
|
|
u8 ident_type;
|
2015-12-16 07:41:35 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline __wsum compute_csum_diff8(const __be32 *from, const __be32 *to)
|
|
|
|
{
|
|
|
|
__be32 diff[] = {
|
|
|
|
~from[0], ~from[1], to[0], to[1],
|
|
|
|
};
|
|
|
|
|
|
|
|
return csum_partial(diff, sizeof(diff), 0);
|
|
|
|
}
|
|
|
|
|
2016-04-24 02:46:57 +08:00
|
|
|
static inline bool ila_csum_neutral_set(struct ila_identifier ident)
|
|
|
|
{
|
|
|
|
return !!(ident.csum_neutral);
|
|
|
|
}
|
|
|
|
|
2016-06-08 07:09:44 +08:00
|
|
|
void ila_update_ipv6_locator(struct sk_buff *skb, struct ila_params *p,
|
|
|
|
bool set_csum_neutral);
|
2015-12-16 07:41:35 +08:00
|
|
|
|
2016-04-24 02:46:57 +08:00
|
|
|
void ila_init_saved_csum(struct ila_params *p);
|
|
|
|
|
2018-06-28 05:39:01 +08:00
|
|
|
struct ila_net {
|
|
|
|
struct {
|
|
|
|
struct rhashtable rhash_table;
|
|
|
|
spinlock_t *locks; /* Bucket locks for entry manipulation */
|
|
|
|
unsigned int locks_mask;
|
|
|
|
bool hooks_registered;
|
|
|
|
} xlat;
|
|
|
|
};
|
|
|
|
|
2015-12-16 07:41:35 +08:00
|
|
|
int ila_lwt_init(void);
|
|
|
|
void ila_lwt_fini(void);
|
2018-06-28 05:39:01 +08:00
|
|
|
|
|
|
|
int ila_xlat_init_net(struct net *net);
|
|
|
|
void ila_xlat_exit_net(struct net *net);
|
|
|
|
|
|
|
|
int ila_xlat_nl_cmd_add_mapping(struct sk_buff *skb, struct genl_info *info);
|
|
|
|
int ila_xlat_nl_cmd_del_mapping(struct sk_buff *skb, struct genl_info *info);
|
|
|
|
int ila_xlat_nl_cmd_get_mapping(struct sk_buff *skb, struct genl_info *info);
|
2018-06-28 05:39:02 +08:00
|
|
|
int ila_xlat_nl_cmd_flush(struct sk_buff *skb, struct genl_info *info);
|
2018-06-28 05:39:01 +08:00
|
|
|
int ila_xlat_nl_dump_start(struct netlink_callback *cb);
|
|
|
|
int ila_xlat_nl_dump_done(struct netlink_callback *cb);
|
|
|
|
int ila_xlat_nl_dump(struct sk_buff *skb, struct netlink_callback *cb);
|
|
|
|
|
|
|
|
extern unsigned int ila_net_id;
|
|
|
|
|
|
|
|
extern struct genl_family ila_nl_family;
|
2015-12-16 07:41:35 +08:00
|
|
|
|
|
|
|
#endif /* __ILA_H */
|