guile-netlink/netlink/constant.scm

constant.scm

1
;;;; This file is part of Guile Netlink
2
;;;;
3
;;;; Copyright (C) 2020, 2025 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
;; Defined in [kernel]/include/uapi/linux/if_link.h
58
(define-enum int->link-attr-kind
59
  IFLA_UNSPEC IFLA_ADDRESS IFLA_BROADCAST IFLA_IFNAME IFLA_MTU
60
  IFLA_LINK IFLA_QDISC IFLA_STATS IFLA_COST IFLA_PRIORITY
61
  IFLA_MASTER IFLA_WIRELESS IFLA_PROTIFO IFLA_TXQLEN IFLA_MAP
62
  IFLA_WEIGHT IFLA_OPERSTATE IFLA_LINKMODE IFLA_LINKINFO
63
  IFLA_NET_NS_PID IFLA_IFALIAS IFLA_NUM_VF IFLA_VFINFO_LIST
64
  IFLA_STATS64 IFLA_VF_PORTS IFLA_PORT_SELF IFLA_AF_SPEC
65
  IFLA_GROUP IFLA_NET_NS_FD IFLA_EXT_MASK IFLA_PROMISCUITY
66
  IFLA_NUM_TX_QUEUES IFLA_NUM_RX_QUEUES IFLA_CARRIER
67
  IFLA_PHYS_PORT_ID IFLA_CARRIER_CHANGES IFLA_PHYS_SWITCH_ID
68
  IFLA_LINK_NETNSID IFLA_PHYS_PORT_NAME IFLA_PROTO_DOWN
69
  IFLA_GSO_MAX_SEGS IFLA_GSO_MAX_SIZE IFLA_PAD IFLA_XDP
70
  IFLA_EVENT IFLA_NEW_NETNSID IFLA_IF_NETNSID IFLA_CARRIER_UP_COUNT
71
  IFLA_CARRIER_DOWN_COUNT IFLA_NEW_IFINDEX IFLA_MIN_MTU IFLA_MAX_MTU
72
  IFLA_PROP_LIST IFLA_ALT_IFNAME IFLA_PERM_ADDRESS IFLA_PROTO_DOWN_REASON
73
  IFLA_PARENT_DEV_NAME IFLA_PARENT_DEV_BUS_NAME IFLA_GRO_MAX_SIZE
74
  IFLA_TSO_MAX_SIZE IFLA_TSO_MAX_SEGS IFLA_ALLMULTI IFLA_DEVLINK_PORT
75
  IFLA_GSO_IPV4_MAX_SIZE IFLA_GRO_IPV4_MAX_SIZE IFLA_DPLL_PIN)
76
(define-public IFLA_TARGET_NETNSID IFLA_IF_NETNSID)
77
78
;; Defined in [kernel]/include/uapi/linux/if_link.h
79
(define-enum int->linkinfo
80
  IFLA_INFO_UNSPEC IFLA_INFO_KIND IFLA_INFO_DATA IFLA_INFO_XSTATS
81
  IFLA_INFO_SLAVE_KIND IFLA_INFO_SLAVE_DATA)
82
83
;; Defined in [kernel]/include/uapi/linux/veth.h
84
(define-enum int->veth-linkinfo
85
  VETH_INFO_UNSPEC VETH_INFO_PEER)
86
87
;; Defined in [kernel]/include/uapi/linux/if_link.h
88
(define-enum int->vlan-linkinfo
89
  IFLA_VLAN_UNSPEC IFLA_VLAN_ID IFLA_VLAN_FLAGS IFLA_VLAN_EGRESS_QOS
90
  IFLA_VLAN_INGRESS_QOS IFLA_VLAN_PROTOCOL)
91
92
;; Defined in [kernel]/include/uapi/linux/if_link.h
93
(define-enum int->bond-linkinfo
94
  IFLA_BOND_UNSPEC IFLA_BOND_MODE IFLA_BOND_ACTIVE_SLAVE IFLA_BOND_MIIMON
95
  IFLA_BOND_UPDELAY IFLA_BOND_DOWNDELAY IFLA_BOND_USE_CARRIER IFLA_BOND_ARP_INTERVAL
96
  IFLA_BOND_ARP_IP_TARGET IFLA_BOND_ARP_VALIDATE IFLA_BOND_ARP_ALL_TARGETS
97
  IFLA_BOND_PRIMARY IFLA_BOND_PRIMARY_RESELECT IFLA_BOND_FAIL_OVER_MAC IFLA_BOND_XMIT_HASH_POLICY
98
  IFLA_BOND_RESEND_IGMP IFLA_BOND_NUM_PEER_NOTIF IFLA_BOND_ALL_SLAVES_ACTIVE
99
  IFLA_BOND_MIN_LINKS IFLA_BOND_LP_INTERVAL IFLA_BOND_PACKETS_PER_SLAVE
100
  IFLA_BOND_AD_LACP_RATE IFLA_BOND_AD_SELECT IFLA_BOND_AD_INFO IFLA_BOND_AD_ACTOR_SYS_PRIO
101
  IFLA_BOND_AD_USER_PORT_KEY IFLA_BOND_AD_ACTOR_SYSTEM IFLA_BOND_TLB_DYNAMIC_LB
102
  IFLA_BOND_PEER_NOTIF_DELAY IFLA_BOND_AD_LACP_ACTIVE IFLA_BOND_MISSED_MAX IFLA_BOND_NS_IP6_TARGET)
103
104
;; see iproute2/ip/iplink_bond.c for mode_tbl
105
;; Defined in [kernel]/include/uapi/linux/if_bonding.h
106
(define-enum int->bond-mode
107
  BOND_MODE_ROUNDROBIN BOND_MODE_ACTIVEBACKUP BOND_MODE_XOR BOND_MODE_BROADCAST
108
  BOND_MODE_8023AD BOND_MODE_TLB
109
  ;; TLB + RLB (receive load balancing)
110
  BOND_MODE_ALB)
111
112
;; Defined in [kernel]/include/net/bonding.h
113
(define-public BOND_PRIMARY_RESELECT_ALWAYS 0)
114
(define-public BOND_PRIMARY_RESELECT_BETTER 1)
115
(define-public BOND_PRIMARY_RESELECT_FAILURE 2)
116
117
;; see iproute2/ip/iplink_bond.c for lacp_active_tbl
118
(define-public BOND_AD_LACP_ACTIVE_OFF 0)
119
(define-public BOND_AD_LACP_ACTIVE_ON 1)
120
121
;; Defined in [kernel]/include/uapi/linux/if_addr.h
122
(define-enum int->addr-attr-kind
123
  IFA_UNSPEC IFA_ADDRESS IFA_LOCAL IFA_LABEL IFA_BROADCAST
124
  IFA_ANYCAST IFA_CACHEINFO IFA_MULTICAST IFA_FLAGS
125
  IFA_RT_PRIORITY IFA_TARGET_NETNSID IFA_PROTO)
126
127
;; Defined in [kernel]/include/uapi/linux/rtnetlink.h
128
(define-enum int->route-attr-kind
129
  RTA_UNSPEC RTA_DST RTA_SRC RTA_IIF RTA_OIF RTA_GATEWAY
130
  RTA_PRIORITY RTA_PREFSRC RTA_METRICS RTA_MULTIPATH
131
  RTA_PROTOINFO RTA_FLOW RTA_CACHEINFO RTA_SESSION RTA_MP_ALGO
132
  RTA_TABLE RTA_MARK RTA_MFC_STATS RTA_VIA RTA_NEWDST RTA_PREF
133
  RTA_ENCAP_TYPE RTA_ENCAP RTA_EXPIRES RTA_PAD RTA_UID
134
  RTA_TTL_PROPAGATE RTA_IP_PROTO RTA_SPORT RTA_DPORT RTA_NH_ID)
135
136
(define-public AF_NETLINK 16)
137
(define-public AF_PACKET 17)
138
139
;; Defined in [kernel]/include/uapi/linux/netlink.h
140
(define-enum int->protocol
141
  NETLINK_ROUTE NETLINK_UNUSED NETLINK_USERSOCK NETLINK_FIREWALL
142
  NETLINK_SOCK_DIAG NETLINK_NFLOG NETLINK_XFRM NETLINK_SELINUX
143
  NETLINK_ISCSI NETLINK_AUDIT NETLINK_FIB_LOOKUP NETLINK_CONNECTOR
144
  NETLINK_NETFILTER NETLINK_IP6_FW NETLINK_DNRTMSG NETLINK_KOBJECT_UEVENT
145
  NETLINK_GENERIC NETLINK_DM NETLINK_SCSITRANSPORT NETLINK_ECRYPTFS
146
  NETLINK_RDMA NETLINK_CRYPTO NETLINK_SMC)
147
(define-public NETLINK_INET_DIAG NETLINK_SOCK_DIAG)
148
149
(define-enum int->message-kind
150
;; Defined in [kernel]/include/uapi/linux/netlink.h
151
  (NLMSG_NOOP 1)
152
  NLMSG_ERROR
153
  NLMSG_DONE
154
  NLMSG_OVERUN
155
  
156
;; Defined in [kernel]/include/uapi/linux/rtnetlink.h
157
  (RTM_NEWLINK 16)
158
  RTM_DELLINK
159
  RTM_GETLINK
160
  RTM_SETLINK
161
162
  (RTM_NEWADDR 20)
163
  RTM_DELADDR
164
  RTM_GETADDR
165
  
166
  (RTM_NEWROUTE 24)
167
  RTM_DELROUTE
168
  RTM_GETROUTE
169
170
  (RTM_NEWNEIGH 28)
171
  RTM_DELNEIGH
172
  RTML_GETNEIGH
173
174
  (RTM_NEWRULE 32)
175
  RTM_DELRULE
176
  RTM_GETRULE
177
178
  (RTM_NEWQDISC 36)
179
  RTM_DELQDISC
180
  RTM_GETQDISC
181
182
  (RTM_NEWTCLASS 40)
183
  RTM_DELTCLASS
184
  RTM_GETTCLASS
185
186
  (RTM_NEWTFILTER 44)
187
  RTM_DELTFILTER
188
  RTM_GETTFILTER
189
190
  (RTM_NEWACTION 48)
191
  RTM_DELACTION
192
  RTM_GETACTION
193
194
  (RTM_NEPREFIX 52)
195
  (RTM_GETMULTICAST 58)
196
  (RTM_GETANYCAST 62)
197
  (RTM_NEWNEIGHTBL 64)
198
  (RTM_GETNEIGHTBL 66)
199
  RTM_SETNEIGHTBL
200
201
  (RTM_NEWNDUSEROPT 68)
202
  (RTM_NEWADDRLABEL 72)
203
  RTM_DELADDRLABEL
204
  RTM_GETADDRLABEL
205
206
  (RTM_GETDCB 78)
207
  RTM_SETDCB
208
209
  (RTM_NEWNETCONF 80)
210
  RTM_DELNETCONF
211
  RTM_GETNETCONF
212
213
  (RTM_NEWMDB 84)
214
  RTM_DELMDB
215
  RTM_GETMDB
216
217
  (RTM_NEWNSID 88)
218
  RTM_DELNSID
219
  RTM_GETNSID
220
221
  (RTM_NEWSTATS 92)
222
  (RTM_GETSTATS 94)
223
224
  (RTM_NEWCACHEREPORT 92)
225
226
  (RTM_NEWCHAIN 100)
227
  RTM_DELCHAIN
228
  RTM_GETCHAIN
229
230
  (RTM_NEWNEXTHOP 104)
231
  RTM_DELNEXTHOP
232
  RTM_GETNEXTHOP
233
234
  (RTM_NEWLINKPROP 108)
235
  RTM_DELLINKPROP
236
  RTM_GETLINKPROP
237
238
  (RTM_NEWVLAN 112)
239
  RTM_DELVLAN
240
  RTM_GETVLAN)
241
242
;; Defined in [kernel]/include/uapi/linux/netlink.h
243
(define-public NLM_F_REQUEST #x01)
244
(define-public NLM_F_MULTI #x02)
245
(define-public NLM_F_ACK #x04)
246
(define-public NLM_F_ECHO #x08)
247
(define-public NLM_F_DUMP_INTR #x10)
248
(define-public NLM_F_DUMP_FILTERED #x20)
249
250
;; modifiers to GET requests
251
(define-public NLM_F_ROOT #x100)
252
(define-public NLM_F_MATCH #x200)
253
(define-public NLM_F_ATOMIC #x400)
254
(define-public NLM_F_DUMP (logior NLM_F_ROOT NLM_F_MATCH))
255
256
;; modifiers to NEW requests
257
(define-public NLM_F_REPLACE #x100)
258
(define-public NLM_F_EXCL #x200)
259
(define-public NLM_F_CREATE #x400)
260
(define-public NLM_F_APPEND #x800)
261
262
(define-public NLM_F_NONREC #x100)
263
264
(define-public NLM_F_CAPPED #x100)
265
(define-public NLM_F_ACK_TLVS #x200)
266
267
;; net_device_flags
268
;; Defined in [kernel]/include/uapi/linux/if.h
269
(define-enum int->device-flags
270
  (IFF_UP 1)
271
  (IFF_BROADCAST 2)
272
  (IFF_DEBUG 4)
273
  (IFF_LOOPBACK 8)
274
  (IFF_POINTOPOINT 16)
275
  (IFF_NOTRAILERS 32)
276
  (IFF_RUNNING 64)
277
  (IFF_NOARP 128)
278
  (IFF_PROMISC 256)
279
  (IFF_ALLMULTI 512)
280
  (IFF_MASTER 1024)
281
  (IFF_SLAVE 2048)
282
  (IFF_MULTICAST 4096)
283
  (IFF_PORTSEL 8192)
284
  (IFF_AUTOMEDIA 16384)
285
  (IFF_DYNAMIC 32768)
286
  (IFF_LOWER_UP 65536)
287
  (IFF_DORMANT 131072)
288
  (IFF_ECHO 262144))
289
290
;; operstate
291
;; Defined in [kernel]/include/uapi/linux/if.h
292
(define-enum int->operstate
293
  IF_OPER_UNKNOWN IF_OPER_NOTPRESENT IF_OPER_DOWN
294
  IF_OPER_LOWERLAYERDOWN IF_OPER_TESTING IF_OPER_DORMANT
295
  IF_OPER_UP)
296
297
;; ifa_flags
298
;; Defined in [kernel]/include/uapi/linux/if_addr.h
299
(define-enum int->ifa-flag
300
  (IFA_F_SECONDARY      #x01)
301
  (IFA_F_TEMPORARY      #x01) 
302
  (IFA_F_NODAD          #x02)
303
  (IFA_F_OPTIMISTIC     #x04)
304
  (IFA_F_DADFAILED      #x08)
305
  (IFA_F_HOMEADDRESS    #x10)
306
  (IFA_F_DEPRECATED     #x20)
307
  (IFA_F_TENTATIVE      #x40)
308
  (IFA_F_PERMANENT      #x80)
309
  (IFA_F_MANAGETEMPADDR #x100)
310
  (IFA_F_NOPREFIXROUTE  #x200)
311
  (IFA_F_MCAUTOJOIN     #x400)
312
  (IFA_F_STABLE_PRIVACY #x800))
313
314
315
;; rtm_type
316
;; Defined in [kernel]/include/uapi/linux/rtnetlink.h
317
(define-enum int->rtm-type
318
  RTN_UNSPEC RTN_UNICAST RTN_LOCAL RTN_BROADCAST RTN_ANYCAST
319
  RTN_MULTICAST RTN_BLACKHOLE RTN_UNREACHABLE RTN_PROHIBIT
320
  RTN_THROW RTN_NAT RTN_XRESOLVE)
321
322
;; rtm_protocol
323
;; Defined in [kernel]/include/uapi/linux/rtnetlink.h
324
(define-enum int->rtm-protocol
325
  RTPROT_UNSPEC RTPROT_REDIRECT RTPROT_KERNEL RTPROT_BOOT RTPROT_STATIC
326
  ;; not interpreted by the kernel, but returned anyway.
327
  (RTPROT_GATED 8)
328
  RTPROT_RA RTPROT_MRT RTPROT_ZEBRA RTPROT_BIRD RTPROT_DNROUTED
329
  RTPROT_XORP RTPROT_NTK RTPROT_DHCP RTPROT_MROUTED
330
  (RTPROT_BABEL 42)
331
  (RTPROT_BGP 186)
332
  RTPROT_ISIS RTPROT_OSPF RTPROT_RIP
333
  (RTPROT_EIGRP 192))
334
335
;; rtm_scope
336
;; Defined in [kernel]/include/uapi/linux/rtnetlink.h
337
(define-enum int->rtm-scope
338
  RT_SCOPE_UNIVERSE
339
  (RT_SCOPE_SITE 200)
340
  (RT_SCOPE_LINK 253)
341
  (RT_SCOPE_HOST 254)
342
  (RT_SCOPE_NOWHERE 255))
343
344
;; rtm_flags
345
;; Defined in [kernel]/include/uapi/linux/rtnetlink.h
346
(define-enum int->rtm-flag
347
  (RTM_F_NOTIFY #x100)
348
  (RTM_F_CLONED #x200)
349
  (RTM_F_EQUALIZE #x400)
350
  (RTM_F_PREFIX #x800)
351
  (RTM_F_LOOKUP_TABLE #x1000)
352
  (RTM_F_FIB_MATCH #x2000)
353
  (RTM_F_OFFLOAD #x4000)
354
  (RTM_F_TRAP #x8000))
355
356
357
;; rtm_table
358
;; Defined in [kernel]/include/uapi/linux/rtnetlink.h
359
(define-enum int->rtm-table
360
  RT_TABLE_UNSPEC
361
  (RT_TABLE_COMPAT 252)
362
  (RT_TABLE_DEFAULT 253)
363
  (RT_TABLE_MAIN 254)
364
  (RT_TABLE_LOCAL 255))
365
366
;; link type
367
;; Defined in [kernel]/include/uapi/linux/if_arp.h
368
(define-enum int->link-type
369
  (ARPHRD_ETHER 1)
370
  (ARPHRD_LOOPBACK 772))
371
372
;; enum rtnetlink_groups
373
;; Defined in [kernel]/include/uapi/linux/rtnetlink.h
374
(define-enum int->rtnetlink-group
375
  (RTNLGRP_NONE 0)
376
  RTNLGRP_LINK
377
  RTNLGRP_NOTIFY
378
  RTNLGRP_NEIGH
379
  RTNLGRP_TC
380
  RTNLGRP_IPV4_IFADDR
381
  RTNLGRP_IPV4_MROUTE
382
  RTNLGRP_IPV4_ROUTE
383
  RTNLGRP_IPV4_RULE
384
  RTNLGRP_IPV6_IFADDR
385
  RTNLGRP_IPV6_MROUTE
386
  RTNLGRP_IPV6_ROUTE
387
  RTNLGRP_IPV6_IFINFO
388
  RTNLGRP_DECnet_IFADDR
389
  RTNLGRP_NOP2
390
  RTNLGRP_DECnet_ROUTE
391
  RTNLGRP_DECnet_RULE
392
  RTNLGRP_NOP4
393
  RTNLGRP_IPV6_PREFIX
394
  RTNLGRP_IPV6_RULE
395
  RTNLGRP_ND_USEROPT
396
  RTNLGRP_PHONET_IFADDR
397
  RTNLGRP_PHONET_ROUTE
398
  RTNLGRP_DCB
399
  RTNLGRP_IPV4_NETCONF
400
  RTNLGRP_IPV6_NETCONF
401
  RTNLGRP_MDB
402
  RTNLGRP_MPLS_ROUTE
403
  RTNLGRP_NSID
404
  RTNLGRP_MPLS_NETCONF
405
  RTNLGRP_IPV4_MROUTE_R
406
  RTNLGRP_IPV6_MROUTE_R
407
  RTNLGRP_NEXTHOP
408
  RTNLGRP_BRVLAN
409
  RTNLGRP_MCTP_IFADDR
410
  RTNLGRP_TUNNEL
411
  RTNLGRP_STATS)
412
413
;; Defined in [kernel]/include/uapi/linux/genetlink.h
414
(define-enum int->genetlink-command
415
  (CTRL_CMD_UNSPEC 0)
416
  CTRL_CMD_NEWFAMILY
417
  CTRL_CMD_DELFAMILY
418
  CTRL_CMD_GETFAMILY
419
  CTRL_CMD_NEWOPS
420
  CTRL_CMD_DELOPS
421
  CTRL_CMD_GETOPS
422
  CTRL_CMD_NEWMCAST_GRP
423
  CTRL_CMD_DELMCAST_GRP
424
  CTRL_CMD_GETMCAST_GRP
425
  CTRL_CMD_GETPOLICY)
426
427
;; Defined in [kernel]/include/uapi/linux/genetlink.h
428
(define-enum int->genetlink-attr
429
  (CTRL_ATTR_UNSPEC 0)
430
  CTRL_ATTR_FAMILY_ID
431
  CTRL_ATTR_FAMILY_NAME
432
  CTRL_ATTR_VERSION
433
  CTRL_ATTR_HDRSIZE
434
  CTRL_ATTR_MAXATTR
435
  CTRL_ATTR_OPS
436
  CTRL_ATTR_MCAST_GROUPS
437
  CTRL_ATTR_POLICY
438
  CTRL_ATTR_OP_POLICY
439
  CTRL_ATTR_OP)
440
441
;; Defined in [kernel]/include/uapi/linux/genetlink.h
442
(define-enum int->genetlink-attr-op
443
  (CTRL_ATTR_OP_UNSPEC 0)
444
  CTRL_ATTR_OP_ID
445
  CTRL_ATTR_OP_FLAGS)
446
447
;; Defined in [kernel]/include/uapi/linux/genetlink.h
448
(define-enum int->genetlink-attr-mcast
449
  (CTRL_ATTR_MCAST_GRP_UNSPEC 0)
450
  CTRL_ATTR_MCAST_GRP_NAME
451
  CTRL_ATTR_MCAST_GRP_ID)
452
453
;; Defined in [kernel]/include/uapi/linux/genetlink.h
454
(define-enum int->genetlink-attr-policy
455
  (CTRL_ATTR_POLICY_UNSPEC 0)
456
  CTRL_ATTR_POLICY_DO
457
  CTRL_ATTR_POLICY_DUMP)
458
459
;; Defined in [kernel]/include/uapi/linux/genetlink.h
460
(define-enum int->genetlink-identifiers
461
  (GENL_ID_CTRL #x10)
462
  GENL_ID_VFS_DQUOT
463
  GENL_ID_PMCRAID)
464