[ Upstream commit b640daa2822a39ff76e70200cb2b7b892b896dce ]
Running lwt_dst_cache_ref_loop.sh in selftest with KASAN triggers
the splat below [0].
rpl_do_srh_inline() fetches ipv6_hdr(skb) and accesses it after
skb_cow_head(), which is illegal as the header could be freed then.
Let's fix it by making oldhdr to a local struct instead of a pointer.
[0]:
[root@fedora net]# ./lwt_dst_cache_ref_loop.sh
...
TEST: rpl (input)
[ 57.631529] ==================================================================
BUG: KASAN: slab-use-after-free in rpl_do_srh_inline.isra.0 (net/ipv6/rpl_iptunnel.c:174)
Read of size 40 at addr ffff888122bf96d8 by task ping6/1543
CPU: 50 UID: 0 PID: 1543 Comm: ping6 Not tainted 6.16.0-rc5-01302-gfadd1e6231b1 #23 PREEMPT(voluntary)
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
<IRQ>
dump_stack_lvl (lib/dump_stack.c:122)
print_report (mm/kasan/report.c:409 mm/kasan/report.c:521)
kasan_report (mm/kasan/report.c:221 mm/kasan/report.c:636)
kasan_check_range (mm/kasan/generic.c:175 (discriminator 1) mm/kasan/generic.c:189 (discriminator 1))
__asan_memmove (mm/kasan/shadow.c:94 (discriminator 2))
rpl_do_srh_inline.isra.0 (net/ipv6/rpl_iptunnel.c:174)
rpl_input (net/ipv6/rpl_iptunnel.c:201 net/ipv6/rpl_iptunnel.c:282)
lwtunnel_input (net/core/lwtunnel.c:459)
ipv6_rcv (./include/net/dst.h:471 (discriminator 1) ./include/net/dst.h:469 (discriminator 1) net/ipv6/ip6_input.c:79 (discriminator 1) ./include/linux/netfilter.h:317 (discriminator 1) ./include/linux/netfilter.h:311 (discriminator 1) net/ipv6/ip6_input.c:311 (discriminator 1))
__netif_receive_skb_one_core (net/core/dev.c:5967)
process_backlog (./include/linux/rcupdate.h:869 net/core/dev.c:6440)
__napi_poll.constprop.0 (net/core/dev.c:7452)
net_rx_action (net/core/dev.c:7518 net/core/dev.c:7643)
handle_softirqs (kernel/softirq.c:579)
do_softirq (kernel/softirq.c:480 (discriminator 20))
</IRQ>
<TASK>
__local_bh_enable_ip (kernel/softirq.c:407)
__dev_queue_xmit (net/core/dev.c:4740)
ip6_finish_output2 (./include/linux/netdevice.h:3358 ./include/net/neighbour.h:526 ./include/net/neighbour.h:540 net/ipv6/ip6_output.c:141)
ip6_finish_output (net/ipv6/ip6_output.c:215 net/ipv6/ip6_output.c:226)
ip6_output (./include/linux/netfilter.h:306 net/ipv6/ip6_output.c:248)
ip6_send_skb (net/ipv6/ip6_output.c:1983)
rawv6_sendmsg (net/ipv6/raw.c:588 net/ipv6/raw.c:918)
__sys_sendto (net/socket.c:714 (discriminator 1) net/socket.c:729 (discriminator 1) net/socket.c:2228 (discriminator 1))
__x64_sys_sendto (net/socket.c:2231)
do_syscall_64 (arch/x86/entry/syscall_64.c:63 (discriminator 1) arch/x86/entry/syscall_64.c:94 (discriminator 1))
entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:130)
RIP: 0033:0x7f68cffb2a06
Code: 5d e8 41 8b 93 08 03 00 00 59 5e 48 83 f8 fc 75 19 83 e2 39 83 fa 08 75 11 e8 26 ff ff ff 66 0f 1f 44 00 00 48 8b 45 10 0f 05 <48> 8b 5d f8 c9 c3 0f 1f 40 00 f3 0f 1e fa 55 48 89 e5 48 83 ec 08
RSP: 002b:00007ffefb7c53d0 EFLAGS: 00000202 ORIG_RAX: 000000000000002c
RAX: ffffffffffffffda RBX: 0000564cd69f10a0 RCX: 00007f68cffb2a06
RDX: 0000000000000040 RSI: 0000564cd69f10a4 RDI: 0000000000000003
RBP: 00007ffefb7c53f0 R08: 0000564cd6a032ac R09: 000000000000001c
R10: 0000000000000000 R11: 0000000000000202 R12: 0000564cd69f10a4
R13: 0000000000000040 R14: 00007ffefb7c66e0 R15: 0000564cd69f10a0
</TASK>
Allocated by task 1543:
kasan_save_stack (mm/kasan/common.c:48)
kasan_save_track (mm/kasan/common.c:60 (discriminator 1) mm/kasan/common.c:69 (discriminator 1))
__kasan_slab_alloc (mm/kasan/common.c:319 mm/kasan/common.c:345)
kmem_cache_alloc_node_noprof (./include/linux/kasan.h:250 mm/slub.c:4148 mm/slub.c:4197 mm/slub.c:4249)
kmalloc_reserve (net/core/skbuff.c:581 (discriminator 88))
__alloc_skb (net/core/skbuff.c:669)
__ip6_append_data (net/ipv6/ip6_output.c:1672 (discriminator 1))
ip6_append_data (net/ipv6/ip6_output.c:1859)
rawv6_sendmsg (net/ipv6/raw.c:911)
__sys_sendto (net/socket.c:714 (discriminator 1) net/socket.c:729 (discriminator 1) net/socket.c:2228 (discriminator 1))
__x64_sys_sendto (net/socket.c:2231)
do_syscall_64 (arch/x86/entry/syscall_64.c:63 (discriminator 1) arch/x86/entry/syscall_64.c:94 (discriminator 1))
entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:130)
Freed by task 1543:
kasan_save_stack (mm/kasan/common.c:48)
kasan_save_track (mm/kasan/common.c:60 (discriminator 1) mm/kasan/common.c:69 (discriminator 1))
kasan_save_free_info (mm/kasan/generic.c:579 (discriminator 1))
__kasan_slab_free (mm/kasan/common.c:271)
kmem_cache_free (mm/slub.c:4643 (discriminator 3) mm/slub.c:4745 (discriminator 3))
pskb_expand_head (net/core/skbuff.c:2274)
rpl_do_srh_inline.isra.0 (net/ipv6/rpl_iptunnel.c:158 (discriminator 1))
rpl_input (net/ipv6/rpl_iptunnel.c:201 net/ipv6/rpl_iptunnel.c:282)
lwtunnel_input (net/core/lwtunnel.c:459)
ipv6_rcv (./include/net/dst.h:471 (discriminator 1) ./include/net/dst.h:469 (discriminator 1) net/ipv6/ip6_input.c:79 (discriminator 1) ./include/linux/netfilter.h:317 (discriminator 1) ./include/linux/netfilter.h:311 (discriminator 1) net/ipv6/ip6_input.c:311 (discriminator 1))
__netif_receive_skb_one_core (net/core/dev.c:5967)
process_backlog (./include/linux/rcupdate.h:869 net/core/dev.c:6440)
__napi_poll.constprop.0 (net/core/dev.c:7452)
net_rx_action (net/core/dev.c:7518 net/core/dev.c:7643)
handle_softirqs (kernel/softirq.c:579)
do_softirq (kernel/softirq.c:480 (discriminator 20))
__local_bh_enable_ip (kernel/softirq.c:407)
__dev_queue_xmit (net/core/dev.c:4740)
ip6_finish_output2 (./include/linux/netdevice.h:3358 ./include/net/neighbour.h:526 ./include/net/neighbour.h:540 net/ipv6/ip6_output.c:141)
ip6_finish_output (net/ipv6/ip6_output.c:215 net/ipv6/ip6_output.c:226)
ip6_output (./include/linux/netfilter.h:306 net/ipv6/ip6_output.c:248)
ip6_send_skb (net/ipv6/ip6_output.c:1983)
rawv6_sendmsg (net/ipv6/raw.c:588 net/ipv6/raw.c:918)
__sys_sendto (net/socket.c:714 (discriminator 1) net/socket.c:729 (discriminator 1) net/socket.c:2228 (discriminator 1))
__x64_sys_sendto (net/socket.c:2231)
do_syscall_64 (arch/x86/entry/syscall_64.c:63 (discriminator 1) arch/x86/entry/syscall_64.c:94 (discriminator 1))
entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:130)
The buggy address belongs to the object at ffff888122bf96c0
which belongs to the cache skbuff_small_head of size 704
The buggy address is located 24 bytes inside of
freed 704-byte region [ffff888122bf96c0, ffff888122bf9980)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x122bf8
head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0x200000000000040(head|node=0|zone=2)
page_type: f5(slab)
raw: 0200000000000040 ffff888101fc0a00 ffffea000464dc00 0000000000000002
raw: 0000000000000000 0000000080270027 00000000f5000000 0000000000000000
head: 0200000000000040 ffff888101fc0a00 ffffea000464dc00 0000000000000002
head: 0000000000000000 0000000080270027 00000000f5000000 0000000000000000
head: 0200000000000003 ffffea00048afe01 00000000ffffffff 00000000ffffffff
head: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff888122bf9580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888122bf9600: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
>ffff888122bf9680: fc fc fc fc fc fc fc fc fa fb fb fb fb fb fb fb
^
ffff888122bf9700: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888122bf9780: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
Fixes: a7a29f9c36 ("net: ipv6: add rpl sr tunnel")
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
395 lines
8.7 KiB
C
395 lines
8.7 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Authors:
|
|
* (C) 2020 Alexander Aring <alex.aring@gmail.com>
|
|
*/
|
|
|
|
#include <linux/rpl_iptunnel.h>
|
|
|
|
#include <net/dst_cache.h>
|
|
#include <net/ip6_route.h>
|
|
#include <net/lwtunnel.h>
|
|
#include <net/ipv6.h>
|
|
#include <net/rpl.h>
|
|
|
|
struct rpl_iptunnel_encap {
|
|
DECLARE_FLEX_ARRAY(struct ipv6_rpl_sr_hdr, srh);
|
|
};
|
|
|
|
struct rpl_lwt {
|
|
struct dst_cache cache;
|
|
struct rpl_iptunnel_encap tuninfo;
|
|
};
|
|
|
|
static inline struct rpl_lwt *rpl_lwt_lwtunnel(struct lwtunnel_state *lwt)
|
|
{
|
|
return (struct rpl_lwt *)lwt->data;
|
|
}
|
|
|
|
static inline struct rpl_iptunnel_encap *
|
|
rpl_encap_lwtunnel(struct lwtunnel_state *lwt)
|
|
{
|
|
return &rpl_lwt_lwtunnel(lwt)->tuninfo;
|
|
}
|
|
|
|
static const struct nla_policy rpl_iptunnel_policy[RPL_IPTUNNEL_MAX + 1] = {
|
|
[RPL_IPTUNNEL_SRH] = { .type = NLA_BINARY },
|
|
};
|
|
|
|
static bool rpl_validate_srh(struct net *net, struct ipv6_rpl_sr_hdr *srh,
|
|
size_t seglen)
|
|
{
|
|
int err;
|
|
|
|
if ((srh->hdrlen << 3) != seglen)
|
|
return false;
|
|
|
|
/* check at least one segment and seglen fit with segments_left */
|
|
if (!srh->segments_left ||
|
|
(srh->segments_left * sizeof(struct in6_addr)) != seglen)
|
|
return false;
|
|
|
|
if (srh->cmpri || srh->cmpre)
|
|
return false;
|
|
|
|
err = ipv6_chk_rpl_srh_loop(net, srh->rpl_segaddr,
|
|
srh->segments_left);
|
|
if (err)
|
|
return false;
|
|
|
|
if (ipv6_addr_type(&srh->rpl_segaddr[srh->segments_left - 1]) &
|
|
IPV6_ADDR_MULTICAST)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
static int rpl_build_state(struct net *net, struct nlattr *nla,
|
|
unsigned int family, const void *cfg,
|
|
struct lwtunnel_state **ts,
|
|
struct netlink_ext_ack *extack)
|
|
{
|
|
struct nlattr *tb[RPL_IPTUNNEL_MAX + 1];
|
|
struct lwtunnel_state *newts;
|
|
struct ipv6_rpl_sr_hdr *srh;
|
|
struct rpl_lwt *rlwt;
|
|
int err, srh_len;
|
|
|
|
if (family != AF_INET6)
|
|
return -EINVAL;
|
|
|
|
err = nla_parse_nested(tb, RPL_IPTUNNEL_MAX, nla,
|
|
rpl_iptunnel_policy, extack);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
if (!tb[RPL_IPTUNNEL_SRH])
|
|
return -EINVAL;
|
|
|
|
srh = nla_data(tb[RPL_IPTUNNEL_SRH]);
|
|
srh_len = nla_len(tb[RPL_IPTUNNEL_SRH]);
|
|
|
|
if (srh_len < sizeof(*srh))
|
|
return -EINVAL;
|
|
|
|
/* verify that SRH is consistent */
|
|
if (!rpl_validate_srh(net, srh, srh_len - sizeof(*srh)))
|
|
return -EINVAL;
|
|
|
|
newts = lwtunnel_state_alloc(srh_len + sizeof(*rlwt));
|
|
if (!newts)
|
|
return -ENOMEM;
|
|
|
|
rlwt = rpl_lwt_lwtunnel(newts);
|
|
|
|
err = dst_cache_init(&rlwt->cache, GFP_ATOMIC);
|
|
if (err) {
|
|
kfree(newts);
|
|
return err;
|
|
}
|
|
|
|
memcpy(&rlwt->tuninfo.srh, srh, srh_len);
|
|
|
|
newts->type = LWTUNNEL_ENCAP_RPL;
|
|
newts->flags |= LWTUNNEL_STATE_INPUT_REDIRECT;
|
|
newts->flags |= LWTUNNEL_STATE_OUTPUT_REDIRECT;
|
|
|
|
*ts = newts;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void rpl_destroy_state(struct lwtunnel_state *lwt)
|
|
{
|
|
dst_cache_destroy(&rpl_lwt_lwtunnel(lwt)->cache);
|
|
}
|
|
|
|
static int rpl_do_srh_inline(struct sk_buff *skb, const struct rpl_lwt *rlwt,
|
|
const struct ipv6_rpl_sr_hdr *srh,
|
|
struct dst_entry *cache_dst)
|
|
{
|
|
struct ipv6_rpl_sr_hdr *isrh, *csrh;
|
|
struct ipv6hdr oldhdr;
|
|
struct ipv6hdr *hdr;
|
|
unsigned char *buf;
|
|
size_t hdrlen;
|
|
int err;
|
|
|
|
memcpy(&oldhdr, ipv6_hdr(skb), sizeof(oldhdr));
|
|
|
|
buf = kcalloc(struct_size(srh, segments.addr, srh->segments_left), 2, GFP_ATOMIC);
|
|
if (!buf)
|
|
return -ENOMEM;
|
|
|
|
isrh = (struct ipv6_rpl_sr_hdr *)buf;
|
|
csrh = (struct ipv6_rpl_sr_hdr *)(buf + ((srh->hdrlen + 1) << 3));
|
|
|
|
memcpy(isrh, srh, sizeof(*isrh));
|
|
memcpy(isrh->rpl_segaddr, &srh->rpl_segaddr[1],
|
|
(srh->segments_left - 1) * 16);
|
|
isrh->rpl_segaddr[srh->segments_left - 1] = oldhdr.daddr;
|
|
|
|
ipv6_rpl_srh_compress(csrh, isrh, &srh->rpl_segaddr[0],
|
|
isrh->segments_left - 1);
|
|
|
|
hdrlen = ((csrh->hdrlen + 1) << 3);
|
|
|
|
err = skb_cow_head(skb, hdrlen + dst_dev_overhead(cache_dst, skb));
|
|
if (unlikely(err)) {
|
|
kfree(buf);
|
|
return err;
|
|
}
|
|
|
|
skb_pull(skb, sizeof(struct ipv6hdr));
|
|
skb_postpull_rcsum(skb, skb_network_header(skb),
|
|
sizeof(struct ipv6hdr));
|
|
|
|
skb_push(skb, sizeof(struct ipv6hdr) + hdrlen);
|
|
skb_reset_network_header(skb);
|
|
skb_mac_header_rebuild(skb);
|
|
|
|
hdr = ipv6_hdr(skb);
|
|
memmove(hdr, &oldhdr, sizeof(*hdr));
|
|
isrh = (void *)hdr + sizeof(*hdr);
|
|
memcpy(isrh, csrh, hdrlen);
|
|
|
|
isrh->nexthdr = hdr->nexthdr;
|
|
hdr->nexthdr = NEXTHDR_ROUTING;
|
|
hdr->daddr = srh->rpl_segaddr[0];
|
|
|
|
ipv6_hdr(skb)->payload_len = htons(skb->len - sizeof(struct ipv6hdr));
|
|
skb_set_transport_header(skb, sizeof(struct ipv6hdr));
|
|
|
|
skb_postpush_rcsum(skb, hdr, sizeof(struct ipv6hdr) + hdrlen);
|
|
|
|
kfree(buf);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int rpl_do_srh(struct sk_buff *skb, const struct rpl_lwt *rlwt,
|
|
struct dst_entry *cache_dst)
|
|
{
|
|
struct dst_entry *dst = skb_dst(skb);
|
|
struct rpl_iptunnel_encap *tinfo;
|
|
|
|
if (skb->protocol != htons(ETH_P_IPV6))
|
|
return -EINVAL;
|
|
|
|
tinfo = rpl_encap_lwtunnel(dst->lwtstate);
|
|
|
|
return rpl_do_srh_inline(skb, rlwt, tinfo->srh, cache_dst);
|
|
}
|
|
|
|
static int rpl_output(struct net *net, struct sock *sk, struct sk_buff *skb)
|
|
{
|
|
struct dst_entry *orig_dst = skb_dst(skb);
|
|
struct dst_entry *dst = NULL;
|
|
struct rpl_lwt *rlwt;
|
|
int err;
|
|
|
|
rlwt = rpl_lwt_lwtunnel(orig_dst->lwtstate);
|
|
|
|
local_bh_disable();
|
|
dst = dst_cache_get(&rlwt->cache);
|
|
local_bh_enable();
|
|
|
|
err = rpl_do_srh(skb, rlwt, dst);
|
|
if (unlikely(err))
|
|
goto drop;
|
|
|
|
if (unlikely(!dst)) {
|
|
struct ipv6hdr *hdr = ipv6_hdr(skb);
|
|
struct flowi6 fl6;
|
|
|
|
memset(&fl6, 0, sizeof(fl6));
|
|
fl6.daddr = hdr->daddr;
|
|
fl6.saddr = hdr->saddr;
|
|
fl6.flowlabel = ip6_flowinfo(hdr);
|
|
fl6.flowi6_mark = skb->mark;
|
|
fl6.flowi6_proto = hdr->nexthdr;
|
|
|
|
dst = ip6_route_output(net, NULL, &fl6);
|
|
if (dst->error) {
|
|
err = dst->error;
|
|
goto drop;
|
|
}
|
|
|
|
/* cache only if we don't create a dst reference loop */
|
|
if (orig_dst->lwtstate != dst->lwtstate) {
|
|
local_bh_disable();
|
|
dst_cache_set_ip6(&rlwt->cache, dst, &fl6.saddr);
|
|
local_bh_enable();
|
|
}
|
|
|
|
err = skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev));
|
|
if (unlikely(err))
|
|
goto drop;
|
|
}
|
|
|
|
skb_dst_drop(skb);
|
|
skb_dst_set(skb, dst);
|
|
|
|
return dst_output(net, sk, skb);
|
|
|
|
drop:
|
|
dst_release(dst);
|
|
kfree_skb(skb);
|
|
return err;
|
|
}
|
|
|
|
static int rpl_input(struct sk_buff *skb)
|
|
{
|
|
struct dst_entry *orig_dst = skb_dst(skb);
|
|
struct dst_entry *dst = NULL;
|
|
struct lwtunnel_state *lwtst;
|
|
struct rpl_lwt *rlwt;
|
|
int err;
|
|
|
|
/* We cannot dereference "orig_dst" once ip6_route_input() or
|
|
* skb_dst_drop() is called. However, in order to detect a dst loop, we
|
|
* need the address of its lwtstate. So, save the address of lwtstate
|
|
* now and use it later as a comparison.
|
|
*/
|
|
lwtst = orig_dst->lwtstate;
|
|
|
|
rlwt = rpl_lwt_lwtunnel(lwtst);
|
|
|
|
local_bh_disable();
|
|
dst = dst_cache_get(&rlwt->cache);
|
|
local_bh_enable();
|
|
|
|
err = rpl_do_srh(skb, rlwt, dst);
|
|
if (unlikely(err)) {
|
|
dst_release(dst);
|
|
goto drop;
|
|
}
|
|
|
|
if (!dst) {
|
|
ip6_route_input(skb);
|
|
dst = skb_dst(skb);
|
|
|
|
/* cache only if we don't create a dst reference loop */
|
|
if (!dst->error && lwtst != dst->lwtstate) {
|
|
local_bh_disable();
|
|
dst_cache_set_ip6(&rlwt->cache, dst,
|
|
&ipv6_hdr(skb)->saddr);
|
|
local_bh_enable();
|
|
}
|
|
|
|
err = skb_cow_head(skb, LL_RESERVED_SPACE(dst->dev));
|
|
if (unlikely(err))
|
|
goto drop;
|
|
} else {
|
|
skb_dst_drop(skb);
|
|
skb_dst_set(skb, dst);
|
|
}
|
|
|
|
return dst_input(skb);
|
|
|
|
drop:
|
|
kfree_skb(skb);
|
|
return err;
|
|
}
|
|
|
|
static int nla_put_rpl_srh(struct sk_buff *skb, int attrtype,
|
|
struct rpl_iptunnel_encap *tuninfo)
|
|
{
|
|
struct rpl_iptunnel_encap *data;
|
|
struct nlattr *nla;
|
|
int len;
|
|
|
|
len = RPL_IPTUNNEL_SRH_SIZE(tuninfo->srh);
|
|
|
|
nla = nla_reserve(skb, attrtype, len);
|
|
if (!nla)
|
|
return -EMSGSIZE;
|
|
|
|
data = nla_data(nla);
|
|
memcpy(data, tuninfo->srh, len);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int rpl_fill_encap_info(struct sk_buff *skb,
|
|
struct lwtunnel_state *lwtstate)
|
|
{
|
|
struct rpl_iptunnel_encap *tuninfo = rpl_encap_lwtunnel(lwtstate);
|
|
|
|
if (nla_put_rpl_srh(skb, RPL_IPTUNNEL_SRH, tuninfo))
|
|
return -EMSGSIZE;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int rpl_encap_nlsize(struct lwtunnel_state *lwtstate)
|
|
{
|
|
struct rpl_iptunnel_encap *tuninfo = rpl_encap_lwtunnel(lwtstate);
|
|
|
|
return nla_total_size(RPL_IPTUNNEL_SRH_SIZE(tuninfo->srh));
|
|
}
|
|
|
|
static int rpl_encap_cmp(struct lwtunnel_state *a, struct lwtunnel_state *b)
|
|
{
|
|
struct rpl_iptunnel_encap *a_hdr = rpl_encap_lwtunnel(a);
|
|
struct rpl_iptunnel_encap *b_hdr = rpl_encap_lwtunnel(b);
|
|
int len = RPL_IPTUNNEL_SRH_SIZE(a_hdr->srh);
|
|
|
|
if (len != RPL_IPTUNNEL_SRH_SIZE(b_hdr->srh))
|
|
return 1;
|
|
|
|
return memcmp(a_hdr, b_hdr, len);
|
|
}
|
|
|
|
static const struct lwtunnel_encap_ops rpl_ops = {
|
|
.build_state = rpl_build_state,
|
|
.destroy_state = rpl_destroy_state,
|
|
.output = rpl_output,
|
|
.input = rpl_input,
|
|
.fill_encap = rpl_fill_encap_info,
|
|
.get_encap_size = rpl_encap_nlsize,
|
|
.cmp_encap = rpl_encap_cmp,
|
|
.owner = THIS_MODULE,
|
|
};
|
|
|
|
int __init rpl_init(void)
|
|
{
|
|
int err;
|
|
|
|
err = lwtunnel_encap_add_ops(&rpl_ops, LWTUNNEL_ENCAP_RPL);
|
|
if (err)
|
|
goto out;
|
|
|
|
pr_info("RPL Segment Routing with IPv6\n");
|
|
|
|
return 0;
|
|
|
|
out:
|
|
return err;
|
|
}
|
|
|
|
void rpl_exit(void)
|
|
{
|
|
lwtunnel_encap_del_ops(&rpl_ops, LWTUNNEL_ENCAP_RPL);
|
|
}
|