Debian Codegraph @

src/network/netdev/tunnel.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "fou-tunnel.h"
5 #include "netdev.h"
6 #include "networkd-link.h"
7 #include "shared-forward.h"
8
9 /* For IFLA_IPTUN_PROTO attribute */
10 typedef enum TunnelMode {
11 TUNNEL_MODE_ANY, /* 0, "any" */
12 TUNNEL_MODE_IPIP, /* IPPROTO_IPIP, "ipip", for ipip and sit */
13 TUNNEL_MODE_IP6IP, /* IPPROTO_IPV6, "ip6ip", for sit */
14 TUNNEL_MODE_IPIP6, /* IPPROTO_IPIP, "ipip6", for ip6tnl */
15 TUNNEL_MODE_IP6IP6, /* IPPROTO_IPV6, "ip6ip6", for ip6tnl */
16 _TUNNEL_MODE_MAX,
17 _TUNNEL_MODE_INVALID = -EINVAL,
18 } TunnelMode;
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
45 uint8_t erspan_version;
46 uint32_t erspan_index; /* version 1 */
47 uint8_t erspan_direction; /* version 2 */
48 uint16_t erspan_hwid; /* version 2 */
49
50 NetDevLocalAddressType local_type;
51 union in_addr_union local;
52 union in_addr_union remote;
53
54 TunnelMode mode;
55 FooOverUDPEncapType fou_encap_type;
56
57 int pmtudisc;
58 bool ignore_df;
59 bool copy_dscp;
60 bool independent;
61 bool fou_tunnel;
62 bool assign_to_loopback;
63 bool external; /* a.k.a collect metadata mode */
64
65 uint16_t encap_src_port;
66 uint16_t fou_destination_port;
67
68 struct in6_addr sixrd_prefix;
69 uint8_t sixrd_prefixlen;
70 } Tunnel;
71
72 int dhcp4_pd_create_6rd_tunnel(Link *link, link_netlink_message_handler_t callback);
73
74 DEFINE_NETDEV_CAST(IPIP, Tunnel);
75 DEFINE_NETDEV_CAST(GRE, Tunnel);
76 DEFINE_NETDEV_CAST(GRETAP, Tunnel);
77 DEFINE_NETDEV_CAST(IP6GRE, Tunnel);
78 DEFINE_NETDEV_CAST(IP6GRETAP, Tunnel);
79 DEFINE_NETDEV_CAST(SIT, Tunnel);
80 DEFINE_NETDEV_CAST(VTI, Tunnel);
81 DEFINE_NETDEV_CAST(VTI6, Tunnel);
82 DEFINE_NETDEV_CAST(IP6TNL, Tunnel);
83 DEFINE_NETDEV_CAST(ERSPAN, Tunnel);
84
85 static inline Tunnel* TUNNEL(NetDev *netdev) {
86 assert(netdev);
87
88 switch (netdev->kind) {
89 case NETDEV_KIND_IPIP:
90 return IPIP(netdev);
91 case NETDEV_KIND_SIT:
92 return SIT(netdev);
93 case NETDEV_KIND_GRE:
94 return GRE(netdev);
95 case NETDEV_KIND_GRETAP:
96 return GRETAP(netdev);
97 case NETDEV_KIND_IP6GRE:
98 return IP6GRE(netdev);
99 case NETDEV_KIND_IP6GRETAP:
100 return IP6GRETAP(netdev);
101 case NETDEV_KIND_VTI:
102 return VTI(netdev);
103 case NETDEV_KIND_VTI6:
104 return VTI6(netdev);
105 case NETDEV_KIND_IP6TNL:
106 return IP6TNL(netdev);
107 case NETDEV_KIND_ERSPAN:
108 return ERSPAN(netdev);
109 default:
110 return NULL;
111 }
112 }
113
114 extern const NetDevVTable ipip_vtable;
115 extern const NetDevVTable sit_vtable;
116 extern const NetDevVTable vti_vtable;
117 extern const NetDevVTable vti6_vtable;
118 extern const NetDevVTable gre_vtable;
119 extern const NetDevVTable gretap_vtable;
120 extern const NetDevVTable ip6gre_vtable;
121 extern const NetDevVTable ip6gretap_vtable;
122 extern const NetDevVTable ip6tnl_vtable;
123 extern const NetDevVTable erspan_vtable;
124
125 DECLARE_STRING_TABLE_LOOKUP(tunnel_mode, TunnelMode);
126
127 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel_mode);
128 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel_local_address);
129 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel_remote_address);
130 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_flowlabel);
131 CONFIG_PARSER_PROTOTYPE(config_parse_encap_limit);
132 CONFIG_PARSER_PROTOTYPE(config_parse_tunnel_key);
133 CONFIG_PARSER_PROTOTYPE(config_parse_6rd_prefix);
134 CONFIG_PARSER_PROTOTYPE(config_parse_erspan_version);
135 CONFIG_PARSER_PROTOTYPE(config_parse_erspan_index);
136 CONFIG_PARSER_PROTOTYPE(config_parse_erspan_direction);
137 CONFIG_PARSER_PROTOTYPE(config_parse_erspan_hwid);