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->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-public AF_NETLINK 16) |
75 | (define-public AF_PACKET 17) |
76 | |
77 | (define-enum int->protocol |
78 | NETLINK_ROUTE NETLINK_UNUSED NETLINK_USERSOCK NETLINK_FIREWALL |
79 | NETLINK_SOCK_DIAG NETLINK_NFLOG NETLINK_XFRM NETLINK_SELINUX |
80 | NETLINK_ISCSI NETLINK_AUDIT NETLINK_FIB_LOOKUP NETLINK_CONNECTOR |
81 | NETLINK_NETFILTER NETLINK_IP6_FW NETLINK_DNRTMSG NETLINK_KOBJECT_UEVENT |
82 | NETLINK_GENERIC NETLINK_DM NETLINK_SCSITRANSPORT NETLINK_ECRYPTFS |
83 | NETLINK_RDMA NETLINK_CRYPTO NETLINK_SMC) |
84 | (define-public NETLINK_INET_DIAG NETLINK_SOCK_DIAG) |
85 | |
86 | (define-enum int->message-kind |
87 | (NLMSG_NOOP 1) |
88 | NLMSG_ERROR |
89 | NLMSG_DONE |
90 | NLMSG_OVERUN |
91 | |
92 | (RTM_NEWLINK 16) |
93 | RTM_DELLINK |
94 | RTM_GETLINK |
95 | RTM_SETLINK |
96 | |
97 | (RTM_NEWADDR 20) |
98 | RTM_DELADDR |
99 | RTM_GETADDR |
100 | |
101 | (RTM_NEWROUTE 24) |
102 | RTM_DELROUTE |
103 | RTM_GETROUTE |
104 | |
105 | (RTM_NEWNEIGH 28) |
106 | RTM_DELNEIGH |
107 | RTML_GETNEIGH |
108 | |
109 | (RTM_NEWRULE 32) |
110 | RTM_DELRULE |
111 | RTM_GETRULE |
112 | |
113 | (RTM_NEWQDISC 36) |
114 | RTM_DELQDISC |
115 | RTM_GETQDISC |
116 | |
117 | (RTM_NEWTCLASS 40) |
118 | RTM_DELTCLASS |
119 | RTM_GETTCLASS |
120 | |
121 | (RTM_NEWTFILTER 44) |
122 | RTM_DELTFILTER |
123 | RTM_GETTFILTER |
124 | |
125 | (RTM_NEWACTION 48) |
126 | RTM_DELACTION |
127 | RTM_GETACTION |
128 | |
129 | (RTM_NEPREFIX 52) |
130 | (RTM_GETMULTICAST 58) |
131 | (RTM_GETANYCAST 62) |
132 | (RTM_NEWNEIGHTBL 64) |
133 | (RTM_GETNEIGHTBL 66) |
134 | RTM_SETNEIGHTBL |
135 | |
136 | (RTM_NEWNDUSEROPT 68) |
137 | (RTM_NEWADDRLABEL 72) |
138 | RTM_DELADDRLABEL |
139 | RTM_GETADDRLABEL |
140 | |
141 | (RTM_GETDCB 78) |
142 | RTM_SETDCB |
143 | |
144 | (RTM_NEWNETCONF 80) |
145 | RTM_DELNETCONF |
146 | RTM_GETNETCONF |
147 | |
148 | (RTM_NEWMDB 84) |
149 | RTM_DELMDB |
150 | RTM_GETMDB |
151 | |
152 | (RTM_NEWNSID 88) |
153 | RTM_DELNSID |
154 | RTM_GETNSID |
155 | |
156 | (RTM_NEWSTATS 92) |
157 | (RTM_GETSTATS 94) |
158 | |
159 | (RTM_NEWCACHEREPORT 92) |
160 | |
161 | (RTM_NEWCHAIN 100) |
162 | RTM_DELCHAIN |
163 | RTM_GETCHAIN |
164 | |
165 | (RTM_NEWNEXTHOP 104) |
166 | RTM_DELNEXTHOP |
167 | RTM_GETNEXTHOP |
168 | |
169 | (RTM_NEWLINKPROP 108) |
170 | RTM_DELLINKPROP |
171 | RTM_GETLINKPROP |
172 | |
173 | (RTM_NEWVLAN 112) |
174 | RTM_DELVLAN |
175 | RTM_GETVLAN) |
176 | |
177 | (define-public NLM_F_REQUEST #x01) |
178 | (define-public NLM_F_MULTI #x02) |
179 | (define-public NLM_F_ACK #x04) |
180 | (define-public NLM_F_ECHO #x08) |
181 | (define-public NLM_F_DUMP_INTR #x10) |
182 | (define-public NLM_F_DUMP_FILTERED #x20) |
183 | |
184 | ;; modifiers to GET requests |
185 | (define-public NLM_F_ROOT #x100) |
186 | (define-public NLM_F_MATCH #x200) |
187 | (define-public NLM_F_ATOMIC #x400) |
188 | (define-public NLM_F_DUMP (logior NLM_F_ROOT NLM_F_MATCH)) |
189 | |
190 | ;; modifiers to NEW requests |
191 | (define-public NLM_F_REPLACE #x100) |
192 | (define-public NLM_F_EXCL #x200) |
193 | (define-public NLM_F_CREATE #x400) |
194 | (define-public NLM_F_APPEND #x800) |
195 | |
196 | (define-public NLM_F_NONREC #x100) |
197 | |
198 | (define-public NLM_F_CAPPED #x100) |
199 | (define-public NLM_F_ACK_TLVS #x200) |
200 | |
201 | ;; operstate |
202 | (define-enum int->operstate |
203 | IF_OPER_UNKNOWN IF_OPER_NOTPRESENT IF_OPER_DOWN |
204 | IF_OPER_LOWERLAYERDOWN IF_OPER_TESTING IF_OPER_DORMANT |
205 | IF_OPER_UP) |
206 |