constant.scm
1 | ;;;; Copyright (C) 2020 Julien Lepiller <julien@lepiller.eu> |
2 | ;;;; |
3 | ;;;; This library is free software; you can redistribute it and/or |
4 | ;;;; modify it under the terms of the GNU Lesser General Public |
5 | ;;;; License as published by the Free Software Foundation; either |
6 | ;;;; version 3 of the License, or (at your option) any later version. |
7 | ;;;; |
8 | ;;;; This library is distributed in the hope that it will be useful, |
9 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
11 | ;;;; Lesser General Public License for more details. |
12 | ;;;; |
13 | ;;;; You should have received a copy of the GNU Lesser General Public |
14 | ;;;; License along with this library; if not, write to the Free Software |
15 | ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
16 | ;;;; |
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->addr-attr-kind |
86 | IFA_UNSPEC IFA_ADDRESS IFA_LOCAL IFA_LABEL IFA_BROADCAST |
87 | IFA_ANYCAST IFA_CACHEINFO IFA_MULTICAST IFA_FLAGS |
88 | IFA_RT_PRIORITY IFA_TARGET_NETNSID) |
89 | |
90 | (define-enum int->route-attr-kind |
91 | RTA_UNSPEC RTA_DST RTA_SRC RTA_IIF RTA_OIF RTA_GATEWAY |
92 | RTA_PRIORITY RTA_PREFSRC RTA_METRICS RTA_MULTIPATH |
93 | RTA_PROTOINFO RTA_FLOW RTA_CACHEINFO RTA_SESSION RTA_MP_ALGO |
94 | RTA_TABLE RTA_MARK RTA_MFC_STATS RTA_VIA RTA_NEWDST RTA_PREF |
95 | RTA_ENCAP_TYPE RTA_ENCAP RTA_EXPIRES RTA_PAD RTA_UID |
96 | RTA_TTL_PROPAGATE RTA_IP_PROTO RTA_SPORT RTA_DPORT RTA_NH_ID) |
97 | |
98 | (define-public AF_NETLINK 16) |
99 | (define-public AF_PACKET 17) |
100 | |
101 | (define-enum int->protocol |
102 | NETLINK_ROUTE NETLINK_UNUSED NETLINK_USERSOCK NETLINK_FIREWALL |
103 | NETLINK_SOCK_DIAG NETLINK_NFLOG NETLINK_XFRM NETLINK_SELINUX |
104 | NETLINK_ISCSI NETLINK_AUDIT NETLINK_FIB_LOOKUP NETLINK_CONNECTOR |
105 | NETLINK_NETFILTER NETLINK_IP6_FW NETLINK_DNRTMSG NETLINK_KOBJECT_UEVENT |
106 | NETLINK_GENERIC NETLINK_DM NETLINK_SCSITRANSPORT NETLINK_ECRYPTFS |
107 | NETLINK_RDMA NETLINK_CRYPTO NETLINK_SMC) |
108 | (define-public NETLINK_INET_DIAG NETLINK_SOCK_DIAG) |
109 | |
110 | (define-enum int->message-kind |
111 | (NLMSG_NOOP 1) |
112 | NLMSG_ERROR |
113 | NLMSG_DONE |
114 | NLMSG_OVERUN |
115 | |
116 | (RTM_NEWLINK 16) |
117 | RTM_DELLINK |
118 | RTM_GETLINK |
119 | RTM_SETLINK |
120 | |
121 | (RTM_NEWADDR 20) |
122 | RTM_DELADDR |
123 | RTM_GETADDR |
124 | |
125 | (RTM_NEWROUTE 24) |
126 | RTM_DELROUTE |
127 | RTM_GETROUTE |
128 | |
129 | (RTM_NEWNEIGH 28) |
130 | RTM_DELNEIGH |
131 | RTML_GETNEIGH |
132 | |
133 | (RTM_NEWRULE 32) |
134 | RTM_DELRULE |
135 | RTM_GETRULE |
136 | |
137 | (RTM_NEWQDISC 36) |
138 | RTM_DELQDISC |
139 | RTM_GETQDISC |
140 | |
141 | (RTM_NEWTCLASS 40) |
142 | RTM_DELTCLASS |
143 | RTM_GETTCLASS |
144 | |
145 | (RTM_NEWTFILTER 44) |
146 | RTM_DELTFILTER |
147 | RTM_GETTFILTER |
148 | |
149 | (RTM_NEWACTION 48) |
150 | RTM_DELACTION |
151 | RTM_GETACTION |
152 | |
153 | (RTM_NEPREFIX 52) |
154 | (RTM_GETMULTICAST 58) |
155 | (RTM_GETANYCAST 62) |
156 | (RTM_NEWNEIGHTBL 64) |
157 | (RTM_GETNEIGHTBL 66) |
158 | RTM_SETNEIGHTBL |
159 | |
160 | (RTM_NEWNDUSEROPT 68) |
161 | (RTM_NEWADDRLABEL 72) |
162 | RTM_DELADDRLABEL |
163 | RTM_GETADDRLABEL |
164 | |
165 | (RTM_GETDCB 78) |
166 | RTM_SETDCB |
167 | |
168 | (RTM_NEWNETCONF 80) |
169 | RTM_DELNETCONF |
170 | RTM_GETNETCONF |
171 | |
172 | (RTM_NEWMDB 84) |
173 | RTM_DELMDB |
174 | RTM_GETMDB |
175 | |
176 | (RTM_NEWNSID 88) |
177 | RTM_DELNSID |
178 | RTM_GETNSID |
179 | |
180 | (RTM_NEWSTATS 92) |
181 | (RTM_GETSTATS 94) |
182 | |
183 | (RTM_NEWCACHEREPORT 92) |
184 | |
185 | (RTM_NEWCHAIN 100) |
186 | RTM_DELCHAIN |
187 | RTM_GETCHAIN |
188 | |
189 | (RTM_NEWNEXTHOP 104) |
190 | RTM_DELNEXTHOP |
191 | RTM_GETNEXTHOP |
192 | |
193 | (RTM_NEWLINKPROP 108) |
194 | RTM_DELLINKPROP |
195 | RTM_GETLINKPROP |
196 | |
197 | (RTM_NEWVLAN 112) |
198 | RTM_DELVLAN |
199 | RTM_GETVLAN) |
200 | |
201 | (define-public NLM_F_REQUEST #x01) |
202 | (define-public NLM_F_MULTI #x02) |
203 | (define-public NLM_F_ACK #x04) |
204 | (define-public NLM_F_ECHO #x08) |
205 | (define-public NLM_F_DUMP_INTR #x10) |
206 | (define-public NLM_F_DUMP_FILTERED #x20) |
207 | |
208 | ;; modifiers to GET requests |
209 | (define-public NLM_F_ROOT #x100) |
210 | (define-public NLM_F_MATCH #x200) |
211 | (define-public NLM_F_ATOMIC #x400) |
212 | (define-public NLM_F_DUMP (logior NLM_F_ROOT NLM_F_MATCH)) |
213 | |
214 | ;; modifiers to NEW requests |
215 | (define-public NLM_F_REPLACE #x100) |
216 | (define-public NLM_F_EXCL #x200) |
217 | (define-public NLM_F_CREATE #x400) |
218 | (define-public NLM_F_APPEND #x800) |
219 | |
220 | (define-public NLM_F_NONREC #x100) |
221 | |
222 | (define-public NLM_F_CAPPED #x100) |
223 | (define-public NLM_F_ACK_TLVS #x200) |
224 | |
225 | ;; net_device_flags |
226 | (define-enum int->device-flags |
227 | (IFF_UP 1) |
228 | (IFF_BROADCAST 2) |
229 | (IFF_DEBUG 4) |
230 | (IFF_LOOPBACK 8) |
231 | (IFF_POINTOPOINT 16) |
232 | (IFF_NOTRAILERS 32) |
233 | (IFF_RUNNING 64) |
234 | (IFF_NOARP 128) |
235 | (IFF_PROMISC 256) |
236 | (IFF_ALLMULTI 512) |
237 | (IFF_MASTER 1024) |
238 | (IFF_SLAVE 2048) |
239 | (IFF_MULTICAST 4096) |
240 | (IFF_PORTSEL 8192) |
241 | (IFF_AUTOMEDIA 16384) |
242 | (IFF_DYNAMIC 32768) |
243 | (IFF_LOWER_UP 65536) |
244 | (IFF_DORMANT 131072) |
245 | (IFF_ECHO 262144)) |
246 | |
247 | ;; operstate |
248 | (define-enum int->operstate |
249 | IF_OPER_UNKNOWN IF_OPER_NOTPRESENT IF_OPER_DOWN |
250 | IF_OPER_LOWERLAYERDOWN IF_OPER_TESTING IF_OPER_DORMANT |
251 | IF_OPER_UP) |
252 | |
253 | ;; ifa_flags |
254 | (define-enum int->ifa-flag |
255 | (IFA_F_SECONDARY #x01) |
256 | (IFA_F_TEMPORARY #x01) |
257 | (IFA_F_NODAD #x02) |
258 | (IFA_F_OPTIMISTIC #x04) |
259 | (IFA_F_DADFAILED #x08) |
260 | (IFA_F_HOMEADDRESS #x10) |
261 | (IFA_F_DEPRECATED #x20) |
262 | (IFA_F_TENTATIVE #x40) |
263 | (IFA_F_PERMANENT #x80) |
264 | (IFA_F_MANAGETEMPADDR #x100) |
265 | (IFA_F_NOPREFIXROUTE #x200) |
266 | (IFA_F_MCAUTOJOIN #x400) |
267 | (IFA_F_STABLE_PRIVACY #x800)) |
268 | |
269 | |
270 | ;; rtm_type |
271 | (define-enum int->rtm-type |
272 | RTN_UNSPEC RTN_UNICAST RTN_LOCAL RTN_BROADCAST RTN_ANYCAST |
273 | RTN_MULTICAST RTN_BLACKHOLE RTN_UNREACHABLE RTN_PROHIBIT |
274 | RTN_THROW RTN_NAT RTN_XRESOLVE) |
275 | |
276 | ;; rtm_protocol |
277 | (define-enum int->rtm-protocol |
278 | RTPROT_UNSPEC RTPROT_REDIRECT RTPROT_KERNEL RTPROT_BOOT RTPROT_STATIC |
279 | ;; not interpreted by the kernel, but returned anyway. |
280 | (RTPROT_GATED 8) |
281 | RTPROT_RA RTPROT_MRT RTPROT_ZEBRA RTPROT_BIRD RTPROT_DNROUTED |
282 | RTPROT_XORP RTPROT_NTK RTPROT_DHCP RTPROT_MROUTED |
283 | (RTPROT_BABEL 42) |
284 | (RTPROT_BGP 186) |
285 | RTPROT_ISIS RTPROT_OSPF RTPROT_RIP |
286 | (RTPROT_EIGRP 192)) |
287 | |
288 | ;; rtm_scope |
289 | (define-enum int->rtm-scope |
290 | RT_SCOPE_UNIVERSE |
291 | (RT_SCOPE_SITE 200) |
292 | (RT_SCOPE_LINK 253) |
293 | (RT_SCOPE_HOST 254) |
294 | (RT_SCOPE_NOWHERE 255)) |
295 | |
296 | ;; rtm_flags |
297 | (define-enum int->rtm-flag |
298 | (RTM_F_NOTIFY #x100) |
299 | (RTM_F_CLONED #x200) |
300 | (RTM_F_EQUALIZE #x400) |
301 | (RTM_F_PREFIX #x800) |
302 | (RTM_F_LOOKUP_TABLE #x1000) |
303 | (RTM_F_FIB_MATCH #x2000) |
304 | (RTM_F_OFFLOAD #x4000) |
305 | (RTM_F_TRAP #x8000)) |
306 | |
307 | |
308 | ;; rtm_table |
309 | (define-enum int->rtm-table |
310 | RT_TABLE_UNSPEC |
311 | (RT_TABLE_COMPAT 252) |
312 | (RT_TABLE_DEFAULT 253) |
313 | (RT_TABLE_MAIN 254) |
314 | (RT_TABLE_LOCAL 255)) |
315 | |
316 | ;; link type |
317 | ;; more at include/uapi/linux/if_arp.h |
318 | (define-enum int->link-type |
319 | (ARPHRD_ETHER 1) |
320 | (ARPHRD_LOOPBACK 772)) |
321 |