Compare commits
2 Commits
bbf52550be
...
flag
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce3fd3cc28 | ||
|
|
20cf4124c8 |
5
Makefile
5
Makefile
@@ -10,6 +10,11 @@ all: module tools
|
|||||||
module:
|
module:
|
||||||
$(MAKE) -C $(KDIR) M=$(PWD) modules
|
$(MAKE) -C $(KDIR) M=$(PWD) modules
|
||||||
|
|
||||||
|
tools: etherip6ctl
|
||||||
|
|
||||||
|
etherip6ctl: etherip6ctl.c etherip6_uapi.h
|
||||||
|
$(CC) $(CFLAGS) -Wall -Wextra -O2 -o $@ etherip6ctl.c
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@if [ -d "$(KDIR)" ]; then \
|
@if [ -d "$(KDIR)" ]; then \
|
||||||
$(MAKE) -C "$(KDIR)" M="$(PWD)" clean; \
|
$(MAKE) -C "$(KDIR)" M="$(PWD)" clean; \
|
||||||
|
|||||||
10
README.md
10
README.md
@@ -37,9 +37,13 @@ sudo ip link set eip0 up
|
|||||||
sudo ip addr add 192.0.2.1/30 dev eip0
|
sudo ip addr add 192.0.2.1/30 dev eip0
|
||||||
```
|
```
|
||||||
|
|
||||||
TCP SYN に MSS オプションがある場合、外側 IPv6 経路の MTU を超えないよう、
|
Overlay MTUのデフォルトは1500です。Underlayの経路MTUも1500の場合、
|
||||||
送信時に IPv4/IPv6 の MSS を自動的に縮小します。802.1Q/802.1ad VLAN と IPv6
|
カプセル化後の外側IPv6パケットはMTUを超えるため、送信元で経路MTU以下の
|
||||||
拡張ヘッダーにも対応します。既に十分小さい MSS は変更しません。
|
IPv6フラグメントに分割します。
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sudo ip link set eip0 mtu 1500
|
||||||
|
```
|
||||||
|
|
||||||
## トンネルの削除
|
## トンネルの削除
|
||||||
|
|
||||||
|
|||||||
134
etherip6.c
134
etherip6.c
@@ -5,7 +5,6 @@
|
|||||||
#include <linux/in6.h>
|
#include <linux/in6.h>
|
||||||
#include <linux/ip.h>
|
#include <linux/ip.h>
|
||||||
#include <linux/ipv6.h>
|
#include <linux/ipv6.h>
|
||||||
#include <linux/if_vlan.h>
|
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
#include <linux/list.h>
|
#include <linux/list.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
@@ -15,17 +14,12 @@
|
|||||||
#include <linux/rculist.h>
|
#include <linux/rculist.h>
|
||||||
#include <linux/rtnetlink.h>
|
#include <linux/rtnetlink.h>
|
||||||
#include <linux/skbuff.h>
|
#include <linux/skbuff.h>
|
||||||
#include <linux/tcp.h>
|
|
||||||
#include <linux/unaligned.h>
|
|
||||||
#include <net/checksum.h>
|
|
||||||
#include <net/ip.h>
|
|
||||||
#include <net/ip6_route.h>
|
#include <net/ip6_route.h>
|
||||||
#include <net/ipv6.h>
|
#include <net/ipv6.h>
|
||||||
#include <net/net_namespace.h>
|
#include <net/net_namespace.h>
|
||||||
#include <net/netns/generic.h>
|
#include <net/netns/generic.h>
|
||||||
#include <net/protocol.h>
|
#include <net/protocol.h>
|
||||||
#include <net/rtnetlink.h>
|
#include <net/rtnetlink.h>
|
||||||
#include <net/tcp.h>
|
|
||||||
|
|
||||||
#include "etherip6_uapi.h"
|
#include "etherip6_uapi.h"
|
||||||
|
|
||||||
@@ -38,9 +32,7 @@
|
|||||||
#define ETHERIP6_HLEN 2
|
#define ETHERIP6_HLEN 2
|
||||||
#define ETHERIP6_DEFAULT_HOP_LIMIT 64
|
#define ETHERIP6_DEFAULT_HOP_LIMIT 64
|
||||||
#define ETHERIP6_MAX_MTU 9000
|
#define ETHERIP6_MAX_MTU 9000
|
||||||
|
#define ETHERIP6_ENCAP_HLEN (sizeof(struct ipv6hdr) + ETHERIP6_HLEN)
|
||||||
/* IPv6 + EtherIP headers added outside the encapsulated Ethernet frame. */
|
|
||||||
#define ETHERIP6_OUTER_HLEN (sizeof(struct ipv6hdr) + ETHERIP6_HLEN)
|
|
||||||
|
|
||||||
struct etherip6_tunnel {
|
struct etherip6_tunnel {
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
@@ -149,110 +141,6 @@ static struct etherip6_tunnel *etherip6_lookup_rx(struct net *net,
|
|||||||
return etherip6_lookup_unique_rx(net, local, remote, iif, false, false);
|
return etherip6_lookup_unique_rx(net, local, remote, iif, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void etherip6_clamp_tcp_mss(struct sk_buff *skb, unsigned int path_mtu)
|
|
||||||
{
|
|
||||||
struct vlan_hdr _vh, *vh;
|
|
||||||
struct tcphdr _th, *th;
|
|
||||||
struct ethhdr _eth, *eth;
|
|
||||||
unsigned int nhoff = ETH_HLEN;
|
|
||||||
unsigned int thoff, tcp_hlen;
|
|
||||||
unsigned int inner_mtu;
|
|
||||||
unsigned int min_ip_hlen;
|
|
||||||
unsigned char *opt;
|
|
||||||
unsigned int optlen;
|
|
||||||
__be16 proto;
|
|
||||||
u16 old_mss, new_mss;
|
|
||||||
u8 nexthdr;
|
|
||||||
|
|
||||||
eth = skb_header_pointer(skb, 0, sizeof(_eth), &_eth);
|
|
||||||
if (!eth)
|
|
||||||
return;
|
|
||||||
proto = eth->h_proto;
|
|
||||||
|
|
||||||
while (eth_type_vlan(proto)) {
|
|
||||||
vh = skb_header_pointer(skb, nhoff, sizeof(_vh), &_vh);
|
|
||||||
if (!vh)
|
|
||||||
return;
|
|
||||||
proto = vh->h_vlan_encapsulated_proto;
|
|
||||||
nhoff += sizeof(*vh);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (path_mtu <= ETHERIP6_OUTER_HLEN + nhoff)
|
|
||||||
return;
|
|
||||||
inner_mtu = min_t(unsigned int, skb->dev->mtu,
|
|
||||||
path_mtu - ETHERIP6_OUTER_HLEN - nhoff);
|
|
||||||
|
|
||||||
if (proto == htons(ETH_P_IP)) {
|
|
||||||
struct iphdr _iph, *iph;
|
|
||||||
|
|
||||||
iph = skb_header_pointer(skb, nhoff, sizeof(_iph), &_iph);
|
|
||||||
if (!iph || iph->version != 4 || iph->ihl < 5 ||
|
|
||||||
iph->protocol != IPPROTO_TCP ||
|
|
||||||
(iph->frag_off & htons(IP_MF | IP_OFFSET)))
|
|
||||||
return;
|
|
||||||
thoff = nhoff + iph->ihl * 4;
|
|
||||||
min_ip_hlen = sizeof(struct iphdr);
|
|
||||||
} else if (proto == htons(ETH_P_IPV6)) {
|
|
||||||
struct ipv6hdr _ip6h, *ip6h;
|
|
||||||
__be16 frag_off = 0;
|
|
||||||
int offset;
|
|
||||||
|
|
||||||
ip6h = skb_header_pointer(skb, nhoff, sizeof(_ip6h), &_ip6h);
|
|
||||||
if (!ip6h || ip6h->version != 6)
|
|
||||||
return;
|
|
||||||
nexthdr = ip6h->nexthdr;
|
|
||||||
offset = ipv6_skip_exthdr(skb, nhoff + sizeof(*ip6h),
|
|
||||||
&nexthdr, &frag_off);
|
|
||||||
if (offset < 0 || nexthdr != IPPROTO_TCP || frag_off)
|
|
||||||
return;
|
|
||||||
thoff = offset;
|
|
||||||
min_ip_hlen = sizeof(struct ipv6hdr);
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
th = skb_header_pointer(skb, thoff, sizeof(_th), &_th);
|
|
||||||
if (!th || !th->syn || th->doff < sizeof(*th) / 4)
|
|
||||||
return;
|
|
||||||
tcp_hlen = th->doff * 4;
|
|
||||||
if (inner_mtu <= min_ip_hlen + sizeof(*th))
|
|
||||||
return;
|
|
||||||
new_mss = min_t(unsigned int, U16_MAX,
|
|
||||||
inner_mtu - min_ip_hlen - sizeof(*th));
|
|
||||||
|
|
||||||
if (skb_ensure_writable(skb, thoff + tcp_hlen))
|
|
||||||
return;
|
|
||||||
th = (struct tcphdr *)(skb->data + thoff);
|
|
||||||
opt = (unsigned char *)(th + 1);
|
|
||||||
optlen = tcp_hlen - sizeof(*th);
|
|
||||||
|
|
||||||
while (optlen) {
|
|
||||||
u8 kind = opt[0];
|
|
||||||
u8 len;
|
|
||||||
|
|
||||||
if (kind == TCPOPT_EOL)
|
|
||||||
return;
|
|
||||||
if (kind == TCPOPT_NOP) {
|
|
||||||
opt++;
|
|
||||||
optlen--;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (optlen < 2 || (len = opt[1]) < 2 || len > optlen)
|
|
||||||
return;
|
|
||||||
if (kind == TCPOPT_MSS && len == TCPOLEN_MSS) {
|
|
||||||
old_mss = get_unaligned_be16(opt + 2);
|
|
||||||
if (old_mss > new_mss) {
|
|
||||||
put_unaligned_be16(new_mss, opt + 2);
|
|
||||||
inet_proto_csum_replace2(&th->check, skb,
|
|
||||||
htons(old_mss), htons(new_mss), false);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
opt += len;
|
|
||||||
optlen -= len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static netdev_tx_t etherip6_xmit(struct sk_buff *skb, struct net_device *dev)
|
static netdev_tx_t etherip6_xmit(struct sk_buff *skb, struct net_device *dev)
|
||||||
{
|
{
|
||||||
struct etherip6_tunnel *tun = netdev_priv(dev);
|
struct etherip6_tunnel *tun = netdev_priv(dev);
|
||||||
@@ -280,8 +168,6 @@ static netdev_tx_t etherip6_xmit(struct sk_buff *skb, struct net_device *dev)
|
|||||||
goto tx_error;
|
goto tx_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
etherip6_clamp_tcp_mss(skb, dst_mtu(dst));
|
|
||||||
|
|
||||||
headroom = LL_RESERVED_SPACE(dst->dev) + sizeof(*ip6h) + ETHERIP6_HLEN;
|
headroom = LL_RESERVED_SPACE(dst->dev) + sizeof(*ip6h) + ETHERIP6_HLEN;
|
||||||
err = skb_cow_head(skb, headroom);
|
err = skb_cow_head(skb, headroom);
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -306,18 +192,17 @@ static netdev_tx_t etherip6_xmit(struct sk_buff *skb, struct net_device *dev)
|
|||||||
|
|
||||||
skb->protocol = htons(ETH_P_IPV6);
|
skb->protocol = htons(ETH_P_IPV6);
|
||||||
skb->dev = dst->dev;
|
skb->dev = dst->dev;
|
||||||
|
/*
|
||||||
|
* This skb used to contain an inner Ethernet frame. Clear its control
|
||||||
|
* block before handing it to IPv6, then pin source fragmentation to the
|
||||||
|
* current underlay PMTU. ip6_local_out() adds the Fragment Header and
|
||||||
|
* splits oversized packets in ip6_finish_output().
|
||||||
|
*/
|
||||||
|
memset(IP6CB(skb), 0, sizeof(*IP6CB(skb)));
|
||||||
|
IP6CB(skb)->frag_max_size = dst_mtu(dst);
|
||||||
skb->ignore_df = 1;
|
skb->ignore_df = 1;
|
||||||
skb_dst_set(skb, dst);
|
skb_dst_set(skb, dst);
|
||||||
|
|
||||||
/*
|
|
||||||
* skb->cb belongs to the protocol currently processing the skb. The
|
|
||||||
* encapsulated frame may leave bridge, qdisc, or inner IPv6 state in it;
|
|
||||||
* in particular, stale inet6_skb_parm flags or frag_max_size corrupt the
|
|
||||||
* outer IPv6 fragmentation path. Native IPv6 tunnels clear this state
|
|
||||||
* in ip6tunnel_xmit() before calling ip6_local_out().
|
|
||||||
*/
|
|
||||||
memset(skb->cb, 0, sizeof(struct inet6_skb_parm));
|
|
||||||
|
|
||||||
stats = this_cpu_ptr(tun->stats);
|
stats = this_cpu_ptr(tun->stats);
|
||||||
u64_stats_update_begin(&stats->syncp);
|
u64_stats_update_begin(&stats->syncp);
|
||||||
u64_stats_inc(&stats->tx_packets);
|
u64_stats_inc(&stats->tx_packets);
|
||||||
@@ -376,6 +261,7 @@ static void etherip6_setup(struct net_device *dev)
|
|||||||
dev->vlan_features = 0;
|
dev->vlan_features = 0;
|
||||||
dev->min_mtu = ETH_MIN_MTU;
|
dev->min_mtu = ETH_MIN_MTU;
|
||||||
dev->max_mtu = ETHERIP6_MAX_MTU;
|
dev->max_mtu = ETHERIP6_MAX_MTU;
|
||||||
|
dev->needed_headroom = ETHERIP6_ENCAP_HLEN;
|
||||||
eth_hw_addr_random(dev);
|
eth_hw_addr_random(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user