Commit 9baee834 authored by David Lebrun's avatar David Lebrun Committed by David S. Miller

ipv6: sr: add calls to verify and insert HMAC signatures

This patch enables the verification of the HMAC signature for transiting
SR-enabled packets, and its insertion on encapsulated/injected SRH.
Signed-off-by: default avatarDavid Lebrun <david.lebrun@uclouvain.be>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4f4853dc
...@@ -49,6 +49,9 @@ ...@@ -49,6 +49,9 @@
#endif #endif
#include <linux/seg6.h> #include <linux/seg6.h>
#include <net/seg6.h> #include <net/seg6.h>
#ifdef CONFIG_IPV6_SEG6_HMAC
#include <net/seg6_hmac.h>
#endif
#include <linux/uaccess.h> #include <linux/uaccess.h>
...@@ -340,6 +343,13 @@ static int ipv6_srh_rcv(struct sk_buff *skb) ...@@ -340,6 +343,13 @@ static int ipv6_srh_rcv(struct sk_buff *skb)
return -1; return -1;
} }
#ifdef CONFIG_IPV6_SEG6_HMAC
if (!seg6_hmac_validate_skb(skb)) {
kfree_skb(skb);
return -1;
}
#endif
looped_back: looped_back:
if (hdr->segments_left > 0) { if (hdr->segments_left > 0) {
if (hdr->nexthdr != NEXTHDR_IPV6 && hdr->segments_left == 1 && if (hdr->nexthdr != NEXTHDR_IPV6 && hdr->segments_left == 1 &&
......
...@@ -29,6 +29,9 @@ ...@@ -29,6 +29,9 @@
#ifdef CONFIG_DST_CACHE #ifdef CONFIG_DST_CACHE
#include <net/dst_cache.h> #include <net/dst_cache.h>
#endif #endif
#ifdef CONFIG_IPV6_SEG6_HMAC
#include <net/seg6_hmac.h>
#endif
struct seg6_lwt { struct seg6_lwt {
#ifdef CONFIG_DST_CACHE #ifdef CONFIG_DST_CACHE
...@@ -130,6 +133,14 @@ static int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh) ...@@ -130,6 +133,14 @@ static int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh)
hdr->daddr = isrh->segments[isrh->first_segment]; hdr->daddr = isrh->segments[isrh->first_segment];
set_tun_src(net, skb->dev, &hdr->daddr, &hdr->saddr); set_tun_src(net, skb->dev, &hdr->daddr, &hdr->saddr);
#ifdef CONFIG_IPV6_SEG6_HMAC
if (sr_has_hmac(isrh)) {
err = seg6_push_hmac(net, &hdr->saddr, isrh);
if (unlikely(err))
return err;
}
#endif
skb_postpush_rcsum(skb, hdr, tot_len); skb_postpush_rcsum(skb, hdr, tot_len);
return 0; return 0;
...@@ -172,6 +183,16 @@ static int seg6_do_srh_inline(struct sk_buff *skb, struct ipv6_sr_hdr *osrh) ...@@ -172,6 +183,16 @@ static int seg6_do_srh_inline(struct sk_buff *skb, struct ipv6_sr_hdr *osrh)
isrh->segments[0] = hdr->daddr; isrh->segments[0] = hdr->daddr;
hdr->daddr = isrh->segments[isrh->first_segment]; hdr->daddr = isrh->segments[isrh->first_segment];
#ifdef CONFIG_IPV6_SEG6_HMAC
if (sr_has_hmac(isrh)) {
struct net *net = dev_net(skb_dst(skb)->dev);
err = seg6_push_hmac(net, &hdr->saddr, isrh);
if (unlikely(err))
return err;
}
#endif
skb_postpush_rcsum(skb, hdr, sizeof(struct ipv6hdr) + hdrlen); skb_postpush_rcsum(skb, hdr, sizeof(struct ipv6hdr) + hdrlen);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment