| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * SR-IPv6 implementation |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Author: |
|---|
| 5 | 6 | * David Lebrun <david.lebrun@uclouvain.be> |
|---|
| 6 | | - * |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is free software; you can redistribute it and/or |
|---|
| 9 | | - * modify it under the terms of the GNU General Public License |
|---|
| 10 | | - * as published by the Free Software Foundation; either version |
|---|
| 11 | | - * 2 of the License, or (at your option) any later version. |
|---|
| 12 | 7 | */ |
|---|
| 13 | 8 | |
|---|
| 14 | 9 | #include <linux/types.h> |
|---|
| .. | .. |
|---|
| 32 | 27 | #include <net/seg6_hmac.h> |
|---|
| 33 | 28 | #endif |
|---|
| 34 | 29 | |
|---|
| 30 | +static size_t seg6_lwt_headroom(struct seg6_iptunnel_encap *tuninfo) |
|---|
| 31 | +{ |
|---|
| 32 | + int head = 0; |
|---|
| 33 | + |
|---|
| 34 | + switch (tuninfo->mode) { |
|---|
| 35 | + case SEG6_IPTUN_MODE_INLINE: |
|---|
| 36 | + break; |
|---|
| 37 | + case SEG6_IPTUN_MODE_ENCAP: |
|---|
| 38 | + head = sizeof(struct ipv6hdr); |
|---|
| 39 | + break; |
|---|
| 40 | + case SEG6_IPTUN_MODE_L2ENCAP: |
|---|
| 41 | + return 0; |
|---|
| 42 | + } |
|---|
| 43 | + |
|---|
| 44 | + return ((tuninfo->srh->hdrlen + 1) << 3) + head; |
|---|
| 45 | +} |
|---|
| 46 | + |
|---|
| 35 | 47 | struct seg6_lwt { |
|---|
| 36 | 48 | struct dst_cache cache; |
|---|
| 37 | | - struct seg6_iptunnel_encap tuninfo[0]; |
|---|
| 49 | + struct seg6_iptunnel_encap tuninfo[]; |
|---|
| 38 | 50 | }; |
|---|
| 39 | 51 | |
|---|
| 40 | 52 | static inline struct seg6_lwt *seg6_lwt_lwtunnel(struct lwtunnel_state *lwt) |
|---|
| .. | .. |
|---|
| 176 | 188 | } |
|---|
| 177 | 189 | #endif |
|---|
| 178 | 190 | |
|---|
| 191 | + hdr->payload_len = htons(skb->len - sizeof(struct ipv6hdr)); |
|---|
| 192 | + |
|---|
| 179 | 193 | skb_postpush_rcsum(skb, hdr, tot_len); |
|---|
| 180 | 194 | |
|---|
| 181 | 195 | return 0; |
|---|
| .. | .. |
|---|
| 227 | 241 | return err; |
|---|
| 228 | 242 | } |
|---|
| 229 | 243 | #endif |
|---|
| 244 | + |
|---|
| 245 | + hdr->payload_len = htons(skb->len - sizeof(struct ipv6hdr)); |
|---|
| 230 | 246 | |
|---|
| 231 | 247 | skb_postpush_rcsum(skb, hdr, sizeof(struct ipv6hdr) + hdrlen); |
|---|
| 232 | 248 | |
|---|
| .. | .. |
|---|
| 281 | 297 | skb_mac_header_rebuild(skb); |
|---|
| 282 | 298 | skb_push(skb, skb->mac_len); |
|---|
| 283 | 299 | |
|---|
| 284 | | - err = seg6_do_srh_encap(skb, tinfo->srh, NEXTHDR_NONE); |
|---|
| 300 | + err = seg6_do_srh_encap(skb, tinfo->srh, IPPROTO_ETHERNET); |
|---|
| 285 | 301 | if (err) |
|---|
| 286 | 302 | return err; |
|---|
| 287 | 303 | |
|---|
| .. | .. |
|---|
| 289 | 305 | break; |
|---|
| 290 | 306 | } |
|---|
| 291 | 307 | |
|---|
| 292 | | - ipv6_hdr(skb)->payload_len = htons(skb->len - sizeof(struct ipv6hdr)); |
|---|
| 293 | 308 | skb_set_transport_header(skb, sizeof(struct ipv6hdr)); |
|---|
| 294 | 309 | |
|---|
| 295 | 310 | return 0; |
|---|
| .. | .. |
|---|
| 389 | 404 | return err; |
|---|
| 390 | 405 | } |
|---|
| 391 | 406 | |
|---|
| 392 | | -static int seg6_build_state(struct nlattr *nla, |
|---|
| 407 | +static int seg6_build_state(struct net *net, struct nlattr *nla, |
|---|
| 393 | 408 | unsigned int family, const void *cfg, |
|---|
| 394 | 409 | struct lwtunnel_state **ts, |
|---|
| 395 | 410 | struct netlink_ext_ack *extack) |
|---|
| .. | .. |
|---|
| 404 | 419 | if (family != AF_INET && family != AF_INET6) |
|---|
| 405 | 420 | return -EINVAL; |
|---|
| 406 | 421 | |
|---|
| 407 | | - err = nla_parse_nested(tb, SEG6_IPTUNNEL_MAX, nla, |
|---|
| 408 | | - seg6_iptunnel_policy, extack); |
|---|
| 422 | + err = nla_parse_nested_deprecated(tb, SEG6_IPTUNNEL_MAX, nla, |
|---|
| 423 | + seg6_iptunnel_policy, extack); |
|---|
| 409 | 424 | |
|---|
| 410 | 425 | if (err < 0) |
|---|
| 411 | 426 | return err; |
|---|
| .. | .. |
|---|
| 439 | 454 | } |
|---|
| 440 | 455 | |
|---|
| 441 | 456 | /* verify that SRH is consistent */ |
|---|
| 442 | | - if (!seg6_validate_srh(tuninfo->srh, tuninfo_len - sizeof(*tuninfo))) |
|---|
| 457 | + if (!seg6_validate_srh(tuninfo->srh, tuninfo_len - sizeof(*tuninfo), false)) |
|---|
| 443 | 458 | return -EINVAL; |
|---|
| 444 | 459 | |
|---|
| 445 | 460 | newts = lwtunnel_state_alloc(tuninfo_len + sizeof(*slwt)); |
|---|