mirror of
https://github.com/armbian/linux-cix.git
synced 2026-01-06 12:30:45 -08:00
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec-next
Steffen Klassert says: ==================== pull request (net-next): ipsec-next 2019-04-30 1) A lot of work to remove indirections from the xfrm code. From Florian Westphal. 2) Support ESP offload in combination with gso partial. From Boris Pismenny. 3) Remove some duplicated code from vti4. From Jeremy Sowden. Please note that there is merge conflict between commit:8742dc86d0("xfrm4: Fix uninitialized memory read in _decode_session4") from the ipsec tree and commit:c53ac41e37("xfrm: remove decode_session indirection from afinfo_policy") from the ipsec-next tree. The merge conflict will appear when those trees get merged during the merge window. The conflict can be solved as it is done in linux-next: https://lkml.org/lkml/2019/4/25/1207 Please pull or let me know if there are problems. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
@@ -132,6 +132,17 @@ struct xfrm_state_offload {
|
||||
u8 flags;
|
||||
};
|
||||
|
||||
struct xfrm_mode {
|
||||
u8 encap;
|
||||
u8 family;
|
||||
u8 flags;
|
||||
};
|
||||
|
||||
/* Flags for xfrm_mode. */
|
||||
enum {
|
||||
XFRM_MODE_FLAG_TUNNEL = 1,
|
||||
};
|
||||
|
||||
/* Full description of state of transformer. */
|
||||
struct xfrm_state {
|
||||
possible_net_t xs_net;
|
||||
@@ -234,9 +245,9 @@ struct xfrm_state {
|
||||
/* Reference to data common to all the instances of this
|
||||
* transformer. */
|
||||
const struct xfrm_type *type;
|
||||
struct xfrm_mode *inner_mode;
|
||||
struct xfrm_mode *inner_mode_iaf;
|
||||
struct xfrm_mode *outer_mode;
|
||||
struct xfrm_mode inner_mode;
|
||||
struct xfrm_mode inner_mode_iaf;
|
||||
struct xfrm_mode outer_mode;
|
||||
|
||||
const struct xfrm_type_offload *type_offload;
|
||||
|
||||
@@ -315,13 +326,6 @@ struct xfrm_policy_afinfo {
|
||||
xfrm_address_t *saddr,
|
||||
xfrm_address_t *daddr,
|
||||
u32 mark);
|
||||
void (*decode_session)(struct sk_buff *skb,
|
||||
struct flowi *fl,
|
||||
int reverse);
|
||||
int (*get_tos)(const struct flowi *fl);
|
||||
int (*init_path)(struct xfrm_dst *path,
|
||||
struct dst_entry *dst,
|
||||
int nfheader_len);
|
||||
int (*fill_dst)(struct xfrm_dst *xdst,
|
||||
struct net_device *dev,
|
||||
const struct flowi *fl);
|
||||
@@ -347,7 +351,6 @@ struct xfrm_state_afinfo {
|
||||
struct module *owner;
|
||||
const struct xfrm_type *type_map[IPPROTO_MAX];
|
||||
const struct xfrm_type_offload *type_offload_map[IPPROTO_MAX];
|
||||
struct xfrm_mode *mode_map[XFRM_MODE_MAX];
|
||||
|
||||
int (*init_flags)(struct xfrm_state *x);
|
||||
void (*init_tempsel)(struct xfrm_selector *sel,
|
||||
@@ -422,78 +425,6 @@ struct xfrm_type_offload {
|
||||
int xfrm_register_type_offload(const struct xfrm_type_offload *type, unsigned short family);
|
||||
int xfrm_unregister_type_offload(const struct xfrm_type_offload *type, unsigned short family);
|
||||
|
||||
struct xfrm_mode {
|
||||
/*
|
||||
* Remove encapsulation header.
|
||||
*
|
||||
* The IP header will be moved over the top of the encapsulation
|
||||
* header.
|
||||
*
|
||||
* On entry, the transport header shall point to where the IP header
|
||||
* should be and the network header shall be set to where the IP
|
||||
* header currently is. skb->data shall point to the start of the
|
||||
* payload.
|
||||
*/
|
||||
int (*input2)(struct xfrm_state *x, struct sk_buff *skb);
|
||||
|
||||
/*
|
||||
* This is the actual input entry point.
|
||||
*
|
||||
* For transport mode and equivalent this would be identical to
|
||||
* input2 (which does not need to be set). While tunnel mode
|
||||
* and equivalent would set this to the tunnel encapsulation function
|
||||
* xfrm4_prepare_input that would in turn call input2.
|
||||
*/
|
||||
int (*input)(struct xfrm_state *x, struct sk_buff *skb);
|
||||
|
||||
/*
|
||||
* Add encapsulation header.
|
||||
*
|
||||
* On exit, the transport header will be set to the start of the
|
||||
* encapsulation header to be filled in by x->type->output and
|
||||
* the mac header will be set to the nextheader (protocol for
|
||||
* IPv4) field of the extension header directly preceding the
|
||||
* encapsulation header, or in its absence, that of the top IP
|
||||
* header. The value of the network header will always point
|
||||
* to the top IP header while skb->data will point to the payload.
|
||||
*/
|
||||
int (*output2)(struct xfrm_state *x,struct sk_buff *skb);
|
||||
|
||||
/*
|
||||
* This is the actual output entry point.
|
||||
*
|
||||
* For transport mode and equivalent this would be identical to
|
||||
* output2 (which does not need to be set). While tunnel mode
|
||||
* and equivalent would set this to a tunnel encapsulation function
|
||||
* (xfrm4_prepare_output or xfrm6_prepare_output) that would in turn
|
||||
* call output2.
|
||||
*/
|
||||
int (*output)(struct xfrm_state *x, struct sk_buff *skb);
|
||||
|
||||
/*
|
||||
* Adjust pointers into the packet and do GSO segmentation.
|
||||
*/
|
||||
struct sk_buff *(*gso_segment)(struct xfrm_state *x, struct sk_buff *skb, netdev_features_t features);
|
||||
|
||||
/*
|
||||
* Adjust pointers into the packet when IPsec is done at layer2.
|
||||
*/
|
||||
void (*xmit)(struct xfrm_state *x, struct sk_buff *skb);
|
||||
|
||||
struct xfrm_state_afinfo *afinfo;
|
||||
struct module *owner;
|
||||
unsigned int encap;
|
||||
int flags;
|
||||
};
|
||||
|
||||
/* Flags for xfrm_mode. */
|
||||
enum {
|
||||
XFRM_MODE_FLAG_TUNNEL = 1,
|
||||
};
|
||||
|
||||
int xfrm_register_mode(struct xfrm_mode *mode, int family);
|
||||
int xfrm_unregister_mode(struct xfrm_mode *mode, int family);
|
||||
|
||||
static inline int xfrm_af2proto(unsigned int family)
|
||||
{
|
||||
switch(family) {
|
||||
@@ -506,13 +437,13 @@ static inline int xfrm_af2proto(unsigned int family)
|
||||
}
|
||||
}
|
||||
|
||||
static inline struct xfrm_mode *xfrm_ip2inner_mode(struct xfrm_state *x, int ipproto)
|
||||
static inline const struct xfrm_mode *xfrm_ip2inner_mode(struct xfrm_state *x, int ipproto)
|
||||
{
|
||||
if ((ipproto == IPPROTO_IPIP && x->props.family == AF_INET) ||
|
||||
(ipproto == IPPROTO_IPV6 && x->props.family == AF_INET6))
|
||||
return x->inner_mode;
|
||||
return &x->inner_mode;
|
||||
else
|
||||
return x->inner_mode_iaf;
|
||||
return &x->inner_mode_iaf;
|
||||
}
|
||||
|
||||
struct xfrm_tmpl {
|
||||
@@ -1605,7 +1536,6 @@ int xfrm_init_replay(struct xfrm_state *x);
|
||||
int xfrm_state_mtu(struct xfrm_state *x, int mtu);
|
||||
int __xfrm_init_state(struct xfrm_state *x, bool init_replay, bool offload);
|
||||
int xfrm_init_state(struct xfrm_state *x);
|
||||
int xfrm_prepare_input(struct xfrm_state *x, struct sk_buff *skb);
|
||||
int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type);
|
||||
int xfrm_input_resume(struct sk_buff *skb, int nexthdr);
|
||||
int xfrm_trans_queue(struct sk_buff *skb,
|
||||
@@ -1613,7 +1543,11 @@ int xfrm_trans_queue(struct sk_buff *skb,
|
||||
struct sk_buff *));
|
||||
int xfrm_output_resume(struct sk_buff *skb, int err);
|
||||
int xfrm_output(struct sock *sk, struct sk_buff *skb);
|
||||
int xfrm_inner_extract_output(struct xfrm_state *x, struct sk_buff *skb);
|
||||
|
||||
#if IS_ENABLED(CONFIG_NET_PKTGEN)
|
||||
int pktgen_xfrm_outer_mode_output(struct xfrm_state *x, struct sk_buff *skb);
|
||||
#endif
|
||||
|
||||
void xfrm_local_error(struct sk_buff *skb, int mtu);
|
||||
int xfrm4_extract_header(struct sk_buff *skb);
|
||||
int xfrm4_extract_input(struct xfrm_state *x, struct sk_buff *skb);
|
||||
@@ -1632,10 +1566,8 @@ static inline int xfrm4_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi)
|
||||
}
|
||||
|
||||
int xfrm4_extract_output(struct xfrm_state *x, struct sk_buff *skb);
|
||||
int xfrm4_prepare_output(struct xfrm_state *x, struct sk_buff *skb);
|
||||
int xfrm4_output(struct net *net, struct sock *sk, struct sk_buff *skb);
|
||||
int xfrm4_output_finish(struct sock *sk, struct sk_buff *skb);
|
||||
int xfrm4_rcv_cb(struct sk_buff *skb, u8 protocol, int err);
|
||||
int xfrm4_protocol_register(struct xfrm4_protocol *handler, unsigned char protocol);
|
||||
int xfrm4_protocol_deregister(struct xfrm4_protocol *handler, unsigned char protocol);
|
||||
int xfrm4_tunnel_register(struct xfrm_tunnel *handler, unsigned short family);
|
||||
@@ -1651,7 +1583,6 @@ int xfrm6_rcv(struct sk_buff *skb);
|
||||
int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
|
||||
xfrm_address_t *saddr, u8 proto);
|
||||
void xfrm6_local_error(struct sk_buff *skb, u32 mtu);
|
||||
int xfrm6_rcv_cb(struct sk_buff *skb, u8 protocol, int err);
|
||||
int xfrm6_protocol_register(struct xfrm6_protocol *handler, unsigned char protocol);
|
||||
int xfrm6_protocol_deregister(struct xfrm6_protocol *handler, unsigned char protocol);
|
||||
int xfrm6_tunnel_register(struct xfrm6_tunnel *handler, unsigned short family);
|
||||
@@ -1659,7 +1590,6 @@ int xfrm6_tunnel_deregister(struct xfrm6_tunnel *handler, unsigned short family)
|
||||
__be32 xfrm6_tunnel_alloc_spi(struct net *net, xfrm_address_t *saddr);
|
||||
__be32 xfrm6_tunnel_spi_lookup(struct net *net, const xfrm_address_t *saddr);
|
||||
int xfrm6_extract_output(struct xfrm_state *x, struct sk_buff *skb);
|
||||
int xfrm6_prepare_output(struct xfrm_state *x, struct sk_buff *skb);
|
||||
int xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb);
|
||||
int xfrm6_output_finish(struct sock *sk, struct sk_buff *skb);
|
||||
int xfrm6_find_1stfragopt(struct xfrm_state *x, struct sk_buff *skb,
|
||||
@@ -2051,7 +1981,7 @@ static inline int xfrm_tunnel_check(struct sk_buff *skb, struct xfrm_state *x,
|
||||
tunnel = true;
|
||||
break;
|
||||
}
|
||||
if (tunnel && !(x->outer_mode->flags & XFRM_MODE_FLAG_TUNNEL))
|
||||
if (tunnel && !(x->outer_mode.flags & XFRM_MODE_FLAG_TUNNEL))
|
||||
return -EINVAL;
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -2521,7 +2521,7 @@ static int pktgen_output_ipsec(struct sk_buff *skb, struct pktgen_dev *pkt_dev)
|
||||
skb->_skb_refdst = (unsigned long)&pkt_dev->xdst.u.dst | SKB_DST_NOREF;
|
||||
|
||||
rcu_read_lock_bh();
|
||||
err = x->outer_mode->output(x, skb);
|
||||
err = pktgen_xfrm_outer_mode_output(x, skb);
|
||||
rcu_read_unlock_bh();
|
||||
if (err) {
|
||||
XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTSTATEMODEERROR);
|
||||
|
||||
@@ -304,7 +304,7 @@ config NET_IPVTI
|
||||
tristate "Virtual (secure) IP: tunneling"
|
||||
select INET_TUNNEL
|
||||
select NET_IP_TUNNEL
|
||||
depends on INET_XFRM_MODE_TUNNEL
|
||||
select XFRM
|
||||
---help---
|
||||
Tunneling means encapsulating data of one protocol type within
|
||||
another protocol and sending it over a channel that understands the
|
||||
@@ -396,33 +396,6 @@ config INET_TUNNEL
|
||||
tristate
|
||||
default n
|
||||
|
||||
config INET_XFRM_MODE_TRANSPORT
|
||||
tristate "IP: IPsec transport mode"
|
||||
default y
|
||||
select XFRM
|
||||
---help---
|
||||
Support for IPsec transport mode.
|
||||
|
||||
If unsure, say Y.
|
||||
|
||||
config INET_XFRM_MODE_TUNNEL
|
||||
tristate "IP: IPsec tunnel mode"
|
||||
default y
|
||||
select XFRM
|
||||
---help---
|
||||
Support for IPsec tunnel mode.
|
||||
|
||||
If unsure, say Y.
|
||||
|
||||
config INET_XFRM_MODE_BEET
|
||||
tristate "IP: IPsec BEET mode"
|
||||
default y
|
||||
select XFRM
|
||||
---help---
|
||||
Support for IPsec BEET mode.
|
||||
|
||||
If unsure, say Y.
|
||||
|
||||
config INET_DIAG
|
||||
tristate "INET: socket monitoring interface"
|
||||
default y
|
||||
|
||||
@@ -37,10 +37,7 @@ obj-$(CONFIG_INET_ESP) += esp4.o
|
||||
obj-$(CONFIG_INET_ESP_OFFLOAD) += esp4_offload.o
|
||||
obj-$(CONFIG_INET_IPCOMP) += ipcomp.o
|
||||
obj-$(CONFIG_INET_XFRM_TUNNEL) += xfrm4_tunnel.o
|
||||
obj-$(CONFIG_INET_XFRM_MODE_BEET) += xfrm4_mode_beet.o
|
||||
obj-$(CONFIG_INET_TUNNEL) += tunnel4.o
|
||||
obj-$(CONFIG_INET_XFRM_MODE_TRANSPORT) += xfrm4_mode_transport.o
|
||||
obj-$(CONFIG_INET_XFRM_MODE_TUNNEL) += xfrm4_mode_tunnel.o
|
||||
obj-$(CONFIG_IP_PNP) += ipconfig.o
|
||||
obj-$(CONFIG_NETFILTER) += netfilter.o netfilter/
|
||||
obj-$(CONFIG_INET_DIAG) += inet_diag.o
|
||||
|
||||
@@ -107,6 +107,44 @@ static void esp4_gso_encap(struct xfrm_state *x, struct sk_buff *skb)
|
||||
xo->proto = proto;
|
||||
}
|
||||
|
||||
static struct sk_buff *xfrm4_tunnel_gso_segment(struct xfrm_state *x,
|
||||
struct sk_buff *skb,
|
||||
netdev_features_t features)
|
||||
{
|
||||
__skb_push(skb, skb->mac_len);
|
||||
return skb_mac_gso_segment(skb, features);
|
||||
}
|
||||
|
||||
static struct sk_buff *xfrm4_transport_gso_segment(struct xfrm_state *x,
|
||||
struct sk_buff *skb,
|
||||
netdev_features_t features)
|
||||
{
|
||||
const struct net_offload *ops;
|
||||
struct sk_buff *segs = ERR_PTR(-EINVAL);
|
||||
struct xfrm_offload *xo = xfrm_offload(skb);
|
||||
|
||||
skb->transport_header += x->props.header_len;
|
||||
ops = rcu_dereference(inet_offloads[xo->proto]);
|
||||
if (likely(ops && ops->callbacks.gso_segment))
|
||||
segs = ops->callbacks.gso_segment(skb, features);
|
||||
|
||||
return segs;
|
||||
}
|
||||
|
||||
static struct sk_buff *xfrm4_outer_mode_gso_segment(struct xfrm_state *x,
|
||||
struct sk_buff *skb,
|
||||
netdev_features_t features)
|
||||
{
|
||||
switch (x->outer_mode.encap) {
|
||||
case XFRM_MODE_TUNNEL:
|
||||
return xfrm4_tunnel_gso_segment(x, skb, features);
|
||||
case XFRM_MODE_TRANSPORT:
|
||||
return xfrm4_transport_gso_segment(x, skb, features);
|
||||
}
|
||||
|
||||
return ERR_PTR(-EOPNOTSUPP);
|
||||
}
|
||||
|
||||
static struct sk_buff *esp4_gso_segment(struct sk_buff *skb,
|
||||
netdev_features_t features)
|
||||
{
|
||||
@@ -138,14 +176,16 @@ static struct sk_buff *esp4_gso_segment(struct sk_buff *skb,
|
||||
|
||||
skb->encap_hdr_csum = 1;
|
||||
|
||||
if (!(features & NETIF_F_HW_ESP) || x->xso.dev != skb->dev)
|
||||
if ((!(skb->dev->gso_partial_features & NETIF_F_HW_ESP) &&
|
||||
!(features & NETIF_F_HW_ESP)) || x->xso.dev != skb->dev)
|
||||
esp_features = features & ~(NETIF_F_SG | NETIF_F_CSUM_MASK);
|
||||
else if (!(features & NETIF_F_HW_ESP_TX_CSUM))
|
||||
else if (!(features & NETIF_F_HW_ESP_TX_CSUM) &&
|
||||
!(skb->dev->gso_partial_features & NETIF_F_HW_ESP_TX_CSUM))
|
||||
esp_features = features & ~NETIF_F_CSUM_MASK;
|
||||
|
||||
xo->flags |= XFRM_GSO_SEGMENT;
|
||||
|
||||
return x->outer_mode->gso_segment(x, skb, esp_features);
|
||||
return xfrm4_outer_mode_gso_segment(x, skb, esp_features);
|
||||
}
|
||||
|
||||
static int esp_input_tail(struct xfrm_state *x, struct sk_buff *skb)
|
||||
@@ -181,7 +221,9 @@ static int esp_xmit(struct xfrm_state *x, struct sk_buff *skb, netdev_features_
|
||||
if (!xo)
|
||||
return -EINVAL;
|
||||
|
||||
if (!(features & NETIF_F_HW_ESP) || x->xso.dev != skb->dev) {
|
||||
if ((!(features & NETIF_F_HW_ESP) &&
|
||||
!(skb->dev->gso_partial_features & NETIF_F_HW_ESP)) ||
|
||||
x->xso.dev != skb->dev) {
|
||||
xo->flags |= CRYPTO_FALLBACK;
|
||||
hw_offload = false;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ static unsigned int vti_net_id __read_mostly;
|
||||
static int vti_tunnel_init(struct net_device *dev);
|
||||
|
||||
static int vti_input(struct sk_buff *skb, int nexthdr, __be32 spi,
|
||||
int encap_type)
|
||||
int encap_type, bool update_skb_dev)
|
||||
{
|
||||
struct ip_tunnel *tunnel;
|
||||
const struct iphdr *iph = ip_hdr(skb);
|
||||
@@ -65,32 +65,8 @@ static int vti_input(struct sk_buff *skb, int nexthdr, __be32 spi,
|
||||
|
||||
XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip4 = tunnel;
|
||||
|
||||
return xfrm_input(skb, nexthdr, spi, encap_type);
|
||||
}
|
||||
|
||||
return -EINVAL;
|
||||
drop:
|
||||
kfree_skb(skb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vti_input_ipip(struct sk_buff *skb, int nexthdr, __be32 spi,
|
||||
int encap_type)
|
||||
{
|
||||
struct ip_tunnel *tunnel;
|
||||
const struct iphdr *iph = ip_hdr(skb);
|
||||
struct net *net = dev_net(skb->dev);
|
||||
struct ip_tunnel_net *itn = net_generic(net, vti_net_id);
|
||||
|
||||
tunnel = ip_tunnel_lookup(itn, skb->dev->ifindex, TUNNEL_NO_KEY,
|
||||
iph->saddr, iph->daddr, 0);
|
||||
if (tunnel) {
|
||||
if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb))
|
||||
goto drop;
|
||||
|
||||
XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip4 = tunnel;
|
||||
|
||||
skb->dev = tunnel->dev;
|
||||
if (update_skb_dev)
|
||||
skb->dev = tunnel->dev;
|
||||
|
||||
return xfrm_input(skb, nexthdr, spi, encap_type);
|
||||
}
|
||||
@@ -101,20 +77,28 @@ drop:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vti_rcv(struct sk_buff *skb)
|
||||
static int vti_input_proto(struct sk_buff *skb, int nexthdr, __be32 spi,
|
||||
int encap_type)
|
||||
{
|
||||
XFRM_SPI_SKB_CB(skb)->family = AF_INET;
|
||||
XFRM_SPI_SKB_CB(skb)->daddroff = offsetof(struct iphdr, daddr);
|
||||
|
||||
return vti_input(skb, ip_hdr(skb)->protocol, 0, 0);
|
||||
return vti_input(skb, nexthdr, spi, encap_type, false);
|
||||
}
|
||||
|
||||
static int vti_rcv_ipip(struct sk_buff *skb)
|
||||
static int vti_rcv(struct sk_buff *skb, __be32 spi, bool update_skb_dev)
|
||||
{
|
||||
XFRM_SPI_SKB_CB(skb)->family = AF_INET;
|
||||
XFRM_SPI_SKB_CB(skb)->daddroff = offsetof(struct iphdr, daddr);
|
||||
|
||||
return vti_input_ipip(skb, ip_hdr(skb)->protocol, ip_hdr(skb)->saddr, 0);
|
||||
return vti_input(skb, ip_hdr(skb)->protocol, spi, 0, update_skb_dev);
|
||||
}
|
||||
|
||||
static int vti_rcv_proto(struct sk_buff *skb)
|
||||
{
|
||||
return vti_rcv(skb, 0, false);
|
||||
}
|
||||
|
||||
static int vti_rcv_tunnel(struct sk_buff *skb)
|
||||
{
|
||||
return vti_rcv(skb, ip_hdr(skb)->saddr, true);
|
||||
}
|
||||
|
||||
static int vti_rcv_cb(struct sk_buff *skb, int err)
|
||||
@@ -123,7 +107,7 @@ static int vti_rcv_cb(struct sk_buff *skb, int err)
|
||||
struct net_device *dev;
|
||||
struct pcpu_sw_netstats *tstats;
|
||||
struct xfrm_state *x;
|
||||
struct xfrm_mode *inner_mode;
|
||||
const struct xfrm_mode *inner_mode;
|
||||
struct ip_tunnel *tunnel = XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip4;
|
||||
u32 orig_mark = skb->mark;
|
||||
int ret;
|
||||
@@ -142,7 +126,7 @@ static int vti_rcv_cb(struct sk_buff *skb, int err)
|
||||
|
||||
x = xfrm_input_state(skb);
|
||||
|
||||
inner_mode = x->inner_mode;
|
||||
inner_mode = &x->inner_mode;
|
||||
|
||||
if (x->sel.family == AF_UNSPEC) {
|
||||
inner_mode = xfrm_ip2inner_mode(x, XFRM_MODE_SKB_CB(skb)->protocol);
|
||||
@@ -153,7 +137,7 @@ static int vti_rcv_cb(struct sk_buff *skb, int err)
|
||||
}
|
||||
}
|
||||
|
||||
family = inner_mode->afinfo->family;
|
||||
family = inner_mode->family;
|
||||
|
||||
skb->mark = be32_to_cpu(tunnel->parms.i_key);
|
||||
ret = xfrm_policy_check(NULL, XFRM_POLICY_IN, skb, family);
|
||||
@@ -447,31 +431,31 @@ static void __net_init vti_fb_tunnel_init(struct net_device *dev)
|
||||
}
|
||||
|
||||
static struct xfrm4_protocol vti_esp4_protocol __read_mostly = {
|
||||
.handler = vti_rcv,
|
||||
.input_handler = vti_input,
|
||||
.handler = vti_rcv_proto,
|
||||
.input_handler = vti_input_proto,
|
||||
.cb_handler = vti_rcv_cb,
|
||||
.err_handler = vti4_err,
|
||||
.priority = 100,
|
||||
};
|
||||
|
||||
static struct xfrm4_protocol vti_ah4_protocol __read_mostly = {
|
||||
.handler = vti_rcv,
|
||||
.input_handler = vti_input,
|
||||
.handler = vti_rcv_proto,
|
||||
.input_handler = vti_input_proto,
|
||||
.cb_handler = vti_rcv_cb,
|
||||
.err_handler = vti4_err,
|
||||
.priority = 100,
|
||||
};
|
||||
|
||||
static struct xfrm4_protocol vti_ipcomp4_protocol __read_mostly = {
|
||||
.handler = vti_rcv,
|
||||
.input_handler = vti_input,
|
||||
.handler = vti_rcv_proto,
|
||||
.input_handler = vti_input_proto,
|
||||
.cb_handler = vti_rcv_cb,
|
||||
.err_handler = vti4_err,
|
||||
.priority = 100,
|
||||
};
|
||||
|
||||
static struct xfrm_tunnel ipip_handler __read_mostly = {
|
||||
.handler = vti_rcv_ipip,
|
||||
.handler = vti_rcv_tunnel,
|
||||
.err_handler = vti4_err,
|
||||
.priority = 0,
|
||||
};
|
||||
|
||||
@@ -1,155 +0,0 @@
|
||||
/*
|
||||
* xfrm4_mode_beet.c - BEET mode encapsulation for IPv4.
|
||||
*
|
||||
* Copyright (c) 2006 Diego Beltrami <diego.beltrami@gmail.com>
|
||||
* Miika Komu <miika@iki.fi>
|
||||
* Herbert Xu <herbert@gondor.apana.org.au>
|
||||
* Abhinav Pathak <abhinav.pathak@hiit.fi>
|
||||
* Jeff Ahrenholz <ahrenholz@gmail.com>
|
||||
*/
|
||||
|
||||
#include <linux/init.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/stringify.h>
|
||||
#include <net/dst.h>
|
||||
#include <net/ip.h>
|
||||
#include <net/xfrm.h>
|
||||
|
||||
static void xfrm4_beet_make_header(struct sk_buff *skb)
|
||||
{
|
||||
struct iphdr *iph = ip_hdr(skb);
|
||||
|
||||
iph->ihl = 5;
|
||||
iph->version = 4;
|
||||
|
||||
iph->protocol = XFRM_MODE_SKB_CB(skb)->protocol;
|
||||
iph->tos = XFRM_MODE_SKB_CB(skb)->tos;
|
||||
|
||||
iph->id = XFRM_MODE_SKB_CB(skb)->id;
|
||||
iph->frag_off = XFRM_MODE_SKB_CB(skb)->frag_off;
|
||||
iph->ttl = XFRM_MODE_SKB_CB(skb)->ttl;
|
||||
}
|
||||
|
||||
/* Add encapsulation header.
|
||||
*
|
||||
* The top IP header will be constructed per draft-nikander-esp-beet-mode-06.txt.
|
||||
*/
|
||||
static int xfrm4_beet_output(struct xfrm_state *x, struct sk_buff *skb)
|
||||
{
|
||||
struct ip_beet_phdr *ph;
|
||||
struct iphdr *top_iph;
|
||||
int hdrlen, optlen;
|
||||
|
||||
hdrlen = 0;
|
||||
optlen = XFRM_MODE_SKB_CB(skb)->optlen;
|
||||
if (unlikely(optlen))
|
||||
hdrlen += IPV4_BEET_PHMAXLEN - (optlen & 4);
|
||||
|
||||
skb_set_network_header(skb, -x->props.header_len -
|
||||
hdrlen + (XFRM_MODE_SKB_CB(skb)->ihl - sizeof(*top_iph)));
|
||||
if (x->sel.family != AF_INET6)
|
||||
skb->network_header += IPV4_BEET_PHMAXLEN;
|
||||
skb->mac_header = skb->network_header +
|
||||
offsetof(struct iphdr, protocol);
|
||||
skb->transport_header = skb->network_header + sizeof(*top_iph);
|
||||
|
||||
xfrm4_beet_make_header(skb);
|
||||
|
||||
ph = __skb_pull(skb, XFRM_MODE_SKB_CB(skb)->ihl - hdrlen);
|
||||
|
||||
top_iph = ip_hdr(skb);
|
||||
|
||||
if (unlikely(optlen)) {
|
||||
BUG_ON(optlen < 0);
|
||||
|
||||
ph->padlen = 4 - (optlen & 4);
|
||||
ph->hdrlen = optlen / 8;
|
||||
ph->nexthdr = top_iph->protocol;
|
||||
if (ph->padlen)
|
||||
memset(ph + 1, IPOPT_NOP, ph->padlen);
|
||||
|
||||
top_iph->protocol = IPPROTO_BEETPH;
|
||||
top_iph->ihl = sizeof(struct iphdr) / 4;
|
||||
}
|
||||
|
||||
top_iph->saddr = x->props.saddr.a4;
|
||||
top_iph->daddr = x->id.daddr.a4;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int xfrm4_beet_input(struct xfrm_state *x, struct sk_buff *skb)
|
||||
{
|
||||
struct iphdr *iph;
|
||||
int optlen = 0;
|
||||
int err = -EINVAL;
|
||||
|
||||
if (unlikely(XFRM_MODE_SKB_CB(skb)->protocol == IPPROTO_BEETPH)) {
|
||||
struct ip_beet_phdr *ph;
|
||||
int phlen;
|
||||
|
||||
if (!pskb_may_pull(skb, sizeof(*ph)))
|
||||
goto out;
|
||||
|
||||
ph = (struct ip_beet_phdr *)skb->data;
|
||||
|
||||
phlen = sizeof(*ph) + ph->padlen;
|
||||
optlen = ph->hdrlen * 8 + (IPV4_BEET_PHMAXLEN - phlen);
|
||||
if (optlen < 0 || optlen & 3 || optlen > 250)
|
||||
goto out;
|
||||
|
||||
XFRM_MODE_SKB_CB(skb)->protocol = ph->nexthdr;
|
||||
|
||||
if (!pskb_may_pull(skb, phlen))
|
||||
goto out;
|
||||
__skb_pull(skb, phlen);
|
||||
}
|
||||
|
||||
skb_push(skb, sizeof(*iph));
|
||||
skb_reset_network_header(skb);
|
||||
skb_mac_header_rebuild(skb);
|
||||
|
||||
xfrm4_beet_make_header(skb);
|
||||
|
||||
iph = ip_hdr(skb);
|
||||
|
||||
iph->ihl += optlen / 4;
|
||||
iph->tot_len = htons(skb->len);
|
||||
iph->daddr = x->sel.daddr.a4;
|
||||
iph->saddr = x->sel.saddr.a4;
|
||||
iph->check = 0;
|
||||
iph->check = ip_fast_csum(skb_network_header(skb), iph->ihl);
|
||||
err = 0;
|
||||
out:
|
||||
return err;
|
||||
}
|
||||
|
||||
static struct xfrm_mode xfrm4_beet_mode = {
|
||||
.input2 = xfrm4_beet_input,
|
||||
.input = xfrm_prepare_input,
|
||||
.output2 = xfrm4_beet_output,
|
||||
.output = xfrm4_prepare_output,
|
||||
.owner = THIS_MODULE,
|
||||
.encap = XFRM_MODE_BEET,
|
||||
.flags = XFRM_MODE_FLAG_TUNNEL,
|
||||
};
|
||||
|
||||
static int __init xfrm4_beet_init(void)
|
||||
{
|
||||
return xfrm_register_mode(&xfrm4_beet_mode, AF_INET);
|
||||
}
|
||||
|
||||
static void __exit xfrm4_beet_exit(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = xfrm_unregister_mode(&xfrm4_beet_mode, AF_INET);
|
||||
BUG_ON(err);
|
||||
}
|
||||
|
||||
module_init(xfrm4_beet_init);
|
||||
module_exit(xfrm4_beet_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_ALIAS_XFRM_MODE(AF_INET, XFRM_MODE_BEET);
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* xfrm4_mode_transport.c - Transport mode encapsulation for IPv4.
|
||||
*
|
||||
* Copyright (c) 2004-2006 Herbert Xu <herbert@gondor.apana.org.au>
|
||||
*/
|
||||
|
||||
#include <linux/init.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/stringify.h>
|
||||
#include <net/dst.h>
|
||||
#include <net/ip.h>
|
||||
#include <net/xfrm.h>
|
||||
#include <net/protocol.h>
|
||||
|
||||
/* Add encapsulation header.
|
||||
*
|
||||
* The IP header will be moved forward to make space for the encapsulation
|
||||
* header.
|
||||
*/
|
||||
static int xfrm4_transport_output(struct xfrm_state *x, struct sk_buff *skb)
|
||||
{
|
||||
struct iphdr *iph = ip_hdr(skb);
|
||||
int ihl = iph->ihl * 4;
|
||||
|
||||
skb_set_inner_transport_header(skb, skb_transport_offset(skb));
|
||||
|
||||
skb_set_network_header(skb, -x->props.header_len);
|
||||
skb->mac_header = skb->network_header +
|
||||
offsetof(struct iphdr, protocol);
|
||||
skb->transport_header = skb->network_header + ihl;
|
||||
__skb_pull(skb, ihl);
|
||||
memmove(skb_network_header(skb), iph, ihl);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Remove encapsulation header.
|
||||
*
|
||||
* The IP header will be moved over the top of the encapsulation header.
|
||||
*
|
||||
* On entry, skb->h shall point to where the IP header should be and skb->nh
|
||||
* shall be set to where the IP header currently is. skb->data shall point
|
||||
* to the start of the payload.
|
||||
*/
|
||||
static int xfrm4_transport_input(struct xfrm_state *x, struct sk_buff *skb)
|
||||
{
|
||||
int ihl = skb->data - skb_transport_header(skb);
|
||||
|
||||
if (skb->transport_header != skb->network_header) {
|
||||
memmove(skb_transport_header(skb),
|
||||
skb_network_header(skb), ihl);
|
||||
skb->network_header = skb->transport_header;
|
||||
}
|
||||
ip_hdr(skb)->tot_len = htons(skb->len + ihl);
|
||||
skb_reset_transport_header(skb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct sk_buff *xfrm4_transport_gso_segment(struct xfrm_state *x,
|
||||
struct sk_buff *skb,
|
||||
netdev_features_t features)
|
||||
{
|
||||
const struct net_offload *ops;
|
||||
struct sk_buff *segs = ERR_PTR(-EINVAL);
|
||||
struct xfrm_offload *xo = xfrm_offload(skb);
|
||||
|
||||
skb->transport_header += x->props.header_len;
|
||||
ops = rcu_dereference(inet_offloads[xo->proto]);
|
||||
if (likely(ops && ops->callbacks.gso_segment))
|
||||
segs = ops->callbacks.gso_segment(skb, features);
|
||||
|
||||
return segs;
|
||||
}
|
||||
|
||||
static void xfrm4_transport_xmit(struct xfrm_state *x, struct sk_buff *skb)
|
||||
{
|
||||
struct xfrm_offload *xo = xfrm_offload(skb);
|
||||
|
||||
skb_reset_mac_len(skb);
|
||||
pskb_pull(skb, skb->mac_len + sizeof(struct iphdr) + x->props.header_len);
|
||||
|
||||
if (xo->flags & XFRM_GSO_SEGMENT) {
|
||||
skb_reset_transport_header(skb);
|
||||
skb->transport_header -= x->props.header_len;
|
||||
}
|
||||
}
|
||||
|
||||
static struct xfrm_mode xfrm4_transport_mode = {
|
||||
.input = xfrm4_transport_input,
|
||||
.output = xfrm4_transport_output,
|
||||
.gso_segment = xfrm4_transport_gso_segment,
|
||||
.xmit = xfrm4_transport_xmit,
|
||||
.owner = THIS_MODULE,
|
||||
.encap = XFRM_MODE_TRANSPORT,
|
||||
};
|
||||
|
||||
static int __init xfrm4_transport_init(void)
|
||||
{
|
||||
return xfrm_register_mode(&xfrm4_transport_mode, AF_INET);
|
||||
}
|
||||
|
||||
static void __exit xfrm4_transport_exit(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = xfrm_unregister_mode(&xfrm4_transport_mode, AF_INET);
|
||||
BUG_ON(err);
|
||||
}
|
||||
|
||||
module_init(xfrm4_transport_init);
|
||||
module_exit(xfrm4_transport_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_ALIAS_XFRM_MODE(AF_INET, XFRM_MODE_TRANSPORT);
|
||||
@@ -1,152 +0,0 @@
|
||||
/*
|
||||
* xfrm4_mode_tunnel.c - Tunnel mode encapsulation for IPv4.
|
||||
*
|
||||
* Copyright (c) 2004-2006 Herbert Xu <herbert@gondor.apana.org.au>
|
||||
*/
|
||||
|
||||
#include <linux/gfp.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/stringify.h>
|
||||
#include <net/dst.h>
|
||||
#include <net/inet_ecn.h>
|
||||
#include <net/ip.h>
|
||||
#include <net/xfrm.h>
|
||||
|
||||
static inline void ipip_ecn_decapsulate(struct sk_buff *skb)
|
||||
{
|
||||
struct iphdr *inner_iph = ipip_hdr(skb);
|
||||
|
||||
if (INET_ECN_is_ce(XFRM_MODE_SKB_CB(skb)->tos))
|
||||
IP_ECN_set_ce(inner_iph);
|
||||
}
|
||||
|
||||
/* Add encapsulation header.
|
||||
*
|
||||
* The top IP header will be constructed per RFC 2401.
|
||||
*/
|
||||
static int xfrm4_mode_tunnel_output(struct xfrm_state *x, struct sk_buff *skb)
|
||||
{
|
||||
struct dst_entry *dst = skb_dst(skb);
|
||||
struct iphdr *top_iph;
|
||||
int flags;
|
||||
|
||||
skb_set_inner_network_header(skb, skb_network_offset(skb));
|
||||
skb_set_inner_transport_header(skb, skb_transport_offset(skb));
|
||||
|
||||
skb_set_network_header(skb, -x->props.header_len);
|
||||
skb->mac_header = skb->network_header +
|
||||
offsetof(struct iphdr, protocol);
|
||||
skb->transport_header = skb->network_header + sizeof(*top_iph);
|
||||
top_iph = ip_hdr(skb);
|
||||
|
||||
top_iph->ihl = 5;
|
||||
top_iph->version = 4;
|
||||
|
||||
top_iph->protocol = xfrm_af2proto(skb_dst(skb)->ops->family);
|
||||
|
||||
/* DS disclosing depends on XFRM_SA_XFLAG_DONT_ENCAP_DSCP */
|
||||
if (x->props.extra_flags & XFRM_SA_XFLAG_DONT_ENCAP_DSCP)
|
||||
top_iph->tos = 0;
|
||||
else
|
||||
top_iph->tos = XFRM_MODE_SKB_CB(skb)->tos;
|
||||
top_iph->tos = INET_ECN_encapsulate(top_iph->tos,
|
||||
XFRM_MODE_SKB_CB(skb)->tos);
|
||||
|
||||
flags = x->props.flags;
|
||||
if (flags & XFRM_STATE_NOECN)
|
||||
IP_ECN_clear(top_iph);
|
||||
|
||||
top_iph->frag_off = (flags & XFRM_STATE_NOPMTUDISC) ?
|
||||
0 : (XFRM_MODE_SKB_CB(skb)->frag_off & htons(IP_DF));
|
||||
|
||||
top_iph->ttl = ip4_dst_hoplimit(xfrm_dst_child(dst));
|
||||
|
||||
top_iph->saddr = x->props.saddr.a4;
|
||||
top_iph->daddr = x->id.daddr.a4;
|
||||
ip_select_ident(dev_net(dst->dev), skb, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int xfrm4_mode_tunnel_input(struct xfrm_state *x, struct sk_buff *skb)
|
||||
{
|
||||
int err = -EINVAL;
|
||||
|
||||
if (XFRM_MODE_SKB_CB(skb)->protocol != IPPROTO_IPIP)
|
||||
goto out;
|
||||
|
||||
if (!pskb_may_pull(skb, sizeof(struct iphdr)))
|
||||
goto out;
|
||||
|
||||
err = skb_unclone(skb, GFP_ATOMIC);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
if (x->props.flags & XFRM_STATE_DECAP_DSCP)
|
||||
ipv4_copy_dscp(XFRM_MODE_SKB_CB(skb)->tos, ipip_hdr(skb));
|
||||
if (!(x->props.flags & XFRM_STATE_NOECN))
|
||||
ipip_ecn_decapsulate(skb);
|
||||
|
||||
skb_reset_network_header(skb);
|
||||
skb_mac_header_rebuild(skb);
|
||||
if (skb->mac_len)
|
||||
eth_hdr(skb)->h_proto = skb->protocol;
|
||||
|
||||
err = 0;
|
||||
|
||||
out:
|
||||
return err;
|
||||
}
|
||||
|
||||
static struct sk_buff *xfrm4_mode_tunnel_gso_segment(struct xfrm_state *x,
|
||||
struct sk_buff *skb,
|
||||
netdev_features_t features)
|
||||
{
|
||||
__skb_push(skb, skb->mac_len);
|
||||
return skb_mac_gso_segment(skb, features);
|
||||
}
|
||||
|
||||
static void xfrm4_mode_tunnel_xmit(struct xfrm_state *x, struct sk_buff *skb)
|
||||
{
|
||||
struct xfrm_offload *xo = xfrm_offload(skb);
|
||||
|
||||
if (xo->flags & XFRM_GSO_SEGMENT)
|
||||
skb->transport_header = skb->network_header +
|
||||
sizeof(struct iphdr);
|
||||
|
||||
skb_reset_mac_len(skb);
|
||||
pskb_pull(skb, skb->mac_len + x->props.header_len);
|
||||
}
|
||||
|
||||
static struct xfrm_mode xfrm4_tunnel_mode = {
|
||||
.input2 = xfrm4_mode_tunnel_input,
|
||||
.input = xfrm_prepare_input,
|
||||
.output2 = xfrm4_mode_tunnel_output,
|
||||
.output = xfrm4_prepare_output,
|
||||
.gso_segment = xfrm4_mode_tunnel_gso_segment,
|
||||
.xmit = xfrm4_mode_tunnel_xmit,
|
||||
.owner = THIS_MODULE,
|
||||
.encap = XFRM_MODE_TUNNEL,
|
||||
.flags = XFRM_MODE_FLAG_TUNNEL,
|
||||
};
|
||||
|
||||
static int __init xfrm4_mode_tunnel_init(void)
|
||||
{
|
||||
return xfrm_register_mode(&xfrm4_tunnel_mode, AF_INET);
|
||||
}
|
||||
|
||||
static void __exit xfrm4_mode_tunnel_exit(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = xfrm_unregister_mode(&xfrm4_tunnel_mode, AF_INET);
|
||||
BUG_ON(err);
|
||||
}
|
||||
|
||||
module_init(xfrm4_mode_tunnel_init);
|
||||
module_exit(xfrm4_mode_tunnel_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_ALIAS_XFRM_MODE(AF_INET, XFRM_MODE_TUNNEL);
|
||||
@@ -58,21 +58,6 @@ int xfrm4_extract_output(struct xfrm_state *x, struct sk_buff *skb)
|
||||
return xfrm4_extract_header(skb);
|
||||
}
|
||||
|
||||
int xfrm4_prepare_output(struct xfrm_state *x, struct sk_buff *skb)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = xfrm_inner_extract_output(x, skb);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
IPCB(skb)->flags |= IPSKB_XFRM_TUNNEL_SIZE;
|
||||
skb->protocol = htons(ETH_P_IP);
|
||||
|
||||
return x->outer_mode->output2(x, skb);
|
||||
}
|
||||
EXPORT_SYMBOL(xfrm4_prepare_output);
|
||||
|
||||
int xfrm4_output_finish(struct sock *sk, struct sk_buff *skb)
|
||||
{
|
||||
memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
|
||||
@@ -87,6 +72,8 @@ int xfrm4_output_finish(struct sock *sk, struct sk_buff *skb)
|
||||
static int __xfrm4_output(struct net *net, struct sock *sk, struct sk_buff *skb)
|
||||
{
|
||||
struct xfrm_state *x = skb_dst(skb)->xfrm;
|
||||
const struct xfrm_state_afinfo *afinfo;
|
||||
int ret = -EAFNOSUPPORT;
|
||||
|
||||
#ifdef CONFIG_NETFILTER
|
||||
if (!x) {
|
||||
@@ -95,7 +82,15 @@ static int __xfrm4_output(struct net *net, struct sock *sk, struct sk_buff *skb)
|
||||
}
|
||||
#endif
|
||||
|
||||
return x->outer_mode->afinfo->output_finish(sk, skb);
|
||||
rcu_read_lock();
|
||||
afinfo = xfrm_state_afinfo_get_rcu(x->outer_mode.family);
|
||||
if (likely(afinfo))
|
||||
ret = afinfo->output_finish(sk, skb);
|
||||
else
|
||||
kfree_skb(skb);
|
||||
rcu_read_unlock();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int xfrm4_output(struct net *net, struct sock *sk, struct sk_buff *skb)
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include <linux/err.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/inetdevice.h>
|
||||
#include <linux/if_tunnel.h>
|
||||
#include <net/dst.h>
|
||||
#include <net/xfrm.h>
|
||||
#include <net/ip.h>
|
||||
@@ -69,17 +68,6 @@ static int xfrm4_get_saddr(struct net *net, int oif,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int xfrm4_get_tos(const struct flowi *fl)
|
||||
{
|
||||
return IPTOS_RT_MASK & fl->u.ip4.flowi4_tos; /* Strip ECN bits */
|
||||
}
|
||||
|
||||
static int xfrm4_init_path(struct xfrm_dst *path, struct dst_entry *dst,
|
||||
int nfheader_len)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int xfrm4_fill_dst(struct xfrm_dst *xdst, struct net_device *dev,
|
||||
const struct flowi *fl)
|
||||
{
|
||||
@@ -110,118 +98,6 @@ static int xfrm4_fill_dst(struct xfrm_dst *xdst, struct net_device *dev,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
_decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
|
||||
{
|
||||
const struct iphdr *iph = ip_hdr(skb);
|
||||
u8 *xprth = skb_network_header(skb) + iph->ihl * 4;
|
||||
struct flowi4 *fl4 = &fl->u.ip4;
|
||||
int oif = 0;
|
||||
|
||||
if (skb_dst(skb))
|
||||
oif = skb_dst(skb)->dev->ifindex;
|
||||
|
||||
memset(fl4, 0, sizeof(struct flowi4));
|
||||
fl4->flowi4_mark = skb->mark;
|
||||
fl4->flowi4_oif = reverse ? skb->skb_iif : oif;
|
||||
|
||||
if (!ip_is_fragment(iph)) {
|
||||
switch (iph->protocol) {
|
||||
case IPPROTO_UDP:
|
||||
case IPPROTO_UDPLITE:
|
||||
case IPPROTO_TCP:
|
||||
case IPPROTO_SCTP:
|
||||
case IPPROTO_DCCP:
|
||||
if (xprth + 4 < skb->data ||
|
||||
pskb_may_pull(skb, xprth + 4 - skb->data)) {
|
||||
__be16 *ports;
|
||||
|
||||
xprth = skb_network_header(skb) + iph->ihl * 4;
|
||||
ports = (__be16 *)xprth;
|
||||
|
||||
fl4->fl4_sport = ports[!!reverse];
|
||||
fl4->fl4_dport = ports[!reverse];
|
||||
}
|
||||
break;
|
||||
|
||||
case IPPROTO_ICMP:
|
||||
if (xprth + 2 < skb->data ||
|
||||
pskb_may_pull(skb, xprth + 2 - skb->data)) {
|
||||
u8 *icmp;
|
||||
|
||||
xprth = skb_network_header(skb) + iph->ihl * 4;
|
||||
icmp = xprth;
|
||||
|
||||
fl4->fl4_icmp_type = icmp[0];
|
||||
fl4->fl4_icmp_code = icmp[1];
|
||||
}
|
||||
break;
|
||||
|
||||
case IPPROTO_ESP:
|
||||
if (xprth + 4 < skb->data ||
|
||||
pskb_may_pull(skb, xprth + 4 - skb->data)) {
|
||||
__be32 *ehdr;
|
||||
|
||||
xprth = skb_network_header(skb) + iph->ihl * 4;
|
||||
ehdr = (__be32 *)xprth;
|
||||
|
||||
fl4->fl4_ipsec_spi = ehdr[0];
|
||||
}
|
||||
break;
|
||||
|
||||
case IPPROTO_AH:
|
||||
if (xprth + 8 < skb->data ||
|
||||
pskb_may_pull(skb, xprth + 8 - skb->data)) {
|
||||
__be32 *ah_hdr;
|
||||
|
||||
xprth = skb_network_header(skb) + iph->ihl * 4;
|
||||
ah_hdr = (__be32 *)xprth;
|
||||
|
||||
fl4->fl4_ipsec_spi = ah_hdr[1];
|
||||
}
|
||||
break;
|
||||
|
||||
case IPPROTO_COMP:
|
||||
if (xprth + 4 < skb->data ||
|
||||
pskb_may_pull(skb, xprth + 4 - skb->data)) {
|
||||
__be16 *ipcomp_hdr;
|
||||
|
||||
xprth = skb_network_header(skb) + iph->ihl * 4;
|
||||
ipcomp_hdr = (__be16 *)xprth;
|
||||
|
||||
fl4->fl4_ipsec_spi = htonl(ntohs(ipcomp_hdr[1]));
|
||||
}
|
||||
break;
|
||||
|
||||
case IPPROTO_GRE:
|
||||
if (xprth + 12 < skb->data ||
|
||||
pskb_may_pull(skb, xprth + 12 - skb->data)) {
|
||||
__be16 *greflags;
|
||||
__be32 *gre_hdr;
|
||||
|
||||
xprth = skb_network_header(skb) + iph->ihl * 4;
|
||||
greflags = (__be16 *)xprth;
|
||||
gre_hdr = (__be32 *)xprth;
|
||||
|
||||
if (greflags[0] & GRE_KEY) {
|
||||
if (greflags[0] & GRE_CSUM)
|
||||
gre_hdr++;
|
||||
fl4->fl4_gre_key = gre_hdr[1];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
fl4->fl4_ipsec_spi = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fl4->flowi4_proto = iph->protocol;
|
||||
fl4->daddr = reverse ? iph->saddr : iph->daddr;
|
||||
fl4->saddr = reverse ? iph->daddr : iph->saddr;
|
||||
fl4->flowi4_tos = iph->tos;
|
||||
}
|
||||
|
||||
static void xfrm4_update_pmtu(struct dst_entry *dst, struct sock *sk,
|
||||
struct sk_buff *skb, u32 mtu)
|
||||
{
|
||||
@@ -274,9 +150,6 @@ static const struct xfrm_policy_afinfo xfrm4_policy_afinfo = {
|
||||
.dst_ops = &xfrm4_dst_ops_template,
|
||||
.dst_lookup = xfrm4_dst_lookup,
|
||||
.get_saddr = xfrm4_get_saddr,
|
||||
.decode_session = _decode_session4,
|
||||
.get_tos = xfrm4_get_tos,
|
||||
.init_path = xfrm4_init_path,
|
||||
.fill_dst = xfrm4_fill_dst,
|
||||
.blackhole_route = ipv4_blackhole_route,
|
||||
};
|
||||
|
||||
@@ -46,7 +46,7 @@ static inline struct xfrm4_protocol __rcu **proto_handlers(u8 protocol)
|
||||
handler != NULL; \
|
||||
handler = rcu_dereference(handler->next)) \
|
||||
|
||||
int xfrm4_rcv_cb(struct sk_buff *skb, u8 protocol, int err)
|
||||
static int xfrm4_rcv_cb(struct sk_buff *skb, u8 protocol, int err)
|
||||
{
|
||||
int ret;
|
||||
struct xfrm4_protocol *handler;
|
||||
@@ -61,7 +61,6 @@ int xfrm4_rcv_cb(struct sk_buff *skb, u8 protocol, int err)
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(xfrm4_rcv_cb);
|
||||
|
||||
int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi,
|
||||
int encap_type)
|
||||
|
||||
@@ -135,44 +135,11 @@ config INET6_TUNNEL
|
||||
tristate
|
||||
default n
|
||||
|
||||
config INET6_XFRM_MODE_TRANSPORT
|
||||
tristate "IPv6: IPsec transport mode"
|
||||
default IPV6
|
||||
select XFRM
|
||||
---help---
|
||||
Support for IPsec transport mode.
|
||||
|
||||
If unsure, say Y.
|
||||
|
||||
config INET6_XFRM_MODE_TUNNEL
|
||||
tristate "IPv6: IPsec tunnel mode"
|
||||
default IPV6
|
||||
select XFRM
|
||||
---help---
|
||||
Support for IPsec tunnel mode.
|
||||
|
||||
If unsure, say Y.
|
||||
|
||||
config INET6_XFRM_MODE_BEET
|
||||
tristate "IPv6: IPsec BEET mode"
|
||||
default IPV6
|
||||
select XFRM
|
||||
---help---
|
||||
Support for IPsec BEET mode.
|
||||
|
||||
If unsure, say Y.
|
||||
|
||||
config INET6_XFRM_MODE_ROUTEOPTIMIZATION
|
||||
tristate "IPv6: MIPv6 route optimization mode"
|
||||
select XFRM
|
||||
---help---
|
||||
Support for MIPv6 route optimization mode.
|
||||
|
||||
config IPV6_VTI
|
||||
tristate "Virtual (secure) IPv6: tunneling"
|
||||
select IPV6_TUNNEL
|
||||
select NET_IP_TUNNEL
|
||||
depends on INET6_XFRM_MODE_TUNNEL
|
||||
select XFRM
|
||||
---help---
|
||||
Tunneling means encapsulating data of one protocol type within
|
||||
another protocol and sending it over a channel that understands the
|
||||
|
||||
@@ -35,10 +35,6 @@ obj-$(CONFIG_INET6_ESP_OFFLOAD) += esp6_offload.o
|
||||
obj-$(CONFIG_INET6_IPCOMP) += ipcomp6.o
|
||||
obj-$(CONFIG_INET6_XFRM_TUNNEL) += xfrm6_tunnel.o
|
||||
obj-$(CONFIG_INET6_TUNNEL) += tunnel6.o
|
||||
obj-$(CONFIG_INET6_XFRM_MODE_TRANSPORT) += xfrm6_mode_transport.o
|
||||
obj-$(CONFIG_INET6_XFRM_MODE_TUNNEL) += xfrm6_mode_tunnel.o
|
||||
obj-$(CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION) += xfrm6_mode_ro.o
|
||||
obj-$(CONFIG_INET6_XFRM_MODE_BEET) += xfrm6_mode_beet.o
|
||||
obj-$(CONFIG_IPV6_MIP6) += mip6.o
|
||||
obj-$(CONFIG_IPV6_ILA) += ila/
|
||||
obj-$(CONFIG_NETFILTER) += netfilter/
|
||||
|
||||
@@ -134,6 +134,44 @@ static void esp6_gso_encap(struct xfrm_state *x, struct sk_buff *skb)
|
||||
xo->proto = proto;
|
||||
}
|
||||
|
||||
static struct sk_buff *xfrm6_tunnel_gso_segment(struct xfrm_state *x,
|
||||
struct sk_buff *skb,
|
||||
netdev_features_t features)
|
||||
{
|
||||
__skb_push(skb, skb->mac_len);
|
||||
return skb_mac_gso_segment(skb, features);
|
||||
}
|
||||
|
||||
static struct sk_buff *xfrm6_transport_gso_segment(struct xfrm_state *x,
|
||||
struct sk_buff *skb,
|
||||
netdev_features_t features)
|
||||
{
|
||||
const struct net_offload *ops;
|
||||
struct sk_buff *segs = ERR_PTR(-EINVAL);
|
||||
struct xfrm_offload *xo = xfrm_offload(skb);
|
||||
|
||||
skb->transport_header += x->props.header_len;
|
||||
ops = rcu_dereference(inet6_offloads[xo->proto]);
|
||||
if (likely(ops && ops->callbacks.gso_segment))
|
||||
segs = ops->callbacks.gso_segment(skb, features);
|
||||
|
||||
return segs;
|
||||
}
|
||||
|
||||
static struct sk_buff *xfrm6_outer_mode_gso_segment(struct xfrm_state *x,
|
||||
struct sk_buff *skb,
|
||||
netdev_features_t features)
|
||||
{
|
||||
switch (x->outer_mode.encap) {
|
||||
case XFRM_MODE_TUNNEL:
|
||||
return xfrm6_tunnel_gso_segment(x, skb, features);
|
||||
case XFRM_MODE_TRANSPORT:
|
||||
return xfrm6_transport_gso_segment(x, skb, features);
|
||||
}
|
||||
|
||||
return ERR_PTR(-EOPNOTSUPP);
|
||||
}
|
||||
|
||||
static struct sk_buff *esp6_gso_segment(struct sk_buff *skb,
|
||||
netdev_features_t features)
|
||||
{
|
||||
@@ -172,7 +210,7 @@ static struct sk_buff *esp6_gso_segment(struct sk_buff *skb,
|
||||
|
||||
xo->flags |= XFRM_GSO_SEGMENT;
|
||||
|
||||
return x->outer_mode->gso_segment(x, skb, esp_features);
|
||||
return xfrm6_outer_mode_gso_segment(x, skb, esp_features);
|
||||
}
|
||||
|
||||
static int esp6_input_tail(struct xfrm_state *x, struct sk_buff *skb)
|
||||
|
||||
@@ -342,7 +342,7 @@ static int vti6_rcv_cb(struct sk_buff *skb, int err)
|
||||
struct net_device *dev;
|
||||
struct pcpu_sw_netstats *tstats;
|
||||
struct xfrm_state *x;
|
||||
struct xfrm_mode *inner_mode;
|
||||
const struct xfrm_mode *inner_mode;
|
||||
struct ip6_tnl *t = XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip6;
|
||||
u32 orig_mark = skb->mark;
|
||||
int ret;
|
||||
@@ -361,7 +361,7 @@ static int vti6_rcv_cb(struct sk_buff *skb, int err)
|
||||
|
||||
x = xfrm_input_state(skb);
|
||||
|
||||
inner_mode = x->inner_mode;
|
||||
inner_mode = &x->inner_mode;
|
||||
|
||||
if (x->sel.family == AF_UNSPEC) {
|
||||
inner_mode = xfrm_ip2inner_mode(x, XFRM_MODE_SKB_CB(skb)->protocol);
|
||||
@@ -372,7 +372,7 @@ static int vti6_rcv_cb(struct sk_buff *skb, int err)
|
||||
}
|
||||
}
|
||||
|
||||
family = inner_mode->afinfo->family;
|
||||
family = inner_mode->family;
|
||||
|
||||
skb->mark = be32_to_cpu(t->parms.i_key);
|
||||
ret = xfrm_policy_check(NULL, XFRM_POLICY_IN, skb, family);
|
||||
|
||||
@@ -1,131 +0,0 @@
|
||||
/*
|
||||
* xfrm6_mode_beet.c - BEET mode encapsulation for IPv6.
|
||||
*
|
||||
* Copyright (c) 2006 Diego Beltrami <diego.beltrami@gmail.com>
|
||||
* Miika Komu <miika@iki.fi>
|
||||
* Herbert Xu <herbert@gondor.apana.org.au>
|
||||
* Abhinav Pathak <abhinav.pathak@hiit.fi>
|
||||
* Jeff Ahrenholz <ahrenholz@gmail.com>
|
||||
*/
|
||||
|
||||
#include <linux/init.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/stringify.h>
|
||||
#include <net/dsfield.h>
|
||||
#include <net/dst.h>
|
||||
#include <net/inet_ecn.h>
|
||||
#include <net/ipv6.h>
|
||||
#include <net/xfrm.h>
|
||||
|
||||
static void xfrm6_beet_make_header(struct sk_buff *skb)
|
||||
{
|
||||
struct ipv6hdr *iph = ipv6_hdr(skb);
|
||||
|
||||
iph->version = 6;
|
||||
|
||||
memcpy(iph->flow_lbl, XFRM_MODE_SKB_CB(skb)->flow_lbl,
|
||||
sizeof(iph->flow_lbl));
|
||||
iph->nexthdr = XFRM_MODE_SKB_CB(skb)->protocol;
|
||||
|
||||
ipv6_change_dsfield(iph, 0, XFRM_MODE_SKB_CB(skb)->tos);
|
||||
iph->hop_limit = XFRM_MODE_SKB_CB(skb)->ttl;
|
||||
}
|
||||
|
||||
/* Add encapsulation header.
|
||||
*
|
||||
* The top IP header will be constructed per draft-nikander-esp-beet-mode-06.txt.
|
||||
*/
|
||||
static int xfrm6_beet_output(struct xfrm_state *x, struct sk_buff *skb)
|
||||
{
|
||||
struct ipv6hdr *top_iph;
|
||||
struct ip_beet_phdr *ph;
|
||||
int optlen, hdr_len;
|
||||
|
||||
hdr_len = 0;
|
||||
optlen = XFRM_MODE_SKB_CB(skb)->optlen;
|
||||
if (unlikely(optlen))
|
||||
hdr_len += IPV4_BEET_PHMAXLEN - (optlen & 4);
|
||||
|
||||
skb_set_network_header(skb, -x->props.header_len - hdr_len);
|
||||
if (x->sel.family != AF_INET6)
|
||||
skb->network_header += IPV4_BEET_PHMAXLEN;
|
||||
skb->mac_header = skb->network_header +
|
||||
offsetof(struct ipv6hdr, nexthdr);
|
||||
skb->transport_header = skb->network_header + sizeof(*top_iph);
|
||||
ph = __skb_pull(skb, XFRM_MODE_SKB_CB(skb)->ihl - hdr_len);
|
||||
|
||||
xfrm6_beet_make_header(skb);
|
||||
|
||||
top_iph = ipv6_hdr(skb);
|
||||
if (unlikely(optlen)) {
|
||||
|
||||
BUG_ON(optlen < 0);
|
||||
|
||||
ph->padlen = 4 - (optlen & 4);
|
||||
ph->hdrlen = optlen / 8;
|
||||
ph->nexthdr = top_iph->nexthdr;
|
||||
if (ph->padlen)
|
||||
memset(ph + 1, IPOPT_NOP, ph->padlen);
|
||||
|
||||
top_iph->nexthdr = IPPROTO_BEETPH;
|
||||
}
|
||||
|
||||
top_iph->saddr = *(struct in6_addr *)&x->props.saddr;
|
||||
top_iph->daddr = *(struct in6_addr *)&x->id.daddr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int xfrm6_beet_input(struct xfrm_state *x, struct sk_buff *skb)
|
||||
{
|
||||
struct ipv6hdr *ip6h;
|
||||
int size = sizeof(struct ipv6hdr);
|
||||
int err;
|
||||
|
||||
err = skb_cow_head(skb, size + skb->mac_len);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
__skb_push(skb, size);
|
||||
skb_reset_network_header(skb);
|
||||
skb_mac_header_rebuild(skb);
|
||||
|
||||
xfrm6_beet_make_header(skb);
|
||||
|
||||
ip6h = ipv6_hdr(skb);
|
||||
ip6h->payload_len = htons(skb->len - size);
|
||||
ip6h->daddr = x->sel.daddr.in6;
|
||||
ip6h->saddr = x->sel.saddr.in6;
|
||||
err = 0;
|
||||
out:
|
||||
return err;
|
||||
}
|
||||
|
||||
static struct xfrm_mode xfrm6_beet_mode = {
|
||||
.input2 = xfrm6_beet_input,
|
||||
.input = xfrm_prepare_input,
|
||||
.output2 = xfrm6_beet_output,
|
||||
.output = xfrm6_prepare_output,
|
||||
.owner = THIS_MODULE,
|
||||
.encap = XFRM_MODE_BEET,
|
||||
.flags = XFRM_MODE_FLAG_TUNNEL,
|
||||
};
|
||||
|
||||
static int __init xfrm6_beet_init(void)
|
||||
{
|
||||
return xfrm_register_mode(&xfrm6_beet_mode, AF_INET6);
|
||||
}
|
||||
|
||||
static void __exit xfrm6_beet_exit(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = xfrm_unregister_mode(&xfrm6_beet_mode, AF_INET6);
|
||||
BUG_ON(err);
|
||||
}
|
||||
|
||||
module_init(xfrm6_beet_init);
|
||||
module_exit(xfrm6_beet_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_ALIAS_XFRM_MODE(AF_INET6, XFRM_MODE_BEET);
|
||||
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* xfrm6_mode_ro.c - Route optimization mode for IPv6.
|
||||
*
|
||||
* Copyright (C)2003-2006 Helsinki University of Technology
|
||||
* Copyright (C)2003-2006 USAGI/WIDE Project
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/*
|
||||
* Authors:
|
||||
* Noriaki TAKAMIYA @USAGI
|
||||
* Masahide NAKAMURA @USAGI
|
||||
*/
|
||||
|
||||
#include <linux/init.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/stringify.h>
|
||||
#include <linux/time.h>
|
||||
#include <net/ipv6.h>
|
||||
#include <net/xfrm.h>
|
||||
|
||||
/* Add route optimization header space.
|
||||
*
|
||||
* The IP header and mutable extension headers will be moved forward to make
|
||||
* space for the route optimization header.
|
||||
*/
|
||||
static int xfrm6_ro_output(struct xfrm_state *x, struct sk_buff *skb)
|
||||
{
|
||||
struct ipv6hdr *iph;
|
||||
u8 *prevhdr;
|
||||
int hdr_len;
|
||||
|
||||
iph = ipv6_hdr(skb);
|
||||
|
||||
hdr_len = x->type->hdr_offset(x, skb, &prevhdr);
|
||||
if (hdr_len < 0)
|
||||
return hdr_len;
|
||||
skb_set_mac_header(skb, (prevhdr - x->props.header_len) - skb->data);
|
||||
skb_set_network_header(skb, -x->props.header_len);
|
||||
skb->transport_header = skb->network_header + hdr_len;
|
||||
__skb_pull(skb, hdr_len);
|
||||
memmove(ipv6_hdr(skb), iph, hdr_len);
|
||||
|
||||
x->lastused = ktime_get_real_seconds();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct xfrm_mode xfrm6_ro_mode = {
|
||||
.output = xfrm6_ro_output,
|
||||
.owner = THIS_MODULE,
|
||||
.encap = XFRM_MODE_ROUTEOPTIMIZATION,
|
||||
};
|
||||
|
||||
static int __init xfrm6_ro_init(void)
|
||||
{
|
||||
return xfrm_register_mode(&xfrm6_ro_mode, AF_INET6);
|
||||
}
|
||||
|
||||
static void __exit xfrm6_ro_exit(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = xfrm_unregister_mode(&xfrm6_ro_mode, AF_INET6);
|
||||
BUG_ON(err);
|
||||
}
|
||||
|
||||
module_init(xfrm6_ro_init);
|
||||
module_exit(xfrm6_ro_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_ALIAS_XFRM_MODE(AF_INET6, XFRM_MODE_ROUTEOPTIMIZATION);
|
||||
@@ -1,121 +0,0 @@
|
||||
/*
|
||||
* xfrm6_mode_transport.c - Transport mode encapsulation for IPv6.
|
||||
*
|
||||
* Copyright (C) 2002 USAGI/WIDE Project
|
||||
* Copyright (c) 2004-2006 Herbert Xu <herbert@gondor.apana.org.au>
|
||||
*/
|
||||
|
||||
#include <linux/init.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/stringify.h>
|
||||
#include <net/dst.h>
|
||||
#include <net/ipv6.h>
|
||||
#include <net/xfrm.h>
|
||||
#include <net/protocol.h>
|
||||
|
||||
/* Add encapsulation header.
|
||||
*
|
||||
* The IP header and mutable extension headers will be moved forward to make
|
||||
* space for the encapsulation header.
|
||||
*/
|
||||
static int xfrm6_transport_output(struct xfrm_state *x, struct sk_buff *skb)
|
||||
{
|
||||
struct ipv6hdr *iph;
|
||||
u8 *prevhdr;
|
||||
int hdr_len;
|
||||
|
||||
iph = ipv6_hdr(skb);
|
||||
skb_set_inner_transport_header(skb, skb_transport_offset(skb));
|
||||
|
||||
hdr_len = x->type->hdr_offset(x, skb, &prevhdr);
|
||||
if (hdr_len < 0)
|
||||
return hdr_len;
|
||||
skb_set_mac_header(skb, (prevhdr - x->props.header_len) - skb->data);
|
||||
skb_set_network_header(skb, -x->props.header_len);
|
||||
skb->transport_header = skb->network_header + hdr_len;
|
||||
__skb_pull(skb, hdr_len);
|
||||
memmove(ipv6_hdr(skb), iph, hdr_len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Remove encapsulation header.
|
||||
*
|
||||
* The IP header will be moved over the top of the encapsulation header.
|
||||
*
|
||||
* On entry, skb->h shall point to where the IP header should be and skb->nh
|
||||
* shall be set to where the IP header currently is. skb->data shall point
|
||||
* to the start of the payload.
|
||||
*/
|
||||
static int xfrm6_transport_input(struct xfrm_state *x, struct sk_buff *skb)
|
||||
{
|
||||
int ihl = skb->data - skb_transport_header(skb);
|
||||
|
||||
if (skb->transport_header != skb->network_header) {
|
||||
memmove(skb_transport_header(skb),
|
||||
skb_network_header(skb), ihl);
|
||||
skb->network_header = skb->transport_header;
|
||||
}
|
||||
ipv6_hdr(skb)->payload_len = htons(skb->len + ihl -
|
||||
sizeof(struct ipv6hdr));
|
||||
skb_reset_transport_header(skb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct sk_buff *xfrm4_transport_gso_segment(struct xfrm_state *x,
|
||||
struct sk_buff *skb,
|
||||
netdev_features_t features)
|
||||
{
|
||||
const struct net_offload *ops;
|
||||
struct sk_buff *segs = ERR_PTR(-EINVAL);
|
||||
struct xfrm_offload *xo = xfrm_offload(skb);
|
||||
|
||||
skb->transport_header += x->props.header_len;
|
||||
ops = rcu_dereference(inet6_offloads[xo->proto]);
|
||||
if (likely(ops && ops->callbacks.gso_segment))
|
||||
segs = ops->callbacks.gso_segment(skb, features);
|
||||
|
||||
return segs;
|
||||
}
|
||||
|
||||
static void xfrm6_transport_xmit(struct xfrm_state *x, struct sk_buff *skb)
|
||||
{
|
||||
struct xfrm_offload *xo = xfrm_offload(skb);
|
||||
|
||||
skb_reset_mac_len(skb);
|
||||
pskb_pull(skb, skb->mac_len + sizeof(struct ipv6hdr) + x->props.header_len);
|
||||
|
||||
if (xo->flags & XFRM_GSO_SEGMENT) {
|
||||
skb_reset_transport_header(skb);
|
||||
skb->transport_header -= x->props.header_len;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static struct xfrm_mode xfrm6_transport_mode = {
|
||||
.input = xfrm6_transport_input,
|
||||
.output = xfrm6_transport_output,
|
||||
.gso_segment = xfrm4_transport_gso_segment,
|
||||
.xmit = xfrm6_transport_xmit,
|
||||
.owner = THIS_MODULE,
|
||||
.encap = XFRM_MODE_TRANSPORT,
|
||||
};
|
||||
|
||||
static int __init xfrm6_transport_init(void)
|
||||
{
|
||||
return xfrm_register_mode(&xfrm6_transport_mode, AF_INET6);
|
||||
}
|
||||
|
||||
static void __exit xfrm6_transport_exit(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = xfrm_unregister_mode(&xfrm6_transport_mode, AF_INET6);
|
||||
BUG_ON(err);
|
||||
}
|
||||
|
||||
module_init(xfrm6_transport_init);
|
||||
module_exit(xfrm6_transport_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_ALIAS_XFRM_MODE(AF_INET6, XFRM_MODE_TRANSPORT);
|
||||
@@ -1,151 +0,0 @@
|
||||
/*
|
||||
* xfrm6_mode_tunnel.c - Tunnel mode encapsulation for IPv6.
|
||||
*
|
||||
* Copyright (C) 2002 USAGI/WIDE Project
|
||||
* Copyright (c) 2004-2006 Herbert Xu <herbert@gondor.apana.org.au>
|
||||
*/
|
||||
|
||||
#include <linux/gfp.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/stringify.h>
|
||||
#include <net/dsfield.h>
|
||||
#include <net/dst.h>
|
||||
#include <net/inet_ecn.h>
|
||||
#include <net/ip6_route.h>
|
||||
#include <net/ipv6.h>
|
||||
#include <net/xfrm.h>
|
||||
|
||||
static inline void ipip6_ecn_decapsulate(struct sk_buff *skb)
|
||||
{
|
||||
struct ipv6hdr *inner_iph = ipipv6_hdr(skb);
|
||||
|
||||
if (INET_ECN_is_ce(XFRM_MODE_SKB_CB(skb)->tos))
|
||||
IP6_ECN_set_ce(skb, inner_iph);
|
||||
}
|
||||
|
||||
/* Add encapsulation header.
|
||||
*
|
||||
* The top IP header will be constructed per RFC 2401.
|
||||
*/
|
||||
static int xfrm6_mode_tunnel_output(struct xfrm_state *x, struct sk_buff *skb)
|
||||
{
|
||||
struct dst_entry *dst = skb_dst(skb);
|
||||
struct ipv6hdr *top_iph;
|
||||
int dsfield;
|
||||
|
||||
skb_set_inner_network_header(skb, skb_network_offset(skb));
|
||||
skb_set_inner_transport_header(skb, skb_transport_offset(skb));
|
||||
|
||||
skb_set_network_header(skb, -x->props.header_len);
|
||||
skb->mac_header = skb->network_header +
|
||||
offsetof(struct ipv6hdr, nexthdr);
|
||||
skb->transport_header = skb->network_header + sizeof(*top_iph);
|
||||
top_iph = ipv6_hdr(skb);
|
||||
|
||||
top_iph->version = 6;
|
||||
|
||||
memcpy(top_iph->flow_lbl, XFRM_MODE_SKB_CB(skb)->flow_lbl,
|
||||
sizeof(top_iph->flow_lbl));
|
||||
top_iph->nexthdr = xfrm_af2proto(skb_dst(skb)->ops->family);
|
||||
|
||||
if (x->props.extra_flags & XFRM_SA_XFLAG_DONT_ENCAP_DSCP)
|
||||
dsfield = 0;
|
||||
else
|
||||
dsfield = XFRM_MODE_SKB_CB(skb)->tos;
|
||||
dsfield = INET_ECN_encapsulate(dsfield, XFRM_MODE_SKB_CB(skb)->tos);
|
||||
if (x->props.flags & XFRM_STATE_NOECN)
|
||||
dsfield &= ~INET_ECN_MASK;
|
||||
ipv6_change_dsfield(top_iph, 0, dsfield);
|
||||
top_iph->hop_limit = ip6_dst_hoplimit(xfrm_dst_child(dst));
|
||||
top_iph->saddr = *(struct in6_addr *)&x->props.saddr;
|
||||
top_iph->daddr = *(struct in6_addr *)&x->id.daddr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define for_each_input_rcu(head, handler) \
|
||||
for (handler = rcu_dereference(head); \
|
||||
handler != NULL; \
|
||||
handler = rcu_dereference(handler->next))
|
||||
|
||||
|
||||
static int xfrm6_mode_tunnel_input(struct xfrm_state *x, struct sk_buff *skb)
|
||||
{
|
||||
int err = -EINVAL;
|
||||
|
||||
if (XFRM_MODE_SKB_CB(skb)->protocol != IPPROTO_IPV6)
|
||||
goto out;
|
||||
if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
|
||||
goto out;
|
||||
|
||||
err = skb_unclone(skb, GFP_ATOMIC);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
if (x->props.flags & XFRM_STATE_DECAP_DSCP)
|
||||
ipv6_copy_dscp(ipv6_get_dsfield(ipv6_hdr(skb)),
|
||||
ipipv6_hdr(skb));
|
||||
if (!(x->props.flags & XFRM_STATE_NOECN))
|
||||
ipip6_ecn_decapsulate(skb);
|
||||
|
||||
skb_reset_network_header(skb);
|
||||
skb_mac_header_rebuild(skb);
|
||||
if (skb->mac_len)
|
||||
eth_hdr(skb)->h_proto = skb->protocol;
|
||||
|
||||
err = 0;
|
||||
|
||||
out:
|
||||
return err;
|
||||
}
|
||||
|
||||
static struct sk_buff *xfrm6_mode_tunnel_gso_segment(struct xfrm_state *x,
|
||||
struct sk_buff *skb,
|
||||
netdev_features_t features)
|
||||
{
|
||||
__skb_push(skb, skb->mac_len);
|
||||
return skb_mac_gso_segment(skb, features);
|
||||
}
|
||||
|
||||
static void xfrm6_mode_tunnel_xmit(struct xfrm_state *x, struct sk_buff *skb)
|
||||
{
|
||||
struct xfrm_offload *xo = xfrm_offload(skb);
|
||||
|
||||
if (xo->flags & XFRM_GSO_SEGMENT)
|
||||
skb->transport_header = skb->network_header + sizeof(struct ipv6hdr);
|
||||
|
||||
skb_reset_mac_len(skb);
|
||||
pskb_pull(skb, skb->mac_len + x->props.header_len);
|
||||
}
|
||||
|
||||
static struct xfrm_mode xfrm6_tunnel_mode = {
|
||||
.input2 = xfrm6_mode_tunnel_input,
|
||||
.input = xfrm_prepare_input,
|
||||
.output2 = xfrm6_mode_tunnel_output,
|
||||
.output = xfrm6_prepare_output,
|
||||
.gso_segment = xfrm6_mode_tunnel_gso_segment,
|
||||
.xmit = xfrm6_mode_tunnel_xmit,
|
||||
.owner = THIS_MODULE,
|
||||
.encap = XFRM_MODE_TUNNEL,
|
||||
.flags = XFRM_MODE_FLAG_TUNNEL,
|
||||
};
|
||||
|
||||
static int __init xfrm6_mode_tunnel_init(void)
|
||||
{
|
||||
return xfrm_register_mode(&xfrm6_tunnel_mode, AF_INET6);
|
||||
}
|
||||
|
||||
static void __exit xfrm6_mode_tunnel_exit(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = xfrm_unregister_mode(&xfrm6_tunnel_mode, AF_INET6);
|
||||
BUG_ON(err);
|
||||
}
|
||||
|
||||
module_init(xfrm6_mode_tunnel_init);
|
||||
module_exit(xfrm6_mode_tunnel_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_ALIAS_XFRM_MODE(AF_INET6, XFRM_MODE_TUNNEL);
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user