constant.scm
1 | ;;;; This file is part of Guile Netlink |
2 | ;;;; |
3 | ;;;; Copyright (C) 2020 Julien Lepiller <julien@lepiller.eu> |
4 | ;;;; |
5 | ;;;; This library is free software: you can redistribute it and/or modify |
6 | ;;;; it under the terms of the GNU General Public License as published by |
7 | ;;;; the Free Software Foundation, either version 3 of the License, or |
8 | ;;;; (at your option) any later version. |
9 | ;;;; |
10 | ;;;; This library is distributed in the hope that it will be useful, |
11 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | ;;;; GNU General Public License for more details. |
14 | ;;;; |
15 | ;;;; You should have received a copy of the GNU General Public License |
16 | ;;;; along with this library. If not, see <https://www.gnu.org/licenses/>. |
17 | |
18 | (define-module (netlink constant) |
19 | #:export (define-enum)) |
20 | |
21 | (define-syntax define-enum-aux |
22 | (syntax-rules () |
23 | ((_ num (name n)) |
24 | (define-public name n)) |
25 | ((_ num name) |
26 | (define-public name num)) |
27 | ((_ num (name n) rest ...) |
28 | (begin |
29 | (define-public name n) |
30 | (define-enum-aux (+ n 1) rest ...))) |
31 | ((_ num name rest ...) |
32 | (begin |
33 | (define-public name num) |
34 | (define-enum-aux (+ num 1) rest ...))))) |
35 | |
36 | (define-syntax define-enum |
37 | (lambda (x) |
38 | (define (spec-names specs) |
39 | (map |
40 | (lambda (spec) |
41 | (syntax-case spec () |
42 | ((name val) #'name) |
43 | (name #'name))) |
44 | specs)) |
45 | |
46 | (define (getter num name) |
47 | #`((= #,num #,name) (quote #,name))) |
48 | |
49 | (syntax-case x () |
50 | ((_ integer->symbol name-spec ...) |
51 | #`(begin |
52 | (define-enum-aux 0 name-spec ...) |
53 | (define-public (integer->symbol num) |
54 | (cond |
55 | #,@(map (lambda (s) (getter #'num s)) (spec-names #'(name-spec ...)))))))))) |
56 | |
57 | (define-enum int->link-attr-kind |
58 | IFLA_UNSPEC IFLA_ADDRESS IFLA_BROADCAST IFLA_IFNAME IFLA_MTU |
59 | IFLA_LINK IFLA_QDISC IFLA_STATS IFLA_COST IFLA_PRIORITY |
60 | IFLA_MASTER IFLA_WIRELESS IFLA_PROTIFO IFLA_TXQLEN IFLA_MAP |
61 | IFLA_WEIGHT IFLA_OPERSTATE IFLA_LINKMODE IFLA_LINKINFO |
62 | IFLA_NET_NS_PID IFLA_IFALIAS IFLA_NUM_VF IFLA_VFINFO_LIST |
63 | IFLA_STATS64 IFLA_VF_PORTS IFLA_PORT_SELF IFLA_AF_SPEC |
64 | IFLA_GROUP IFLA_NET_NS_FD IFLA_EXT_MASK IFLA_PROMISCUITY |
65 | IFLA_NUM_TX_QUEUES IFLA_NUM_RX_QUEUES IFLA_CARRIER |
66 | IFLA_PHYS_PORT_ID IFLA_CARRIER_CHANGES IFLA_PHYS_SWITCH_ID |
67 | IFLA_LINK_NETNSID IFLA_PHYS_PORT_NAME IFLA_PROTO_DOWN |
68 | IFLA_GSO_MAX_SEGS IFLA_GSO_MAX_SIZE IFLA_PAD IFLA_XDP |
69 | IFLA_EVENT IFLA_NEW_NETNSID IFLA_IF_NETNSID IFLA_CARRIER_UP_COUNT |
70 | IFLA_CARRIER_DOWN_COUNT IFLA_NEW_IFINDEX IFLA_MIN_MTU IFLA_MAX_MTU |
71 | IFLA_PROP_LIST IFLA_ALT_IFNAME IFLA_PERM_ADDRESS) |
72 | (define-public IFLA_TARGET_NETNSID IFLA_IF_NETNSID) |
73 | |
74 | (define-enum int->linkinfo |
75 | IFLA_INFO_UNSPEC IFLA_INFO_KIND IFLA_INFO_DATA IFLA_INFO_XSTATS |
76 | IFLA_INFO_SLAVE_KIND IFLA_INFO_SLAVE_DATA) |
77 | |
78 | (define-enum int->veth-linkinfo |
79 | VETH_INFO_UNSPEC VETH_INFO_PEER) |
80 | |
81 | (define-enum int->vlan-linkinfo |
82 | IFLA_VLAN_UNSPEC IFLA_VLAN_ID IFLA_VLAN_FLAGS IFLA_VLAN_EGRESS_QOS |
83 | IFLA_VLAN_INGRESS_QOS IFLA_VLAN_PROTOCOL) |
84 | |
85 | (define-enum int->bond-linkinfo |
86 | IFLA_BOND_UNSPEC IFLA_BOND_MODE IFLA_BOND_ACTIVE_SLAVE IFLA_BOND_MIIMON |
87 | IFLA_BOND_UPDELAY IFLA_BOND_DOWNDELAY IFLA_BOND_USE_CARRIER IFLA_BOND_ARP_INTERVAL |
88 | IFLA_BOND_ARP_IP_TARGET IFLA_BOND_ARP_VALIDATE IFLA_BOND_ARP_ALL_TARGETS |
89 | IFLA_BOND_PRIMARY IFLA_BOND_PRIMARY_RESELECT IFLA_BOND_FAIL_OVER_MAC IFLA_BOND_XMIT_HASH_POLICY |
90 | IFLA_BOND_RESEND_IGMP IFLA_BOND_NUM_PEER_NOTIF IFLA_BOND_ALL_SLAVES_ACTIVE |
91 | IFLA_BOND_MIN_LINKS IFLA_BOND_LP_INTERVAL IFLA_BOND_PACKETS_PER_SLAVE |
92 | IFLA_BOND_AD_LACP_RATE IFLA_BOND_AD_SELECT IFLA_BOND_AD_INFO IFLA_BOND_AD_ACTOR_SYS_PRIO |
93 | IFLA_BOND_AD_USER_PORT_KEY IFLA_BOND_AD_ACTOR_SYSTEM IFLA_BOND_TLB_DYNAMIC_LB |
94 | IFLA_BOND_PEER_NOTIF_DELAY IFLA_BOND_AD_LACP_ACTIVE IFLA_BOND_MISSED_MAX IFLA_BOND_NS_IP6_TARGET) |
95 | |
96 | ;; see iproute2/ip/iplink_bond.c for mode_tbl |
97 | (define-enum int->bond-mode |
98 | BOND_MODE_ROUNDROBIN BOND_MODE_ACTIVEBACKUP BOND_MODE_XOR BOND_MODE_BROADCAST |
99 | BOND_MODE_8023AD BOND_MODE_TLB |
100 | ;; TLB + RLB (receive load balancing) |
101 | BOND_MODE_ALB) |
102 | |
103 | ;; see iproute2/ip/iplink_bond.c primary_reselect_tbl |
104 | (define-public BOND_PRIMARY_RESELECT_ALWAYS 0) |
105 | (define-public BOND_PRIMARY_RESELECT_BETTER 1) |
106 | (define-public BOND_PRIMARY_RESELECT_FAILURE 2) |
107 | |
108 | ;; see iproute2/ip/iplink_bond.c for lacp_active_tbl |
109 | (define-public BOND_AD_LACP_ACTIVE_OFF 0) |
110 | (define-public BOND_AD_LACP_ACTIVE_ON 1) |
111 | |
112 | (define-enum int->addr-attr-kind |
113 | IFA_UNSPEC IFA_ADDRESS IFA_LOCAL IFA_LABEL IFA_BROADCAST |
114 | IFA_ANYCAST IFA_CACHEINFO IFA_MULTICAST IFA_FLAGS |
115 | IFA_RT_PRIORITY IFA_TARGET_NETNSID) |
116 | |
117 | (define-enum int->route-attr-kind |
118 | RTA_UNSPEC RTA_DST RTA_SRC RTA_IIF RTA_OIF RTA_GATEWAY |
119 | RTA_PRIORITY RTA_PREFSRC RTA_METRICS RTA_MULTIPATH |
120 | RTA_PROTOINFO RTA_FLOW RTA_CACHEINFO RTA_SESSION RTA_MP_ALGO |
121 | RTA_TABLE RTA_MARK RTA_MFC_STATS RTA_VIA RTA_NEWDST RTA_PREF |
122 | RTA_ENCAP_TYPE RTA_ENCAP RTA_EXPIRES RTA_PAD RTA_UID |
123 | RTA_TTL_PROPAGATE RTA_IP_PROTO RTA_SPORT RTA_DPORT RTA_NH_ID) |
124 | |
125 | (define-public AF_NETLINK 16) |
126 | (define-public AF_PACKET 17) |
127 | |
128 | (define-enum int->protocol |
129 | NETLINK_ROUTE NETLINK_UNUSED NETLINK_USERSOCK NETLINK_FIREWALL |
130 | NETLINK_SOCK_DIAG NETLINK_NFLOG NETLINK_XFRM NETLINK_SELINUX |
131 | NETLINK_ISCSI NETLINK_AUDIT NETLINK_FIB_LOOKUP NETLINK_CONNECTOR |
132 | NETLINK_NETFILTER NETLINK_IP6_FW NETLINK_DNRTMSG NETLINK_KOBJECT_UEVENT |
133 | NETLINK_GENERIC NETLINK_DM NETLINK_SCSITRANSPORT NETLINK_ECRYPTFS |
134 | NETLINK_RDMA NETLINK_CRYPTO NETLINK_SMC) |
135 | (define-public NETLINK_INET_DIAG NETLINK_SOCK_DIAG) |
136 | |
137 | (define-enum int->message-kind |
138 | (NLMSG_NOOP 1) |
139 | NLMSG_ERROR |
140 | NLMSG_DONE |
141 | NLMSG_OVERUN |
142 | |
143 | (RTM_NEWLINK 16) |
144 | RTM_DELLINK |
145 | RTM_GETLINK |
146 | RTM_SETLINK |
147 | |
148 | (RTM_NEWADDR 20) |
149 | RTM_DELADDR |
150 | RTM_GETADDR |
151 | |
152 | (RTM_NEWROUTE 24) |
153 | RTM_DELROUTE |
154 | RTM_GETROUTE |
155 | |
156 | (RTM_NEWNEIGH 28) |
157 | RTM_DELNEIGH |
158 | RTML_GETNEIGH |
159 | |
160 | (RTM_NEWRULE 32) |
161 | RTM_DELRULE |
162 | RTM_GETRULE |
163 | |
164 | (RTM_NEWQDISC 36) |
165 | RTM_DELQDISC |
166 | RTM_GETQDISC |
167 | |
168 | (RTM_NEWTCLASS 40) |
169 | RTM_DELTCLASS |
170 | RTM_GETTCLASS |
171 | |
172 | (RTM_NEWTFILTER 44) |
173 | RTM_DELTFILTER |
174 | RTM_GETTFILTER |
175 | |
176 | (RTM_NEWACTION 48) |
177 | RTM_DELACTION |
178 | RTM_GETACTION |
179 | |
180 | (RTM_NEPREFIX 52) |
181 | (RTM_GETMULTICAST 58) |
182 | (RTM_GETANYCAST 62) |
183 | (RTM_NEWNEIGHTBL 64) |
184 | (RTM_GETNEIGHTBL 66) |
185 | RTM_SETNEIGHTBL |
186 | |
187 | (RTM_NEWNDUSEROPT 68) |
188 | (RTM_NEWADDRLABEL 72) |
189 | RTM_DELADDRLABEL |
190 | RTM_GETADDRLABEL |
191 | |
192 | (RTM_GETDCB 78) |
193 | RTM_SETDCB |
194 | |
195 | (RTM_NEWNETCONF 80) |
196 | RTM_DELNETCONF |
197 | RTM_GETNETCONF |
198 | |
199 | (RTM_NEWMDB 84) |
200 | RTM_DELMDB |
201 | RTM_GETMDB |
202 | |
203 | (RTM_NEWNSID 88) |
204 | RTM_DELNSID |
205 | RTM_GETNSID |
206 | |
207 | (RTM_NEWSTATS 92) |
208 | (RTM_GETSTATS 94) |
209 | |
210 | (RTM_NEWCACHEREPORT 92) |
211 | |
212 | (RTM_NEWCHAIN 100) |
213 | RTM_DELCHAIN |
214 | RTM_GETCHAIN |
215 | |
216 | (RTM_NEWNEXTHOP 104) |
217 | RTM_DELNEXTHOP |
218 | RTM_GETNEXTHOP |
219 | |
220 | (RTM_NEWLINKPROP 108) |
221 | RTM_DELLINKPROP |
222 | RTM_GETLINKPROP |
223 | |
224 | (RTM_NEWVLAN 112) |
225 | RTM_DELVLAN |
226 | RTM_GETVLAN) |
227 | |
228 | (define-public NLM_F_REQUEST #x01) |
229 | (define-public NLM_F_MULTI #x02) |
230 | (define-public NLM_F_ACK #x04) |
231 | (define-public NLM_F_ECHO #x08) |
232 | (define-public NLM_F_DUMP_INTR #x10) |
233 | (define-public NLM_F_DUMP_FILTERED #x20) |
234 | |
235 | ;; modifiers to GET requests |
236 | (define-public NLM_F_ROOT #x100) |
237 | (define-public NLM_F_MATCH #x200) |
238 | (define-public NLM_F_ATOMIC #x400) |
239 | (define-public NLM_F_DUMP (logior NLM_F_ROOT NLM_F_MATCH)) |
240 | |
241 | ;; modifiers to NEW requests |
242 | (define-public NLM_F_REPLACE #x100) |
243 | (define-public NLM_F_EXCL #x200) |
244 | (define-public NLM_F_CREATE #x400) |
245 | (define-public NLM_F_APPEND #x800) |
246 | |
247 | (define-public NLM_F_NONREC #x100) |
248 | |
249 | (define-public NLM_F_CAPPED #x100) |
250 | (define-public NLM_F_ACK_TLVS #x200) |
251 | |
252 | ;; net_device_flags |
253 | (define-enum int->device-flags |
254 | (IFF_UP 1) |
255 | (IFF_BROADCAST 2) |
256 | (IFF_DEBUG 4) |
257 | (IFF_LOOPBACK 8) |
258 | (IFF_POINTOPOINT 16) |
259 | (IFF_NOTRAILERS 32) |
260 | (IFF_RUNNING 64) |
261 | (IFF_NOARP 128) |
262 | (IFF_PROMISC 256) |
263 | (IFF_ALLMULTI 512) |
264 | (IFF_MASTER 1024) |
265 | (IFF_SLAVE 2048) |
266 | (IFF_MULTICAST 4096) |
267 | (IFF_PORTSEL 8192) |
268 | (IFF_AUTOMEDIA 16384) |
269 | (IFF_DYNAMIC 32768) |
270 | (IFF_LOWER_UP 65536) |
271 | (IFF_DORMANT 131072) |
272 | (IFF_ECHO 262144)) |
273 | |
274 | ;; operstate |
275 | (define-enum int->operstate |
276 | IF_OPER_UNKNOWN IF_OPER_NOTPRESENT IF_OPER_DOWN |
277 | IF_OPER_LOWERLAYERDOWN IF_OPER_TESTING IF_OPER_DORMANT |
278 | IF_OPER_UP) |
279 | |
280 | ;; ifa_flags |
281 | (define-enum int->ifa-flag |
282 | (IFA_F_SECONDARY #x01) |
283 | (IFA_F_TEMPORARY #x01) |
284 | (IFA_F_NODAD #x02) |
285 | (IFA_F_OPTIMISTIC #x04) |
286 | (IFA_F_DADFAILED #x08) |
287 | (IFA_F_HOMEADDRESS #x10) |
288 | (IFA_F_DEPRECATED #x20) |
289 | (IFA_F_TENTATIVE #x40) |
290 | (IFA_F_PERMANENT #x80) |
291 | (IFA_F_MANAGETEMPADDR #x100) |
292 | (IFA_F_NOPREFIXROUTE #x200) |
293 | (IFA_F_MCAUTOJOIN #x400) |
294 | (IFA_F_STABLE_PRIVACY #x800)) |
295 | |
296 | |
297 | ;; rtm_type |
298 | (define-enum int->rtm-type |
299 | RTN_UNSPEC RTN_UNICAST RTN_LOCAL RTN_BROADCAST RTN_ANYCAST |
300 | RTN_MULTICAST RTN_BLACKHOLE RTN_UNREACHABLE RTN_PROHIBIT |
301 | RTN_THROW RTN_NAT RTN_XRESOLVE) |
302 | |
303 | ;; rtm_protocol |
304 | (define-enum int->rtm-protocol |
305 | RTPROT_UNSPEC RTPROT_REDIRECT RTPROT_KERNEL RTPROT_BOOT RTPROT_STATIC |
306 | ;; not interpreted by the kernel, but returned anyway. |
307 | (RTPROT_GATED 8) |
308 | RTPROT_RA RTPROT_MRT RTPROT_ZEBRA RTPROT_BIRD RTPROT_DNROUTED |
309 | RTPROT_XORP RTPROT_NTK RTPROT_DHCP RTPROT_MROUTED |
310 | (RTPROT_BABEL 42) |
311 | (RTPROT_BGP 186) |
312 | RTPROT_ISIS RTPROT_OSPF RTPROT_RIP |
313 | (RTPROT_EIGRP 192)) |
314 | |
315 | ;; rtm_scope |
316 | (define-enum int->rtm-scope |
317 | RT_SCOPE_UNIVERSE |
318 | (RT_SCOPE_SITE 200) |
319 | (RT_SCOPE_LINK 253) |
320 | (RT_SCOPE_HOST 254) |
321 | (RT_SCOPE_NOWHERE 255)) |
322 | |
323 | ;; rtm_flags |
324 | (define-enum int->rtm-flag |
325 | (RTM_F_NOTIFY #x100) |
326 | (RTM_F_CLONED #x200) |
327 | (RTM_F_EQUALIZE #x400) |
328 | (RTM_F_PREFIX #x800) |
329 | (RTM_F_LOOKUP_TABLE #x1000) |
330 | (RTM_F_FIB_MATCH #x2000) |
331 | (RTM_F_OFFLOAD #x4000) |
332 | (RTM_F_TRAP #x8000)) |
333 | |
334 | |
335 | ;; rtm_table |
336 | (define-enum int->rtm-table |
337 | RT_TABLE_UNSPEC |
338 | (RT_TABLE_COMPAT 252) |
339 | (RT_TABLE_DEFAULT 253) |
340 | (RT_TABLE_MAIN 254) |
341 | (RT_TABLE_LOCAL 255)) |
342 | |
343 | ;; link type |
344 | ;; more at include/uapi/linux/if_arp.h |
345 | (define-enum int->link-type |
346 | (ARPHRD_ETHER 1) |
347 | (ARPHRD_LOOPBACK 772)) |
348 | |
349 | ;; enum rtnetlink_groups |
350 | (define-enum int->rtnetlink-group |
351 | (RTNLGRP_NONE 0) |
352 | RTNLGRP_LINK |
353 | RTNLGRP_NOTIFY |
354 | RTNLGRP_NEIGH |
355 | RTNLGRP_TC |
356 | RTNLGRP_IPV4_IFADDR |
357 | RTNLGRP_IPV4_MROUTE |
358 | RTNLGRP_IPV4_ROUTE |
359 | RTNLGRP_IPV4_RULE |
360 | RTNLGRP_IPV6_IFADDR |
361 | RTNLGRP_IPV6_MROUTE |
362 | RTNLGRP_IPV6_ROUTE |
363 | RTNLGRP_IPV6_IFINFO |
364 | RTNLGRP_DECnet_IFADDR |
365 | RTNLGRP_NOP2 |
366 | RTNLGRP_DECnet_ROUTE |
367 | RTNLGRP_DECnet_RULE |
368 | RTNLGRP_NOP4 |
369 | RTNLGRP_IPV6_PREFIX |
370 | RTNLGRP_IPV6_RULE |
371 | RTNLGRP_ND_USEROPT |
372 | RTNLGRP_PHONET_IFADDR |
373 | RTNLGRP_PHONET_ROUTE |
374 | RTNLGRP_DCB |
375 | RTNLGRP_IPV4_NETCONF |
376 | RTNLGRP_IPV6_NETCONF |
377 | RTNLGRP_MDB |
378 | RTNLGRP_MPLS_ROUTE |
379 | RTNLGRP_NSID |
380 | RTNLGRP_MPLS_NETCONF |
381 | RTNLGRP_IPV4_MROUTE_R |
382 | RTNLGRP_IPV6_MROUTE_R |
383 | RTNLGRP_NEXTHOP |
384 | RTNLGRP_BRVLAN |
385 | RTNLGRP_MCTP_IFADDR |
386 | RTNLGRP_TUNNEL |
387 | RTNLGRP_STATS) |
388 |