]>
Commit | Line | Data |
---|---|---|
3be1d7e0 TG |
1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
2 | ||
3 | /*** | |
4 | This file is part of systemd. | |
5 | ||
6 | Copyright 2013 Tom Gundersen <teg@jklm.no> | |
7 | ||
8 | systemd is free software; you can redistribute it and/or modify it | |
9 | under the terms of the GNU Lesser General Public License as published by | |
10 | the Free Software Foundation; either version 2.1 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | systemd is distributed in the hope that it will be useful, but | |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | Lesser General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU Lesser General Public License | |
19 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
20 | ***/ | |
21 | ||
22 | #pragma once | |
23 | ||
24 | #include "networkd.h" | |
25 | #include "hashmap.h" | |
26 | #include "list.h" | |
27 | #include "set.h" | |
28 | #include "condition-util.h" | |
29 | #include "in-addr-util.h" | |
30 | ||
31 | typedef struct NetDevVTable NetDevVTable; | |
32 | ||
33 | typedef struct netdev_join_callback netdev_join_callback; | |
34 | ||
35 | struct netdev_join_callback { | |
36 | sd_rtnl_message_handler_t callback; | |
37 | Link *link; | |
38 | ||
39 | LIST_FIELDS(netdev_join_callback, callbacks); | |
40 | }; | |
41 | ||
42 | typedef enum NetDevKind { | |
43 | NETDEV_KIND_BRIDGE, | |
44 | NETDEV_KIND_BOND, | |
45 | NETDEV_KIND_VLAN, | |
46 | NETDEV_KIND_MACVLAN, | |
47 | NETDEV_KIND_VXLAN, | |
48 | NETDEV_KIND_IPIP, | |
49 | NETDEV_KIND_GRE, | |
50 | NETDEV_KIND_SIT, | |
51 | NETDEV_KIND_VETH, | |
52 | NETDEV_KIND_VTI, | |
53 | NETDEV_KIND_DUMMY, | |
54 | NETDEV_KIND_TUN, | |
55 | NETDEV_KIND_TAP, | |
56 | _NETDEV_KIND_MAX, | |
57 | _NETDEV_KIND_INVALID = -1 | |
58 | } NetDevKind; | |
59 | ||
60 | typedef enum NetDevState { | |
61 | NETDEV_STATE_FAILED, | |
62 | NETDEV_STATE_CREATING, | |
63 | NETDEV_STATE_READY, | |
64 | NETDEV_STATE_LINGER, | |
65 | _NETDEV_STATE_MAX, | |
66 | _NETDEV_STATE_INVALID = -1, | |
67 | } NetDevState; | |
68 | ||
69 | struct NetDev { | |
70 | Manager *manager; | |
71 | ||
72 | int n_ref; | |
73 | ||
74 | char *filename; | |
75 | ||
76 | Condition *match_host; | |
77 | Condition *match_virt; | |
78 | Condition *match_kernel; | |
79 | Condition *match_arch; | |
80 | ||
81 | char *description; | |
82 | char *ifname; | |
83 | char *ifname_peer; | |
84 | char *user_name; | |
85 | char *group_name; | |
86 | size_t mtu; | |
87 | struct ether_addr *mac; | |
88 | struct ether_addr *mac_peer; | |
89 | NetDevKind kind; | |
90 | ||
91 | uint64_t vlanid; | |
92 | uint64_t vxlanid; | |
93 | int32_t macvlan_mode; | |
94 | int32_t bond_mode; | |
95 | ||
96 | int ifindex; | |
97 | NetDevState state; | |
98 | ||
99 | bool tunnel_pmtudisc; | |
100 | bool learning; | |
101 | bool one_queue; | |
102 | bool multi_queue; | |
103 | bool packet_info; | |
104 | ||
105 | unsigned ttl; | |
106 | unsigned tos; | |
0dd25fb9 | 107 | int family; |
3be1d7e0 TG |
108 | union in_addr_union local; |
109 | union in_addr_union remote; | |
110 | union in_addr_union group; | |
111 | ||
112 | LIST_HEAD(netdev_join_callback, callbacks); | |
113 | }; | |
114 | ||
115 | struct NetDevVTable { | |
116 | /* fill in message to create netdev */ | |
117 | int (*fill_message_create)(NetDev *netdev, sd_rtnl_message *message); | |
118 | ||
119 | /* fill in message to create netdev on top of a given link */ | |
120 | int (*fill_message_create_on_link)(NetDev *netdev, Link *link, sd_rtnl_message *message); | |
121 | ||
122 | /* fill in message to enslave link by netdev */ | |
123 | int (*enslave)(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callback); | |
124 | ||
125 | /* create netdev, if not done via rtnl */ | |
126 | int (*create)(NetDev *netdev); | |
127 | ||
128 | /* verify that compulsory configuration options were specified */ | |
129 | int (*config_verify)(NetDev *netdev, const char *filename); | |
130 | }; | |
131 | ||
132 | extern const NetDevVTable * const netdev_vtable[_NETDEV_KIND_MAX]; | |
133 | ||
134 | #define NETDEV_VTABLE(n) netdev_vtable[(n)->kind] | |
135 | ||
136 | int netdev_load(Manager *manager); | |
137 | void netdev_drop(NetDev *netdev); | |
138 | ||
139 | NetDev *netdev_unref(NetDev *netdev); | |
140 | NetDev *netdev_ref(NetDev *netdev); | |
141 | ||
142 | DEFINE_TRIVIAL_CLEANUP_FUNC(NetDev*, netdev_unref); | |
143 | #define _cleanup_netdev_unref_ _cleanup_(netdev_unrefp) | |
144 | ||
145 | int netdev_get(Manager *manager, const char *name, NetDev **ret); | |
146 | int netdev_set_ifindex(NetDev *netdev, sd_rtnl_message *newlink); | |
147 | int netdev_enslave(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callback); | |
148 | int netdev_get_mac(const char *ifname, struct ether_addr **ret); | |
149 | int netdev_join(NetDev *netdev, Link *link, sd_rtnl_message_handler_t cb); | |
150 | ||
151 | const char *netdev_kind_to_string(NetDevKind d) _const_; | |
152 | NetDevKind netdev_kind_from_string(const char *d) _pure_; | |
153 | ||
154 | int config_parse_netdev_kind(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); | |
155 | ||
156 | /* gperf */ | |
157 | const struct ConfigPerfItem* network_netdev_gperf_lookup(const char *key, unsigned length); | |
158 | ||
159 | /* Macros which append INTERFACE= to the message */ | |
160 | ||
161 | #define log_full_netdev(level, netdev, fmt, ...) log_meta_object(level, __FILE__, __LINE__, __func__, "INTERFACE=", netdev->ifname, "%-*s: " fmt, IFNAMSIZ, netdev->ifname, ##__VA_ARGS__) | |
162 | #define log_debug_netdev(netdev, ...) log_full_netdev(LOG_DEBUG, netdev, ##__VA_ARGS__) | |
163 | #define log_info_netdev(netdev, ...) log_full_netdev(LOG_INFO, netdev, ##__VA_ARGS__) | |
164 | #define log_notice_netdev(netdev, ...) log_full_netdev(LOG_NOTICE, netdev, ##__VA_ARGS__) | |
165 | #define log_warning_netdev(netdev, ...) log_full_netdev(LOG_WARNING, netdev,## __VA_ARGS__) | |
166 | #define log_error_netdev(netdev, ...) log_full_netdev(LOG_ERR, netdev, ##__VA_ARGS__) | |
167 | ||
168 | #define log_struct_netdev(level, netdev, ...) log_struct(level, "INTERFACE=%s", netdev->ifname, __VA_ARGS__) | |
169 | ||
170 | #define NETDEV(netdev) "INTERFACE=%s", netdev->ifname |