1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3 
4 #include "in-addr-util.h"
5 
6 #include "conf-parser.h"
7 #include "fou-tunnel.h"
8 #include "netdev-util.h"
9 #include "netdev.h"
10 #include "networkd-link.h"
11 
12 typedef enum Ip6TnlMode {
13         NETDEV_IP6_TNL_MODE_IP6IP6,
14         NETDEV_IP6_TNL_MODE_IPIP6,
15         NETDEV_IP6_TNL_MODE_ANYIP6,
16         _NETDEV_IP6_TNL_MODE_MAX,
17         _NETDEV_IP6_TNL_MODE_INVALID = -EINVAL,
18 } Ip6TnlMode;
19 
20 typedef enum IPv6FlowLabel {
21         NETDEV_IPV6_FLOWLABEL_INHERIT = 0xFFFFF + 1,
22         _NETDEV_IPV6_FLOWLABEL_MAX,
23         _NETDEV_IPV6_FLOWLABEL_INVALID = -EINVAL,
24 } IPv6FlowLabel;
25 
26 typedef struct Tunnel {
27         NetDev meta;
28 
29         uint8_t encap_limit;
30 
31         int family;
32         int ipv6_flowlabel;
33         int allow_localremote;
34         int gre_erspan_sequence;
35         int isatap;
36 
37         unsigned ttl;
38         unsigned tos;
39         unsigned flags;
40 
41         uint32_t key;
42         uint32_t ikey;
43         uint32_t okey;
44         uint32_t erspan_index;
45 
46         NetDevLocalAddressType local_type;
47         union in_addr_union local;
48         union in_addr_union remote;
49 
50         Ip6TnlMode ip6tnl_mode;
51         FooOverUDPEncapType fou_encap_type;
52 
53         bool pmtudisc;
54         bool copy_dscp;
55         bool independent;
56         bool fou_tunnel;
57         bool assign_to_loopback;
58         bool external; /* a.k.a collect metadata mode */
59 
60         uint16_t encap_src_port;
61         uint16_t fou_destination_port;
62 
63         struct in6_addr sixrd_prefix;
64         uint8_t sixrd_prefixlen;
65 } Tunnel;
66 
67 int dhcp4_pd_create_6rd_tunnel_name(Link *link, char **ret);
68 int dhcp4_pd_create_6rd_tunnel(Link *link, link_netlink_message_handler_t callback);
69 
70 DEFINE_NETDEV_CAST(IPIP, Tunnel);
71 DEFINE_NETDEV_CAST(GRE, Tunnel);
72 DEFINE_NETDEV_CAST(GRETAP, Tunnel);
73 DEFINE_NETDEV_CAST(IP6GRE, Tunnel);
74 DEFINE_NETDEV_CAST(IP6GRETAP, Tunnel);
75 DEFINE_NETDEV_CAST(SIT, Tunnel);
76 DEFINE_NETDEV_CAST(VTI, Tunnel);
77 DEFINE_NETDEV_CAST(VTI6, Tunnel);
78 DEFINE_NETDEV_CAST(IP6TNL, Tunnel);
79 DEFINE_NETDEV_CAST(ERSPAN, Tunnel);
80 
TUNNEL(NetDev * netdev)81 static inline Tunnel* TUNNEL(NetDev *netdev) {
82         assert(netdev);
83 
84         switch (netdev->kind) {
85         case NETDEV_KIND_IPIP:
86                 return IPIP(netdev);
87         case NETDEV_KIND_SIT:
88                 return SIT(netdev);
89         case NETDEV_KIND_GRE:
90                 return GRE(netdev);
91         case NETDEV_KIND_GRETAP:
92                 return GRETAP(netdev);
93         case NETDEV_KIND_IP6GRE:
94                 return IP6GRE(netdev);
95         case NETDEV_KIND_IP6GRETAP:
96                 return IP6GRETAP(netdev);
97         case NETDEV_KIND_VTI:
98                 return VTI(netdev);
99         case NETDEV_KIND_VTI6:
100                 return VTI6(netdev);
101         case NETDEV_KIND_IP6TNL:
102                 return IP6TNL(netdev);
103         case NETDEV_KIND_ERSPAN:
104                 return ERSPAN(netdev);
105         default:
106                 return NULL;
107         }
108 }
109 
110 extern const NetDevVTable ipip_vtable;
111 extern const NetDevVTable sit_vtable;
112 extern const NetDevVTable vti_vtable;
113 extern const NetDevVTable vti6_vtable;
114 extern const NetDevVTable gre_vtable;
115 extern const NetDevVTable gretap_vtable;
116 extern const NetDevVTable ip6gre_vtable;
117 extern const NetDevVTable ip6gretap_vtable;
118 extern const NetDevVTable ip6tnl_vtable;
119 extern const NetDevVTable erspan_vtable;
120 
121 const char *ip6tnl_mode_to_string(Ip6TnlMode d) _const_;
122 Ip6TnlMode ip6tnl_mode_from_string(const char *d) _pure_;
123 
124 CONFIG_PARSER_PROTOTYPE(config_parse_ip6tnl_mode);
125 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel_local_address);
126 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel_remote_address);
127 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_flowlabel);
128 CONFIG_PARSER_PROTOTYPE(config_parse_encap_limit);
129 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel_key);
130 CONFIG_PARSER_PROTOTYPE(config_parse_6rd_prefix);
131