1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3 
4 #include <netinet/in.h>
5 #include <linux/l2tp.h>
6 
7 #include "in-addr-util.h"
8 #include "netdev.h"
9 #include "networkd-util.h"
10 
11 typedef enum L2tpL2specType {
12         NETDEV_L2TP_L2SPECTYPE_NONE = L2TP_L2SPECTYPE_NONE,
13         NETDEV_L2TP_L2SPECTYPE_DEFAULT = L2TP_L2SPECTYPE_DEFAULT,
14         _NETDEV_L2TP_L2SPECTYPE_MAX,
15         _NETDEV_L2TP_L2SPECTYPE_INVALID = -EINVAL,
16 } L2tpL2specType;
17 
18 typedef enum L2tpEncapType {
19         NETDEV_L2TP_ENCAPTYPE_UDP = L2TP_ENCAPTYPE_UDP,
20         NETDEV_L2TP_ENCAPTYPE_IP = L2TP_ENCAPTYPE_IP,
21         _NETDEV_L2TP_ENCAPTYPE_MAX,
22         _NETDEV_L2TP_ENCAPTYPE_INVALID = -EINVAL,
23 } L2tpEncapType;
24 
25 typedef enum L2tpLocalAddressType {
26         NETDEV_L2TP_LOCAL_ADDRESS_AUTO,
27         NETDEV_L2TP_LOCAL_ADDRESS_STATIC,
28         NETDEV_L2TP_LOCAL_ADDRESS_DYNAMIC,
29         _NETDEV_L2TP_LOCAL_ADDRESS_MAX,
30         _NETDEV_L2TP_LOCAL_ADDRESS_INVALID = -EINVAL,
31 } L2tpLocalAddressType;
32 
33 typedef struct L2tpTunnel L2tpTunnel;
34 
35 typedef struct L2tpSession {
36         L2tpTunnel *tunnel;
37         ConfigSection *section;
38 
39         char *name;
40 
41         uint32_t session_id;
42         uint32_t peer_session_id;
43         L2tpL2specType l2tp_l2spec_type;
44 } L2tpSession;
45 
46 struct L2tpTunnel {
47         NetDev meta;
48 
49         uint16_t l2tp_udp_sport;
50         uint16_t l2tp_udp_dport;
51 
52         uint32_t tunnel_id;
53         uint32_t peer_tunnel_id;
54 
55         int family;
56 
57         bool udp_csum;
58         bool udp6_csum_rx;
59         bool udp6_csum_tx;
60 
61         char *local_ifname;
62         L2tpLocalAddressType local_address_type;
63         union in_addr_union local;
64         union in_addr_union remote;
65 
66         L2tpEncapType l2tp_encap_type;
67 
68         OrderedHashmap *sessions_by_section;
69 };
70 
71 DEFINE_NETDEV_CAST(L2TP, L2tpTunnel);
72 extern const NetDevVTable l2tptnl_vtable;
73 
74 CONFIG_PARSER_PROTOTYPE(config_parse_l2tp_tunnel_local_address);
75 CONFIG_PARSER_PROTOTYPE(config_parse_l2tp_tunnel_remote_address);
76 CONFIG_PARSER_PROTOTYPE(config_parse_l2tp_tunnel_id);
77 CONFIG_PARSER_PROTOTYPE(config_parse_l2tp_encap_type);
78 CONFIG_PARSER_PROTOTYPE(config_parse_l2tp_session_l2spec);
79 CONFIG_PARSER_PROTOTYPE(config_parse_l2tp_session_id);
80 CONFIG_PARSER_PROTOTYPE(config_parse_l2tp_session_name);
81