Compare commits
1433 Commits
v1.3.4
...
burble.dn4
Author | SHA1 | Date | |
---|---|---|---|
256e198fee | |||
18853a82c6 | |||
e6133456c1 | |||
b86d3f9a2e | |||
910f9127f0 | |||
ce7a2736e9 | |||
397c52070a | |||
|
4aecc5f8cd | ||
|
3155bb34be | ||
|
82f19ba95e | ||
|
f1ffe6a231 | ||
|
5a6e8380f8 | ||
|
454ae30445 | ||
|
0a3db4c680 | ||
|
2f98153490 | ||
|
ae9ae864d3 | ||
|
94abefc00b | ||
|
0d1a11cca3 | ||
|
6489a2450e | ||
|
7be3af7fa6 | ||
|
9cf3d53311 | ||
|
211fe69c98 | ||
|
d3782c72b9 | ||
|
77ce849ecf | ||
|
714238716e | ||
|
00b85905b9 | ||
|
d06a875b04 | ||
|
5d414309ec | ||
|
df83f62697 | ||
|
a40ddf5c61 | ||
|
d774f6d721 | ||
|
910adaa08b | ||
|
17663b6a7c | ||
|
2a8cc7259e | ||
|
a141959f07 | ||
|
7a1f4baac1 | ||
|
4155104c90 | ||
|
21f9acd2a0 | ||
|
455c13dc99 | ||
|
ea3c6c1a15 | ||
|
9e2635505a | ||
|
61dae32b29 | ||
|
8cc5bb09e3 | ||
|
2465867712 | ||
|
62d57b9bdf | ||
|
0ef082c51e | ||
|
30b8468269 | ||
|
1678bc0746 | ||
|
c9ae81656f | ||
|
db2d29073a | ||
|
3347aaafec | ||
|
df65d519d6 | ||
|
00ddd18b02 | ||
|
6ea8a46ccb | ||
|
b962967e20 | ||
|
4a42e7e925 | ||
|
3b56bf8849 | ||
|
99ad208dd7 | ||
|
9d3fc3062b | ||
|
fc1e3211b1 | ||
|
6c11dbcf28 | ||
|
14ce8904e7 | ||
|
600eb695b1 | ||
|
dc8d9dec4a | ||
|
c0e1f534c9 | ||
|
c26c6bc2d7 | ||
|
a948cf9a5c | ||
|
4ef0a96639 | ||
|
82937b465b | ||
|
71e08edd94 | ||
|
63451c1961 | ||
|
f1b5f179db | ||
|
19f8f17320 | ||
|
fae5448134 | ||
|
eee8af4db2 | ||
|
4e8f8afc68 | ||
|
c1632ad0f3 | ||
|
1ca7665fa4 | ||
|
b729e731f9 | ||
|
ec430a7fee | ||
|
5fc8407177 | ||
|
b8bbbbaf56 | ||
|
f7c34aa227 | ||
|
e6785c469b | ||
|
82bfee76f0 | ||
|
b12442c985 | ||
|
048eb2ddf1 | ||
|
59238768b3 | ||
|
ea259d6201 | ||
|
0c3b8ffe25 | ||
|
cdde3550dc | ||
|
9ac13d7af2 | ||
|
e26a5195dd | ||
|
3bb10b4d31 | ||
|
258be56539 | ||
|
a7d9b8f116 | ||
|
0fa8bf91cd | ||
|
bbe49ae569 | ||
|
a08853a269 | ||
|
5f60d14ede | ||
|
b748220906 | ||
|
9e64ac4b7c | ||
|
dccee40826 | ||
|
baac700906 | ||
|
a0d0a71a18 | ||
|
a1b61a271a | ||
|
d65a926a67 | ||
|
30ba7c1661 | ||
|
bf9486bf20 | ||
|
17de3a023f | ||
|
8029ae527e | ||
|
d607205486 | ||
|
124d860f64 | ||
|
59a86cbc7c | ||
|
b465604eb1 | ||
|
716e11a584 | ||
|
3c838ad9fd | ||
|
a6548d5b5b | ||
|
fd9f0c0640 | ||
|
a109056145 | ||
|
2928c5bcc7 | ||
|
c9d11e6230 | ||
|
2755002890 | ||
|
d516c68ad8 | ||
|
dc042d87cb | ||
|
e2630a494e | ||
|
1ad98965c5 | ||
|
ead531ffef | ||
|
e6746da6de | ||
|
78e4a123bb | ||
|
757cab18d6 | ||
|
22c3cf955d | ||
|
3343088a71 | ||
|
ab089f4fb5 | ||
|
027a3e66f7 | ||
|
4bbc10614f | ||
|
7f9adafc10 | ||
|
9f2670277c | ||
|
7d767c5a3d | ||
|
ef8c45749c | ||
|
cc75b3e1dc | ||
|
90a9c97e38 | ||
|
3dabf7b8d0 | ||
|
3232d17186 | ||
|
c132acae36 | ||
|
d3aa4f2aed | ||
|
dfb3eb7716 | ||
|
4ab54f1aef | ||
|
ff2ca10cba | ||
|
21d09632a5 | ||
|
92249894b3 | ||
|
0adfa0ec07 | ||
|
6a314d26cb | ||
|
148bd9ee92 | ||
|
faa43a755e | ||
|
5176455f1a | ||
|
5ea39eaa96 | ||
|
af02b83b88 | ||
|
d033e6327d | ||
|
0f88200247 | ||
|
53401bef63 | ||
|
0b228fca04 | ||
|
becda5638a | ||
|
d54a69ac7f | ||
|
10c4cd9677 | ||
|
87512e9751 | ||
|
c00c20a799 | ||
|
26194bd684 | ||
|
6fbcd8914a | ||
|
a52476c9be | ||
|
0edf0c8cd9 | ||
|
08c4c9a30b | ||
|
be7c1aef42 | ||
|
498d8145c0 | ||
|
ec331acf48 | ||
|
5ce881be82 | ||
|
f9eb9b4cab | ||
|
4e23b49969 | ||
|
b000a94275 | ||
|
6c9cda6f92 | ||
|
eeb2c61653 | ||
|
843b10c8b0 | ||
|
9eace84342 | ||
|
cb2b6e0494 | ||
|
09ee846d92 | ||
|
759b204be3 | ||
|
cc95b4594a | ||
|
d6eea6caee | ||
|
368f70604f | ||
|
6dda6931d1 | ||
|
15a7583787 | ||
|
c41a914d6e | ||
|
24493e9169 | ||
|
4821251ebb | ||
|
ca2dacfcee | ||
|
ea0917bcba | ||
|
9c79022153 | ||
|
3f477ccb03 | ||
|
eb1e43a9af | ||
|
5235c3f78d | ||
|
532471967e | ||
|
452e90ba72 | ||
|
1127887a8b | ||
|
8388f5a7e1 | ||
|
56d8b1e7f6 | ||
|
32a254050d | ||
|
5ab3447de1 | ||
|
4fa0e472cf | ||
|
524d253853 | ||
|
a297a4f044 | ||
|
b7d7599ce3 | ||
|
dfe63ed84d | ||
|
70a4320bdd | ||
|
9f3e098320 | ||
|
ef113c6f72 | ||
|
e2b530aa72 | ||
|
f6a6a77640 | ||
|
8c42205e35 | ||
|
cc02da816f | ||
|
3ffb0c4f25 | ||
|
de41d24a3d | ||
|
543875e080 | ||
|
96e4d0960c | ||
|
8c703ecf73 | ||
|
2de1e2062e | ||
|
48addc88be | ||
|
3b62417c35 | ||
|
00284f0ed6 | ||
|
cec40a7467 | ||
|
18f70a6229 | ||
|
048c2f0e8c | ||
|
15b0a92294 | ||
|
d843c27478 | ||
|
39edf4abca | ||
|
cf7ff99513 | ||
|
2eaf65ec60 | ||
|
8235c4747d | ||
|
8263690e75 | ||
|
efd7c87b5b | ||
|
3782454e8d | ||
|
f634adc7dc | ||
|
c0999a149c | ||
|
c29d73a06a | ||
|
0da06b7103 | ||
|
1b9db6d4a7 | ||
|
547be53b8c | ||
|
1aec7112f7 | ||
|
bfa15a642f | ||
|
b2a4feeb4c | ||
|
422a933429 | ||
|
deb84d7989 | ||
|
e840cb9cd5 | ||
|
74a38adb6b | ||
|
1322e205e2 | ||
|
bb001af0e8 | ||
|
2872ab927e | ||
|
85840d4c03 | ||
|
05e3933c06 | ||
|
2ce25ebbef | ||
|
fa1e0ba354 | ||
|
eac9250fd5 | ||
|
8816b6cdd9 | ||
|
84ac62d396 | ||
|
0206c070ac | ||
|
3265c9169d | ||
|
78976974e7 | ||
|
263fa2c4a6 | ||
|
59d3a3611f | ||
|
84c58aabd0 | ||
|
550a6488c9 | ||
|
1187627a1d | ||
|
c376555cec | ||
|
b40c0f028f | ||
|
30667d5041 | ||
|
26bfe59f45 | ||
|
4212c0e7e5 | ||
|
f74d19765e | ||
|
236828d06f | ||
|
026bfedb33 | ||
|
9dac814ee8 | ||
|
bb57d9171f | ||
|
6c0f85d5de | ||
|
1a2ad348f6 | ||
|
8a68316eb9 | ||
|
63f49457dc | ||
|
64bb1346c7 | ||
|
a8ab54d18d | ||
|
63e7620462 | ||
|
2e0777317f | ||
|
a84b8b6ebb | ||
|
5c864e2cfa | ||
|
87c82334a7 | ||
|
bdf2e55d98 | ||
|
9106a750cd | ||
|
8a2cbb88d1 | ||
|
d35fb9d732 | ||
|
bd91338246 | ||
|
aa6c5f4d92 | ||
|
1757a6fce5 | ||
|
6479e403ef | ||
|
23e3b1e665 | ||
|
96d757c13f | ||
|
20c6ea70cc | ||
|
9eef9c648c | ||
|
dbbe4a783b | ||
|
7ff34ca2cb | ||
|
0b1e1e1a00 | ||
|
e0835db4f1 | ||
|
df092aa1de | ||
|
6ff8119765 | ||
|
4a50c8bd03 | ||
|
23ee6b1cd6 | ||
|
a22c3e5968 | ||
|
fe503c7c06 | ||
|
7078aa63ae | ||
|
2ab680c697 | ||
|
3a22a6e858 | ||
|
3c3605818f | ||
|
7e5f769d91 | ||
|
8d65add626 | ||
|
5d511948cd | ||
|
2f02c25e36 | ||
|
d638c1794a | ||
|
875cc073b0 | ||
|
9aa77fcceb | ||
|
e1ac6f1e30 | ||
|
a68442e056 | ||
|
b9deced219 | ||
|
f249d0b84c | ||
|
0d12aa4836 | ||
|
2915e711f7 | ||
|
99911873a1 | ||
|
7c36eb3e8b | ||
|
412614c700 | ||
|
93af78d2d2 | ||
|
ad702bae0c | ||
|
d1039926f5 | ||
|
32793ab685 | ||
|
d348a916f5 | ||
|
d4bf74816f | ||
|
ea4f55e3dc | ||
|
0b39b1cbb7 | ||
|
132529ce89 | ||
|
dd4d409551 | ||
|
de12cd18fb | ||
|
b256f24145 | ||
|
041608129a | ||
|
5289304519 | ||
|
87bd7cd7b0 | ||
|
75206f266f | ||
|
4f082dfa89 | ||
|
0a793ebc60 | ||
|
8bdb05edb2 | ||
|
c1e97169cd | ||
|
c0e958e022 | ||
|
713658798d | ||
|
9b46748d5b | ||
|
4c553c5a5b | ||
|
967b88d938 | ||
|
8436040735 | ||
|
ca2ee91a80 | ||
|
7f0ac73724 | ||
|
224b77d4f7 | ||
|
8e8b1fe48c | ||
|
c577493908 | ||
|
a8740d6c09 | ||
|
fc8df41ec6 | ||
|
7afa143886 | ||
|
f62a369fb4 | ||
|
25566c6810 | ||
|
aca8263926 | ||
|
02dcbf343d | ||
|
a946317fab | ||
|
ae294cc2d0 | ||
|
900fda4411 | ||
|
3a8ca7abbc | ||
|
bf8d7bba9e | ||
|
4a3f5b3617 | ||
|
1e958e52d3 | ||
|
cd16538fc9 | ||
|
6e8fb66859 | ||
|
52fdd1cb76 | ||
|
a9b97cbcb7 | ||
|
16605f2fda | ||
|
9c94583a3d | ||
|
267da8138d | ||
|
e1c275d87b | ||
|
f9b97f1c62 | ||
|
a8d0f2516c | ||
|
e85e37d91d | ||
|
7411b694c3 | ||
|
c65a9a05f9 | ||
|
e84c81b76f | ||
|
ee95f281f0 | ||
|
1c730ee761 | ||
|
b8a3608aa5 | ||
|
5a50a98980 | ||
|
9548888599 | ||
|
3e60932a28 | ||
|
d7e8f00e7e | ||
|
a1ee5eb2aa | ||
|
4d9049dc1a | ||
|
470740f97b | ||
|
e16b0aef31 | ||
|
4659b2ae45 | ||
|
c2d29dd197 | ||
|
82b742533b | ||
|
78131eee64 | ||
|
bda5863425 | ||
|
cea2e25f41 | ||
|
1cab2b4a7c | ||
|
337165959c | ||
|
cfa6ff9569 | ||
|
cb311b441a | ||
|
3a2a3c7325 | ||
|
1e0fccd1af | ||
|
532116e7e3 | ||
|
6b5ad2066a | ||
|
0f40405fc9 | ||
|
9e92f357be | ||
|
67d8665af5 | ||
|
682d3f7de0 | ||
|
01fd00f5ed | ||
|
d506263da7 | ||
|
baeacdcfd3 | ||
|
9a5ef043c1 | ||
|
265419a369 | ||
|
0e4920632a | ||
|
f26bf60fb5 | ||
|
3fda08e405 | ||
|
0642fb4d45 | ||
|
d73c4ac869 | ||
|
84661bf6da | ||
|
14375237f6 | ||
|
e2ae08694e | ||
|
66934aceff | ||
|
fc1b933304 | ||
|
863ecfc785 | ||
|
6712e77271 | ||
|
c68ba7d093 | ||
|
d0b4597842 | ||
|
f2d8e6801e | ||
|
69b2f63d9a | ||
|
e19d08055a | ||
|
0ac9cb2c1f | ||
|
df50598f1c | ||
|
83715aa829 | ||
|
41b83e52f7 | ||
|
01dd78f9e9 | ||
|
addb1bcd86 | ||
|
961671c0f5 | ||
|
0db7a1d69c | ||
|
d4cebc6bbe | ||
|
d50b0bc437 | ||
|
89b0af3978 | ||
|
a043f2d794 | ||
|
64c5ad58d2 | ||
|
765f400f6b | ||
|
7ffc0a6534 | ||
|
78ca6ea8f0 | ||
|
86b9e8e39a | ||
|
1279a83103 | ||
|
d33cf3f4c3 | ||
|
5bd734317c | ||
|
318acb0f6c | ||
|
0ed3129f6b | ||
|
8bd718b3ba | ||
|
092c493027 | ||
|
7b9b0c0a00 | ||
|
a81e18da25 | ||
|
8e86ffce82 | ||
|
93c1defdb0 | ||
|
daf113ac66 | ||
|
d8e816c150 | ||
|
586c1800c4 | ||
|
45f28d8581 | ||
|
da16b33ab9 | ||
|
c2fc4c10ac | ||
|
f851f0d7e3 | ||
|
1771f70d74 | ||
|
1ef23f05ee | ||
|
caa9d03d65 | ||
|
9c9050ff12 | ||
|
13c0be19d3 | ||
|
18b4f2082c | ||
|
ee7e2ffd26 | ||
|
c3becfe193 | ||
|
0ec6b5ecd3 | ||
|
478f9babed | ||
|
cff9e937fd | ||
|
31d6939cde | ||
|
906092534b | ||
|
feae132e0f | ||
|
b24b781117 | ||
|
eaf63d314d | ||
|
70fab17837 | ||
|
23b079043b | ||
|
29958745c8 | ||
|
823ad12191 | ||
|
4727d1db9d | ||
|
f3a8cf050e | ||
|
c408d807a3 | ||
|
a63d20aa87 | ||
|
157f6c2aad | ||
|
6807320a0f | ||
|
4d3d34f599 | ||
|
966602602a | ||
|
4841804fff | ||
|
a177e4dd04 | ||
|
3b522a1e5c | ||
|
89ac4dd3c4 | ||
|
bcb4af81fc | ||
|
364d5823ea | ||
|
159d619caf | ||
|
7a8ae228f9 | ||
|
8a871e890a | ||
|
e8bc64e308 | ||
|
e95705f00c | ||
|
74bfd2f97c | ||
|
d1ba927b36 | ||
|
7c601e6b7b | ||
|
5a14df3950 | ||
|
f2f5a7d945 | ||
|
0575c7db72 | ||
|
d0f47327f8 | ||
|
2d6d4b8053 | ||
|
4406281260 | ||
|
1561ee799c | ||
|
d5144ea9bf | ||
|
5ce7adfcf9 | ||
|
185a0a51f8 | ||
|
be17805c0b | ||
|
a82f692e58 | ||
|
28b3b55122 | ||
|
85ad5855a0 | ||
|
345e50d59f | ||
|
75d98b6013 | ||
|
d6cf996151 | ||
|
ace3072e09 | ||
|
e5ff7929c4 | ||
|
def6efa1ef | ||
|
8adaf730c0 | ||
|
c591810d46 | ||
|
63472779ad | ||
|
b940579115 | ||
|
6f46465af1 | ||
|
c2febfa332 | ||
|
68d0048b3d | ||
|
3831b61966 | ||
|
4db4ac7243 | ||
|
4d36796131 | ||
|
2e507a7457 | ||
|
72163bd5f3 | ||
|
09c1e370b3 | ||
|
94f9be80c3 | ||
|
8f8671bcde | ||
|
0ff86d054e | ||
|
9bd8cb7c3c | ||
|
d493d0f180 | ||
|
e62cd03307 | ||
|
cce6ba4daa | ||
|
4842eeaad3 | ||
|
a63e78c31a | ||
|
e87a95d97d | ||
|
3013fc57bd | ||
|
8396094156 | ||
|
abd4367f48 | ||
|
c36a298c21 | ||
|
d807ea087f | ||
|
3e7923507b | ||
|
772beb7308 | ||
|
cb21c5ffa9 | ||
|
71c51aa4ab | ||
|
1e11918c8c | ||
|
ac48e72bf6 | ||
|
cb5df823ac | ||
|
b5257bea85 | ||
|
66acbc8d7f | ||
|
fa5c09a2e7 | ||
|
d4eada9e0f | ||
|
c99050cce2 | ||
|
cf3e3845c2 | ||
|
6b0f5f68a8 | ||
|
67a2eb9177 | ||
|
a32a7b58ce | ||
|
7fc55925be | ||
|
ed1d853e51 | ||
|
dea9886454 | ||
|
3e52d112d7 | ||
|
517d05dff1 | ||
|
eb95b5ec1a | ||
|
49c7ef3b21 | ||
|
ccee67ca3b | ||
|
830ba75e6d | ||
|
46434a3cad | ||
|
4ff15a75c5 | ||
|
cd80c9b070 | ||
|
a6f79ca57f | ||
|
574b232427 | ||
|
3b3b0910ff | ||
|
dbf1ed263c | ||
|
672fb78e12 | ||
|
268dc7c8b3 | ||
|
738a57b69b | ||
|
b47eaefe12 | ||
|
f00221fadb | ||
|
38f4721092 | ||
|
5ee69d11f2 | ||
|
8b58f565e4 | ||
|
6b5cd7c05f | ||
|
3e405fb188 | ||
|
cc881bd155 | ||
|
b32d557a6e | ||
|
ee528fbd5d | ||
|
92cc1e7457 | ||
|
c521b3ac32 | ||
|
d59c1a2958 | ||
|
21f4f0f4b0 | ||
|
d3fa9e84e9 | ||
|
212eda07c4 | ||
|
49fc021337 | ||
|
f047271cb9 | ||
|
025525266f | ||
|
28a7d3943e | ||
|
534215a18f | ||
|
7c454d9186 | ||
|
abae1cc58b | ||
|
153f02da3b | ||
|
1e8721e2ae | ||
|
9ba4b4a63d | ||
|
4ae3ee1200 | ||
|
289c1a7968 | ||
|
2d7fb19c3c | ||
|
2549300b54 | ||
|
f097f7659c | ||
|
d3f4f92b0e | ||
|
d9573a40ec | ||
|
7e8d6116df | ||
|
18352188ed | ||
|
7c0bab3a39 | ||
|
2a95e63343 | ||
|
5a8b1fb047 | ||
|
cd1d99611e | ||
|
7b2c5f3d28 | ||
|
18ea2ea759 | ||
|
f2dd602fef | ||
|
9f4908fe78 | ||
|
943478b00f | ||
|
98bb80a243 | ||
|
9befc7cc4f | ||
|
96eace1ea7 | ||
|
5c4dfe0c30 | ||
|
08b6a617e8 | ||
|
ec7d6a506e | ||
|
e2d2b3ef21 | ||
|
3ac5d1ce4c | ||
|
e7ed9ecba7 | ||
|
080d9e4ce2 | ||
|
5699a2036c | ||
|
15a4421f9c | ||
|
9b776458ef | ||
|
da390bb11c | ||
|
69f7399247 | ||
|
b3fae3a817 | ||
|
1f182675c8 | ||
|
5a41eed26d | ||
|
637ed49868 | ||
|
afd9845e26 | ||
|
b4a33e21ea | ||
|
a1f5e514ef | ||
|
e46128fb50 | ||
|
5220cb63e3 | ||
|
145ebfa1df | ||
|
b3c6273efa | ||
|
300bd0eb85 | ||
|
4324025f98 | ||
|
801fd81efe | ||
|
33f7fbc42d | ||
|
77810030d2 | ||
|
4fec43067e | ||
|
a1dc526760 | ||
|
b7761af34d | ||
|
4b2aef8857 | ||
|
c72b660b74 | ||
|
6aaaa63519 | ||
|
0705a1c565 | ||
|
734e9fb8a9 | ||
|
bb7aa06a48 | ||
|
e521150b8f | ||
|
5a9169e152 | ||
|
78e4dac993 | ||
|
7d5e61a66a | ||
|
271fa063a3 | ||
|
9b701e69cc | ||
|
d6e01ff900 | ||
|
dab6706aba | ||
|
81edd3b3a7 | ||
|
d19617f06b | ||
|
144c10fad1 | ||
|
a01e951d0f | ||
|
31874783c4 | ||
|
05d47bd53e | ||
|
b880e3ffae | ||
|
1c5b4c5d5b | ||
|
b845ea097c | ||
|
b81a73d1fb | ||
|
e40542ef3a | ||
|
c253ec3a9c | ||
|
f8d44b01df | ||
|
fd1f355b7b | ||
|
71652572e3 | ||
|
525a88d879 | ||
|
5d6dc93043 | ||
|
95639d9577 | ||
|
8e25f7d229 | ||
|
92a85089b8 | ||
|
b644a490f0 | ||
|
1d21306785 | ||
|
e919601aaf | ||
|
5ca4bd5d90 | ||
|
a1de692a69 | ||
|
751fb2366c | ||
|
69fddac052 | ||
|
93a3661c15 | ||
|
2af807a83f | ||
|
a2fd34f81f | ||
|
b29499996b | ||
|
6f535924eb | ||
|
4278abfe27 | ||
|
3484cb9a65 | ||
|
7ee07a3c39 | ||
|
97e48b6a18 | ||
|
54635f435a | ||
|
711d617dc1 | ||
|
ffb38dfb8b | ||
|
2faf519cf9 | ||
|
bff21441dd | ||
|
ed6100441e | ||
|
6fe11c9941 | ||
|
c49e4a6565 | ||
|
7074be22f1 | ||
|
5dbeb87ec9 | ||
|
2282030b2a | ||
|
d1b8fe93f0 | ||
|
ef57b70fa5 | ||
|
01111fc42c | ||
|
1e37e35c3e | ||
|
ead7b8f498 | ||
|
61e501da89 | ||
|
3c74416465 | ||
|
a5d2a34497 | ||
|
7a855725f2 | ||
|
33b6c292c3 | ||
|
27f6ba651e | ||
|
8c9986d310 | ||
|
54334b5667 | ||
|
665be7f6bd | ||
|
7126cadf80 | ||
|
5ffb62dd03 | ||
|
da3cf9eae3 | ||
|
039a65d0e4 | ||
|
1950a479c0 | ||
|
93f50ca317 | ||
|
b2b84359ab | ||
|
c609d03986 | ||
|
2be9218a3b | ||
|
62e64905b7 | ||
|
4e379bde60 | ||
|
9be12a7d95 | ||
|
30c734fc73 | ||
|
c259669fa3 | ||
|
82f42ea091 | ||
|
da65a3d898 | ||
|
d8022d26fc | ||
|
5509e17d0c | ||
|
f6e6c3b5a5 | ||
|
f8aad5d5b7 | ||
|
d311368bc5 | ||
|
d47c3d64b2 | ||
|
d14f8c3c45 | ||
|
f2010f9c65 | ||
|
33ad6e0188 | ||
|
ec5e5d23fa | ||
|
5b208e296f | ||
|
4e276a8920 | ||
|
017da76b72 | ||
|
2c33da5070 | ||
|
256cc8ee08 | ||
|
7d95c44572 | ||
|
eeba61ccd5 | ||
|
9e7d3a7810 | ||
|
5e8df049fb | ||
|
2119ae74c2 | ||
|
5546aad260 | ||
|
66e5dc157a | ||
|
ac3ad139f6 | ||
|
b7605d5c95 | ||
|
c42ecaab8d | ||
|
a7848dd880 | ||
|
77234bbbde | ||
|
b94e5e58db | ||
|
ad88b94bca | ||
|
d15b0b0a1b | ||
|
af62c0f9f1 | ||
|
cdbe1defa4 | ||
|
f7f70bed8f | ||
|
cd6ca9b1f6 | ||
|
e58f8c28d2 | ||
|
69ae578450 | ||
|
f6e8e141df | ||
|
65d2a88dd2 | ||
|
2706747f66 | ||
|
5df4073c81 | ||
|
0eb7f17d9a | ||
|
bd7958776b | ||
|
1b7ddb0ea0 | ||
|
4abe781c27 | ||
|
012a0d6bf8 | ||
|
ed1a908e53 | ||
|
c39a1cb17e | ||
|
0ed1e85091 | ||
|
7dea7ccb10 | ||
|
4b135d0958 | ||
|
bb721f0d6d | ||
|
3ec0bedc60 | ||
|
45ec4ce82a | ||
|
261816b0d4 | ||
|
5e3cd0e5b5 | ||
|
fa71b268a8 | ||
|
fd328869cc | ||
|
101c5a50aa | ||
|
9b0a0ba9e6 | ||
|
8860e991f6 | ||
|
c8cafc8ebb | ||
|
cc5b93f72d | ||
|
920a86e849 | ||
|
e03dc6a984 | ||
|
29239ba2bb | ||
|
390601f038 | ||
|
64385aee0c | ||
|
56cb3bedc2 | ||
|
de2a27e255 | ||
|
7eec398875 | ||
|
3e236955c9 | ||
|
17fe57d8dc | ||
|
3213273d82 | ||
|
c68e8cd374 | ||
|
3c09af4169 | ||
|
5fd7dacadc | ||
|
2e7fb11a6e | ||
|
9df52a98e2 | ||
|
9fcb9637b5 | ||
|
3d28f01453 | ||
|
c2564d34af | ||
|
7935b9d212 | ||
|
9c20a8b7ae | ||
|
963929df02 | ||
|
70104ef4fb | ||
|
f9bd11c337 | ||
|
74d76f6c38 | ||
|
f15dc68138 | ||
|
f5952c7343 | ||
|
22558357d4 | ||
|
b9864aa871 | ||
|
a2df7c0303 | ||
|
9faf72c8cc | ||
|
a998836d4b | ||
|
a46e01eeef | ||
|
cec4a73ccb | ||
|
60566c5c80 | ||
|
66dbdbd993 | ||
|
f51b1f5565 | ||
|
5bf35a9aee | ||
|
ccd2a3eda2 | ||
|
79e2293ab2 | ||
|
768d5e1058 | ||
|
75ac3d199d | ||
|
6e75d0d27f | ||
|
292f7858e6 | ||
|
6273fcf072 | ||
|
0f5054f685 | ||
|
a290da25a1 | ||
|
bc00f05815 | ||
|
4adcb9df1b | ||
|
2feaa6931b | ||
|
84cac51a51 | ||
|
a1839f3c61 | ||
|
f9f2e280ea | ||
|
768d013267 | ||
|
678c97f21e | ||
|
d107ef78df | ||
|
dbac8793bd | ||
|
9b3d2464cd | ||
|
671ddd5b05 | ||
|
33d22f0e9e | ||
|
61e6725335 | ||
|
0ea2afe671 | ||
|
13a31a4001 | ||
|
a08a81c6b4 | ||
|
e37d2e3e70 | ||
|
0a21c21112 | ||
|
c6ed5a0f99 | ||
|
0f67366601 | ||
|
5d6ca22085 | ||
|
ecae2f43f3 | ||
|
12640c1499 | ||
|
321ff8c404 | ||
|
6887f409f0 | ||
|
ea0cb652e9 | ||
|
f0b822a831 | ||
|
f1f39bb9d8 | ||
|
5de0e848de | ||
|
775a5a8195 | ||
|
8f01879c56 | ||
|
044e123fd3 | ||
|
122deb6d5b | ||
|
18c53c4567 | ||
|
a0fe1944d1 | ||
|
90dc0f0843 | ||
|
9dbcb11cb5 | ||
|
925aa14912 | ||
|
d6f027ef34 | ||
|
379f995940 | ||
|
08b3a24da5 | ||
|
5af7b59660 | ||
|
d39d41fbda | ||
|
b66a9e2f33 | ||
|
659f80f262 | ||
|
3f2c7600fa | ||
|
776d6b2c05 | ||
|
af678af0d5 | ||
|
54ac0becee | ||
|
286e2011d2 | ||
|
8e433d6a52 | ||
|
fff7498d6a | ||
|
31e9e10144 | ||
|
0c6dfe5236 | ||
|
92912f063a | ||
|
a8caff322f | ||
|
7152e5efbb | ||
|
f7a99acb4e | ||
|
1e3810f9f8 | ||
|
52bae25580 | ||
|
937e75d8f1 | ||
|
a7baa09862 | ||
|
43fc6bb0fb | ||
|
e90dd656cc | ||
|
2003a18407 | ||
|
7a7ac65682 | ||
|
f2ae2badff | ||
|
4bdf1881dc | ||
|
0c8c8151fc | ||
|
06edbb67ed | ||
|
bd22d7f41d | ||
|
9e7b3ebdf9 | ||
|
e86cfd41d9 | ||
|
ea0a8be2ff | ||
|
54bb032d21 | ||
|
665b8e5283 | ||
|
39a6b19d6d | ||
|
0a505706bc | ||
|
a459f4df16 | ||
|
62a4ad3657 | ||
|
9c92f69272 | ||
|
9036bbf2b7 | ||
|
79a4f74a65 | ||
|
fd926ed4ee | ||
|
e1c13a5a7b | ||
|
1a7daab126 | ||
|
43fd8fae52 | ||
|
062d18fdb1 | ||
|
ce95af7a5f | ||
|
e3f506f9b5 | ||
|
b25509e512 | ||
|
a815d62d59 | ||
|
9c9cc35c02 | ||
|
c2106b674c | ||
|
487c6961cb | ||
|
9a74622ca1 | ||
|
1bb3ecb2a5 | ||
|
2a013bb3a0 | ||
|
ade389b326 | ||
|
f4a60a9bc4 | ||
|
9f5782d969 | ||
|
966ca6143b | ||
|
d82987d12e | ||
|
74d9416763 | ||
|
2fad92144e | ||
|
3f35816136 | ||
|
0e965f6991 | ||
|
7eb9e79648 | ||
|
a4caa1c0a3 | ||
|
259052199b | ||
|
650b418942 | ||
|
0264ccf6f4 | ||
|
cb1bd816db | ||
|
513ad0a85e | ||
|
8109eb765f | ||
|
f9d729ab68 | ||
|
9a883adf95 | ||
|
a820ae1074 | ||
|
93e807292c | ||
|
6ffa8f5393 | ||
|
5b218c3d9b | ||
|
b9f5692186 | ||
|
de9b87f558 | ||
|
e691d16a63 | ||
|
74c838a870 | ||
|
9a70c8d6c3 | ||
|
04632fd77f | ||
|
70b90dde23 | ||
|
600998fcb1 | ||
|
67aa88336a | ||
|
0bf95f99e6 | ||
|
23c212e7f1 | ||
|
e92a4b855f | ||
|
d549b83fc2 | ||
|
0f7d5b1a88 | ||
|
29a6416276 | ||
|
7fd4143ead | ||
|
9656dce72e | ||
|
aedd3a6bab | ||
|
5e173e9f63 | ||
|
d7661fbe9d | ||
|
9b136840d9 | ||
|
52e21323b6 | ||
|
04ae8ddaa1 | ||
|
33b4f40acc | ||
|
90f78507f4 | ||
|
ad27615760 | ||
|
e422ca0f29 | ||
|
5126380bea | ||
|
12d752ef24 | ||
|
1e4891e48e | ||
|
f312a837e9 | ||
|
4035e0e79c | ||
|
5d0c36f1da | ||
|
75ff08022e | ||
|
d44e686e9b | ||
|
fce764f90e | ||
|
9ddbfbddf8 | ||
|
86b4e17001 | ||
|
9b9a7143c4 | ||
|
fe9f1a6ded | ||
|
3aed0a6ff7 | ||
|
338f85ca77 | ||
|
8eb8e546dc | ||
|
acb04cfdc5 | ||
|
8465dccb06 | ||
|
b5e76398de | ||
|
c7b99a932c | ||
|
dbf4c0cb25 | ||
|
641172c6e5 | ||
|
538264cf1a | ||
|
1321e12ac4 | ||
|
ffa398b8d8 | ||
|
a8ad8fd649 | ||
|
17661ff934 | ||
|
6683d42d5b | ||
|
06e0d1b692 | ||
|
ab4da3423d | ||
|
8d9eef1771 | ||
|
db027a41d4 | ||
|
78a2cc289f | ||
|
d217ba5111 | ||
|
ca34698ca6 | ||
|
ae80a2de95 | ||
|
e348ef01b4 | ||
|
398f922531 | ||
|
9fe1d3ca8a | ||
|
d0e23d42de | ||
|
86f567e13c | ||
|
38e835dede | ||
|
9fdf9d29b6 | ||
|
315f23a047 | ||
|
77edab6409 | ||
|
30d09eb96e | ||
|
7069fc9e72 | ||
|
c5ff44a703 | ||
|
90097f4fb9 | ||
|
deec752ef9 | ||
|
b867a87c2f | ||
|
ef3cac669c | ||
|
304ac2e861 | ||
|
d924d5a562 | ||
|
16a3254c4c | ||
|
2eadd36fa0 | ||
|
9aed29e605 | ||
|
a5a5a41e2e | ||
|
509aab5deb | ||
|
af454f9b7c | ||
|
8bcb5fb1e8 | ||
|
4e63974471 | ||
|
9c89560e6c | ||
|
6cf72d7ad7 | ||
|
a1beb8f3ee | ||
|
86c3eea0f3 | ||
|
2bbc308321 | ||
|
374917adcc | ||
|
6264aad16f | ||
|
85a3639d99 | ||
|
7d37bf79de | ||
|
e598853e68 | ||
|
4a591d4b94 | ||
|
8ce9a87755 | ||
|
51762a45b3 | ||
|
bc7f4e0e34 | ||
|
ab00639130 | ||
|
dfc7a6c6a0 | ||
|
523f020b5f | ||
|
7730553b7e | ||
|
0da562a7cb | ||
|
ec2194fa7a | ||
|
dd5ef279bc | ||
|
f92e6ab364 | ||
|
ac9dc669d8 | ||
|
cd3b700393 | ||
|
6f8bbaa10b | ||
|
d148d0af36 | ||
|
88a183c6c9 | ||
|
f8fefde318 | ||
|
d26cfa0519 | ||
|
78342404ff | ||
|
cfdea7b85f | ||
|
7aa809016e | ||
|
1123e70740 | ||
|
dcde7ae597 | ||
|
252c7e4d0b | ||
|
b2f008378a | ||
|
0479b44373 | ||
|
178a197afb | ||
|
742029eb78 | ||
|
a7a7372aa7 | ||
|
7c00551749 | ||
|
06c4b6ac9d | ||
|
029ec22d0a | ||
|
751482899c | ||
|
6285793f18 | ||
|
20e8d040b0 | ||
|
8945f73d94 | ||
|
70945cb645 | ||
|
9d5960cfa5 | ||
|
9eceab33f9 | ||
|
05476c4d04 | ||
|
1149aa977d | ||
|
5a3905fe90 | ||
|
66370eac1f | ||
|
7d9ab86b7a | ||
|
c865cae3eb | ||
|
984d734944 | ||
|
145368f547 | ||
|
4dd24f05f3 | ||
|
6c6ebd64c3 | ||
|
7c4a800725 | ||
|
859cbd75e1 | ||
|
1cb0f83d29 | ||
|
538fec7b1b | ||
|
2750b2484f | ||
|
864f52a5f4 | ||
|
60442b1698 | ||
|
d96ec7f6e0 | ||
|
eb5ea6bdd6 | ||
|
43eb8f610f | ||
|
d7c0628591 | ||
|
0c3d9dacaf | ||
|
4e7c974d22 | ||
|
9637c7c0ac | ||
|
dad92c30c7 | ||
|
c980f8002e | ||
|
227af309e5 | ||
|
2e84b4e82d | ||
|
6eda3f135f | ||
|
0c791f873a | ||
|
d40c26594c | ||
|
3216eb03dd | ||
|
d776540811 | ||
|
4e398e34bf | ||
|
9ae0f4b78c | ||
|
5c200e0a4d | ||
|
4a5eb284c9 | ||
|
12201fd854 | ||
|
10c2e1e012 | ||
|
cba9cbf1bd | ||
|
48e5f32db6 | ||
|
f48fa14214 | ||
|
300e4008f0 | ||
|
e9e6fbf924 | ||
|
ec35c7c2fc | ||
|
6601a14831 | ||
|
2d0b7e24a5 | ||
|
080ed4d8c2 | ||
|
10115b1d70 | ||
|
e7d2ac4401 | ||
|
283c7dfada | ||
|
0bb4e37db3 | ||
|
e75520c455 | ||
|
90eb5e7a8b | ||
|
0c95f85ec5 | ||
|
8137fe6d45 | ||
|
e237b28a4d | ||
|
5ebc92935c | ||
|
c72aca41e5 | ||
|
e4d179f2c2 | ||
|
f3e5917850 | ||
|
52e030e146 | ||
|
65194bd1eb | ||
|
204e0d5d59 | ||
|
d0e3368154 | ||
|
d940a2c4d4 | ||
|
736e143fa5 | ||
|
2b3d52aa42 | ||
|
77e43c8b72 | ||
|
547d3bf45d | ||
|
41f8bf57c4 | ||
|
56027b5cbd | ||
|
1fba34a7a1 | ||
|
0aeac9cb7f | ||
|
8931425d02 | ||
|
548c329cde | ||
|
64534ea2f4 | ||
|
7c9930f9c8 | ||
|
f8f2419d4c | ||
|
4d4979c67c | ||
|
1ec522538f | ||
|
33be3ba713 | ||
|
a15dab76f9 | ||
|
f8cc7396cf | ||
|
1cd198cf52 | ||
|
0e175f9f0f | ||
|
e7c2380260 | ||
|
7ccb36d330 | ||
|
28a10f84cb | ||
|
70c5780535 | ||
|
b655596d1d | ||
|
ec57bbf67f | ||
|
a5fc59587f | ||
|
4df2019ebf | ||
|
f83ce94d5e | ||
|
f515e22924 | ||
|
6a8d3f1c1f | ||
|
e550a37206 | ||
|
c404f4b968 | ||
|
92f8878cbf | ||
|
2a0130f94d | ||
|
507e182a60 | ||
|
d27e127aa9 | ||
|
bf139664aa | ||
|
b0a8c7fc85 | ||
|
e628cad0ca | ||
|
6d90e57332 | ||
|
1f64a487a0 | ||
|
bff9ce5130 | ||
|
8a112d8ba2 | ||
|
b21955e058 | ||
|
00192d5ab8 | ||
|
f8e8fcfabe | ||
|
fd6cbe9053 | ||
|
cff430f396 | ||
|
50b71c1b96 | ||
|
643228bc1c | ||
|
f4830d8cb8 | ||
|
4ee39ff2ff | ||
|
1103b32e83 | ||
|
ac57451348 | ||
|
508d936078 | ||
|
a0b176e3b2 | ||
|
e1afee2799 | ||
|
9135c1f0ca | ||
|
48b15ef10f | ||
|
354496ace8 | ||
|
cc31b75a8f | ||
|
c01a94663c | ||
|
c6964c305b | ||
|
6ac4f87a2d | ||
|
70e212f913 | ||
|
ef4a50be10 | ||
|
fad04c750c | ||
|
f623ab9875 | ||
|
924868543c | ||
|
9810d05562 | ||
|
9c99d753fd | ||
|
a2017200c7 | ||
|
572c644043 | ||
|
32622d0ea3 | ||
|
a5e9f3d26f | ||
|
d2c392d448 | ||
|
efd6d12b97 | ||
|
8df02847e8 | ||
|
cd3b02d198 | ||
|
8bd9b930c3 | ||
|
48bc232f08 | ||
|
9ff5257357 | ||
|
568d9c9fae | ||
|
ce13485374 | ||
|
8322ecde12 | ||
|
e454916149 | ||
|
5c2c4ea8b1 | ||
|
a9fc659b84 | ||
|
de41dcd13d | ||
|
e667622a35 | ||
|
a9c38203bd | ||
|
04ddefb357 | ||
|
2bf59bf4d3 | ||
|
9d969be5f2 | ||
|
4c2abee74e | ||
|
8c4da7e01d | ||
|
0bc3542ab6 | ||
|
155134f396 | ||
|
c6a2fe64be | ||
|
36da2857bc | ||
|
d214ae4fdc | ||
|
13d4dd138d | ||
|
b662290f40 | ||
|
79b4e12e60 | ||
|
a92cf57dd6 | ||
|
80a9cadc76 | ||
|
b31774eeb0 | ||
|
3e40f3e795 | ||
|
c93c02088a | ||
|
7057752924 | ||
|
cf3a704b6a | ||
|
6cadbf325b | ||
|
1555095795 | ||
|
e16469bc4d | ||
|
227af52fb5 | ||
|
a55a90faec | ||
|
cf98be7b67 | ||
|
dd4da6f640 | ||
|
8249ad9b30 | ||
|
e4404cef0b | ||
|
0343d066da | ||
|
8ecbaf9c70 | ||
|
094d2bdb79 | ||
|
d760229ab8 | ||
|
60c412b936 | ||
|
94e2f1c111 | ||
|
c06de722dd | ||
|
5400c0e7f9 | ||
|
bbcfd5a048 | ||
|
48cf5e84e6 | ||
|
0e224d5985 | ||
|
36415e4b1d | ||
|
c4b76d7b19 | ||
|
4be266a983 | ||
|
abced4a914 | ||
|
7617026443 | ||
|
26822d8fe1 | ||
|
fc06fb6244 | ||
|
3fe1d9e4a4 | ||
|
95127cbbb7 | ||
|
0ec031f740 | ||
|
47c447c42e | ||
|
b7f3df7905 | ||
|
72b2db8db7 | ||
|
95616c8202 | ||
|
064e7be5cd | ||
|
e14bd38087 | ||
|
ab188fb76d | ||
|
2795700c31 | ||
|
7a2c48dafc | ||
|
f1aceff59b | ||
|
396dfa9042 | ||
|
182a78957d | ||
|
bf42207332 | ||
|
ab758e4fb2 | ||
|
d494df63ac | ||
|
1f85226ecb | ||
|
d9b77cc281 | ||
|
3589546af4 | ||
|
92f8f7e3a3 | ||
|
cca970666a | ||
|
7d0a31deed | ||
|
334a0ed24d | ||
|
9b2b502be5 | ||
|
f93e6f338e | ||
|
553e405460 | ||
|
ebecb6f6a1 | ||
|
3e17e38059 | ||
|
ae8b300164 | ||
|
d360f129e3 | ||
|
00a09f3c36 | ||
|
ed7c4b0cd5 | ||
|
bf2abe2f51 | ||
|
fb829de690 | ||
|
cb3cf95859 | ||
|
c9df01d321 | ||
|
9ba2798c65 | ||
|
72aed1a00b | ||
|
16fc65acc5 | ||
|
89647357af | ||
|
c47d037ecb | ||
|
df27911880 | ||
|
af582c4811 | ||
|
fd087589f8 | ||
|
0f808c066f | ||
|
20ab192bec | ||
|
0888a737b0 | ||
|
9f1500f50a | ||
|
2f9955b5d5 | ||
|
8796a8a56e | ||
|
7d837aa014 | ||
|
e2bf812f3d | ||
|
f761503760 | ||
|
117e3c4bbf | ||
|
c0adf7e9fc | ||
|
46c1a583a5 | ||
|
39c028e9e9 | ||
|
09686693d3 | ||
|
732a0a257d | ||
|
5c78e0e386 | ||
|
bc09257117 | ||
|
b573755df4 | ||
|
544f2e1b36 | ||
|
3ce1714279 | ||
|
2c5ca47ad4 | ||
|
4b3a8ff8c6 | ||
|
2c67a564b3 | ||
|
8cf8f820fe | ||
|
d7f469c15c | ||
|
3f58437405 | ||
|
53ffbff39f | ||
|
eb1451a3a0 | ||
|
a03ede6493 | ||
|
69a8259c5e | ||
|
c32c3f88f0 | ||
|
be4cd99a36 | ||
|
cf7f064531 | ||
|
2779d50a24 | ||
|
60fd666b79 | ||
|
a7f23f581f | ||
|
74add5df17 | ||
|
78e33c29bb | ||
|
14a8f396e1 |
@ -1 +0,0 @@
|
||||
bird.conf
|
7
.dir-locals.el
Normal file
7
.dir-locals.el
Normal file
@ -0,0 +1,7 @@
|
||||
; BIRD project coding conventions
|
||||
|
||||
((c-mode
|
||||
(c-file-style . "bsd")
|
||||
(c-basic-offset . 2)
|
||||
(fill-column . 80)
|
||||
(show-trailing-whitespace . t)))
|
57
.drone.yml
Normal file
57
.drone.yml
Normal file
@ -0,0 +1,57 @@
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: deploy
|
||||
|
||||
steps:
|
||||
|
||||
- name: build alpine
|
||||
image: c8n.io/simonburblecom/bird-build:alpine
|
||||
commands:
|
||||
- /build.sh
|
||||
|
||||
- name: build ubuntu
|
||||
image: c8n.io/simonburblecom/bird-build:ubuntu
|
||||
commands:
|
||||
- /build.sh
|
||||
|
||||
- name: upload
|
||||
image: plugins/s3
|
||||
settings:
|
||||
bucket: artifacts
|
||||
access_key:
|
||||
from_secret: MINIO_ACCESS_KEY
|
||||
secret_key:
|
||||
from_secret: MINIO_SECRET_KEY
|
||||
endpoint: https://minio.burble.dn42
|
||||
region: uk-lon3
|
||||
path_style: true
|
||||
source: artifacts/**/*
|
||||
strip_prefix: artifacts/
|
||||
target: /bird/${DRONE_BRANCH}
|
||||
|
||||
|
||||
image_pull_secrets:
|
||||
- CONFIG_JSON
|
||||
|
||||
---
|
||||
kind: secret
|
||||
name: CONFIG_JSON
|
||||
get:
|
||||
path: burble.dn42/kv/data/drone/docker
|
||||
name: configjson
|
||||
|
||||
---
|
||||
kind: secret
|
||||
name: MINIO_ACCESS_KEY
|
||||
get:
|
||||
path: burble.dn42/kv/data/drone/minio
|
||||
name: ACCESS_KEY
|
||||
|
||||
---
|
||||
kind: secret
|
||||
name: MINIO_SECRET_KEY
|
||||
get:
|
||||
path: burble.dn42/kv/data/drone/minio
|
||||
name: SECRET_KEY
|
||||
|
14
.gitignore
vendored
Normal file
14
.gitignore
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
/autom4te.cache/
|
||||
/obj/
|
||||
/Makefile
|
||||
/bird
|
||||
/birdc
|
||||
/birdcl
|
||||
/bird.conf
|
||||
/bird.log
|
||||
/config.log
|
||||
/config.status
|
||||
/configure
|
||||
/sysdep/autoconf.h.in
|
||||
/sysdep/autoconf.h.in~
|
||||
/cscope.*
|
415
.gitlab-ci.yml
Normal file
415
.gitlab-ci.yml
Normal file
@ -0,0 +1,415 @@
|
||||
variables:
|
||||
DEBIAN_FRONTEND: noninteractive
|
||||
LC_ALL: C
|
||||
GIT_STRATEGY: fetch
|
||||
DOCKER_CMD: docker --config="$HOME/.docker/$CI_JOB_ID/"
|
||||
IMG_BASE: registry.labs.nic.cz/labs/bird
|
||||
TOOLS_DIR: /var/lib/gitlab-runner/bird-tools
|
||||
|
||||
stages:
|
||||
- image
|
||||
- build
|
||||
- test
|
||||
|
||||
.docker: &docker_build
|
||||
stage: image
|
||||
allow_failure: true
|
||||
script:
|
||||
- $DOCKER_CMD login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.labs.nic.cz
|
||||
# Make sure we refresh the base image if it updates (eg. security updates, etc)
|
||||
# If we do just the build, cache is always reused and the freshness of the
|
||||
# base image is never checked. However, pull always asks and updates the
|
||||
# image only if it changed ‒ therefore, the cache is used unless there's a
|
||||
# change.
|
||||
- $DOCKER_CMD pull `sed -ne 's/^FROM //p' "misc/docker/$IMG_NAME/Dockerfile"`
|
||||
- $DOCKER_CMD build -t "bird:$IMG_NAME" "misc/docker/$IMG_NAME"
|
||||
- $DOCKER_CMD tag "bird:$IMG_NAME" "$IMG_BASE:$IMG_NAME"
|
||||
- $DOCKER_CMD push "$IMG_BASE:$IMG_NAME"
|
||||
after_script:
|
||||
- rm -f "$HOME/.docker/$CI_JOB_ID/" # cleanup the credentials
|
||||
tags:
|
||||
# That's Docker in Docker
|
||||
- dind
|
||||
|
||||
docker_debian-7-amd64:
|
||||
variables:
|
||||
IMG_NAME: "debian-7-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
docker_debian-7-i386:
|
||||
variables:
|
||||
IMG_NAME: "debian-7-i386"
|
||||
<<: *docker_build
|
||||
|
||||
docker_debian-8-amd64:
|
||||
variables:
|
||||
IMG_NAME: "debian-8-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
docker_debian-8-i386:
|
||||
variables:
|
||||
IMG_NAME: "debian-8-i386"
|
||||
<<: *docker_build
|
||||
|
||||
docker_debian-9-amd64:
|
||||
variables:
|
||||
IMG_NAME: "debian-9-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
docker_debian-9-i386:
|
||||
variables:
|
||||
IMG_NAME: "debian-9-i386"
|
||||
<<: *docker_build
|
||||
|
||||
docker_debian-10-amd64:
|
||||
variables:
|
||||
IMG_NAME: "debian-10-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
docker_debian-10-i386:
|
||||
variables:
|
||||
IMG_NAME: "debian-10-i386"
|
||||
<<: *docker_build
|
||||
|
||||
docker_debian-testing-amd64:
|
||||
variables:
|
||||
IMG_NAME: "debian-testing-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
docker_debian-testing-i386:
|
||||
variables:
|
||||
IMG_NAME: "debian-testing-i386"
|
||||
<<: *docker_build
|
||||
|
||||
docker_fedora-25-amd64:
|
||||
variables:
|
||||
IMG_NAME: "fedora-25-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
docker_fedora-26-amd64:
|
||||
variables:
|
||||
IMG_NAME: "fedora-26-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
docker_fedora-27-amd64:
|
||||
variables:
|
||||
IMG_NAME: "fedora-27-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
docker_fedora-28-amd64:
|
||||
variables:
|
||||
IMG_NAME: "fedora-28-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
docker_fedora-29-amd64:
|
||||
variables:
|
||||
IMG_NAME: "fedora-29-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
docker_fedora-30-amd64:
|
||||
variables:
|
||||
IMG_NAME: "fedora-30-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
docker_fedora-31-amd64:
|
||||
variables:
|
||||
IMG_NAME: "fedora-31-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
docker_centos-7-amd64:
|
||||
variables:
|
||||
IMG_NAME: "centos-7-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
docker_centos-8-amd64:
|
||||
variables:
|
||||
IMG_NAME: "centos-8-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
docker_ubuntu-14_04-amd64:
|
||||
variables:
|
||||
IMG_NAME: "ubuntu-14.04-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
docker_ubuntu-16_04-amd64:
|
||||
variables:
|
||||
IMG_NAME: "ubuntu-16.04-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
docker_ubuntu-18_04-amd64:
|
||||
variables:
|
||||
IMG_NAME: "ubuntu-18.04-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
docker_ubuntu-19_10-amd64:
|
||||
variables:
|
||||
IMG_NAME: "ubuntu-19.10-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
docker_opensuse-15.0-amd64:
|
||||
variables:
|
||||
IMG_NAME: "opensuse-15.0-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
docker_opensuse-15.1-amd64:
|
||||
variables:
|
||||
IMG_NAME: "opensuse-15.1-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
# TODO We want to copy these BSDs to our own virtual machines, to make sure
|
||||
# someone doesn't update them by accident.
|
||||
.freebsd-11-i386: &freebsd-11-i386_env
|
||||
tags:
|
||||
- freebsd
|
||||
- i386
|
||||
#only:
|
||||
#- master
|
||||
#- triggers
|
||||
#- tags
|
||||
|
||||
.freebsd-11-amd64: &freebsd-11-amd64_env
|
||||
tags:
|
||||
- freebsd
|
||||
- amd64
|
||||
|
||||
.build: &build-base
|
||||
stage: build
|
||||
script:
|
||||
- autoreconf
|
||||
- ./configure CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS"
|
||||
# Detect which make is available
|
||||
- MAKE=make
|
||||
- which gmake 2>/dev/null >/dev/null && MAKE=gmake
|
||||
- $MAKE
|
||||
# Run tests if they are available
|
||||
- $MAKE check
|
||||
|
||||
.build-linux: &build-linux
|
||||
<<: *build-base
|
||||
tags:
|
||||
- docker
|
||||
- linux
|
||||
- amd64
|
||||
|
||||
build-debian-7-amd64:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:debian-7-amd64
|
||||
|
||||
build-debian-7-i386:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:debian-7-i386
|
||||
|
||||
build-debian-8-amd64:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:debian-8-amd64
|
||||
|
||||
build-debian-8-i386:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:debian-8-i386
|
||||
|
||||
build-debian-9-amd64:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:debian-9-amd64
|
||||
|
||||
build-debian-9-i386:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:debian-9-i386
|
||||
|
||||
build-debian-10-amd64:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:debian-10-amd64
|
||||
|
||||
build-debian-10-i386:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:debian-10-i386
|
||||
|
||||
build-debian-testing-amd64:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:debian-testing-amd64
|
||||
|
||||
build-debian-testing-i386:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:debian-testing-i386
|
||||
|
||||
build-fedora-25-amd64:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:fedora-25-amd64
|
||||
|
||||
build-fedora-26-amd64:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:fedora-26-amd64
|
||||
|
||||
build-fedora-27-amd64:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:fedora-27-amd64
|
||||
|
||||
build-fedora-28-amd64:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:fedora-28-amd64
|
||||
|
||||
build-fedora-29-amd64:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:fedora-29-amd64
|
||||
|
||||
build-fedora-30-amd64:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:fedora-30-amd64
|
||||
|
||||
build-fedora-31-amd64:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:fedora-31-amd64
|
||||
|
||||
build-centos-7-amd64:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:centos-7-amd64
|
||||
|
||||
build-centos-8-amd64:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:centos-8-amd64
|
||||
|
||||
build-ubuntu-14_04-amd64:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:ubuntu-14.04-amd64
|
||||
|
||||
build-ubuntu-16_04-amd64:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:ubuntu-16.04-amd64
|
||||
|
||||
build-ubuntu-18_04-amd64:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:ubuntu-18.04-amd64
|
||||
|
||||
build-ubuntu-19_04-amd64:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:ubuntu-19.04-amd64
|
||||
|
||||
build-opensuse-15.0-amd64:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:opensuse-15.0-amd64
|
||||
|
||||
build-opensuse-15.1-amd64:
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:opensuse-15.1-amd64
|
||||
|
||||
build-freebsd-11-amd64:
|
||||
<<: *build-base
|
||||
tags:
|
||||
- freebsd
|
||||
- amd64
|
||||
|
||||
build-freebsd-11-i386:
|
||||
<<: *build-base
|
||||
tags:
|
||||
- freebsd
|
||||
- i386
|
||||
|
||||
build-birdlab:
|
||||
stage: build
|
||||
tags:
|
||||
- birdlab
|
||||
- amd64
|
||||
script:
|
||||
- DIR=$(pwd)
|
||||
- autoreconf
|
||||
- ./configure
|
||||
- make
|
||||
- cd $TOOLS_DIR
|
||||
- sudo git clean -fx
|
||||
- git pull --ff-only
|
||||
- mv $DIR/bird $DIR/birdc netlab/common
|
||||
|
||||
.test: &test-base
|
||||
stage: test
|
||||
needs: [build-birdlab]
|
||||
tags:
|
||||
- birdlab
|
||||
- amd64
|
||||
script:
|
||||
- cd $TOOLS_DIR/netlab
|
||||
- sudo ./stop
|
||||
- sudo ./runtest -m check $TEST_NAME
|
||||
|
||||
test-ospf-base:
|
||||
<<: *test-base
|
||||
variables:
|
||||
TEST_NAME: cf-ospf-base
|
||||
|
||||
test-ospf-default:
|
||||
<<: *test-base
|
||||
variables:
|
||||
TEST_NAME: cf-ospf-default
|
||||
|
||||
test-ospf-priority:
|
||||
<<: *test-base
|
||||
variables:
|
||||
TEST_NAME: cf-ospf-priority
|
||||
|
||||
test-ospf-nbma:
|
||||
<<: *test-base
|
||||
variables:
|
||||
TEST_NAME: cf-ospf-nbma
|
||||
|
||||
test-ospf-ptmp:
|
||||
<<: *test-base
|
||||
variables:
|
||||
TEST_NAME: cf-ospf-ptmp
|
||||
|
||||
test-ospf-authentication:
|
||||
<<: *test-base
|
||||
variables:
|
||||
TEST_NAME: cf-ospf-authentication
|
||||
|
||||
test-ospf-bfd:
|
||||
<<: *test-base
|
||||
variables:
|
||||
TEST_NAME: cf-ospf-bfd
|
||||
|
||||
test-ospf-custom:
|
||||
<<: *test-base
|
||||
variables:
|
||||
TEST_NAME: cf-ospf-custom
|
||||
|
||||
test-ospf-vrf:
|
||||
<<: *test-base
|
||||
variables:
|
||||
TEST_NAME: cf-ospf-vrf
|
||||
|
||||
test-bgp-base:
|
||||
<<: *test-base
|
||||
variables:
|
||||
TEST_NAME: cf-bgp-base
|
||||
|
||||
test-bgp-auth:
|
||||
<<: *test-base
|
||||
variables:
|
||||
TEST_NAME: cf-bgp-auth
|
||||
|
||||
test-bgp-int:
|
||||
<<: *test-base
|
||||
variables:
|
||||
TEST_NAME: cf-bgp-int
|
||||
|
||||
test-bgp-merged:
|
||||
<<: *test-base
|
||||
variables:
|
||||
TEST_NAME: cf-bgp-merged
|
||||
|
||||
test-ebgp-loop:
|
||||
<<: *test-base
|
||||
variables:
|
||||
TEST_NAME: cf-ebgp-loop
|
||||
|
||||
test-ebgp-star:
|
||||
<<: *test-base
|
||||
variables:
|
||||
TEST_NAME: cf-ebgp-star
|
||||
|
||||
test-ibgp-loop:
|
||||
<<: *test-base
|
||||
variables:
|
||||
TEST_NAME: cf-ibgp-loop
|
||||
|
||||
test-ibgp-star:
|
||||
<<: *test-base
|
||||
variables:
|
||||
TEST_NAME: cf-ibgp-flat
|
19
INSTALL
19
INSTALL
@ -7,7 +7,19 @@ $ make
|
||||
|
||||
Default location for configuration file is /usr/local/etc/bird.conf and
|
||||
for control socket is /usr/local/var/run/bird.ctl . You can change that
|
||||
by --sysconfdir and --localstatedir configure options.
|
||||
by --prefix, --sysconfdir and --runstatedir configure options, e.g.:
|
||||
|
||||
$ ./configure --prefix=/usr --sysconfdir=/etc --runstatedir=/run
|
||||
|
||||
To compile current development BIRD source code from Git repository, you
|
||||
also need Git (to download the source code) and Autoconf (to generate
|
||||
the configure script and associated files using 'autoreconf' tool):
|
||||
|
||||
$ git clone https://gitlab.labs.nic.cz/labs/bird/
|
||||
$ cd bird
|
||||
$ autoreconf
|
||||
|
||||
Then continue as in usual installation above.
|
||||
|
||||
|
||||
Requirements
|
||||
@ -15,14 +27,15 @@ Requirements
|
||||
|
||||
For compiling BIRD you need these programs and libraries:
|
||||
|
||||
- GNU C Compiler
|
||||
- GNU C Compiler (or LLVM Clang)
|
||||
- GNU Make
|
||||
- GNU Bison
|
||||
- GNU M4
|
||||
- Flex
|
||||
|
||||
- ncurses library
|
||||
- GNU Readline library (2.1 or newer)
|
||||
- GNU Readline library
|
||||
- libssh library (optional, for RPKI-Router protocol)
|
||||
|
||||
For compiling BIRD documentation you also need:
|
||||
|
||||
|
236
Makefile.in
Normal file
236
Makefile.in
Normal file
@ -0,0 +1,236 @@
|
||||
# Makefile for the BIRD Internet Routing Daemon
|
||||
# (c) 1999--2000 Martin Mares <mj@ucw.cz>
|
||||
# (c) 2016 Jan Moskyto Matejka <mq@ucw.cz>
|
||||
|
||||
# Disable build-in rules
|
||||
MAKEFLAGS += -r
|
||||
|
||||
# Variable definitions
|
||||
CPPFLAGS=-I$(objdir) -I$(srcdir) @CPPFLAGS@
|
||||
CFLAGS=$(CPPFLAGS) @CFLAGS@
|
||||
LDFLAGS=@LDFLAGS@
|
||||
M4FLAGS=@M4FLAGS@
|
||||
BISONFLAGS=@BISONFLAGS@
|
||||
LIBS=@LIBS@
|
||||
DAEMON_LIBS=@DAEMON_LIBS@
|
||||
CLIENT_LIBS=@CLIENT_LIBS@
|
||||
CC=@CC@
|
||||
M4=@M4@
|
||||
BISON=@BISON@
|
||||
FLEX=@FLEX@
|
||||
RANLIB=@RANLIB@
|
||||
INSTALL=@INSTALL@
|
||||
INSTALL_PROGRAM=@INSTALL_PROGRAM@
|
||||
INSTALL_DATA=@INSTALL_DATA@
|
||||
|
||||
client=$(addprefix $(exedir)/,@CLIENT@)
|
||||
daemon=$(exedir)/bird
|
||||
protocols=@protocols@
|
||||
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
bindir=@bindir@
|
||||
sbindir=@sbindir@
|
||||
sysconfdir=@sysconfdir@
|
||||
localstatedir=@localstatedir@
|
||||
runstatedir=@runstatedir@
|
||||
docdir=@prefix@/doc
|
||||
|
||||
srcdir := @srcdir@
|
||||
objdir := @objdir@
|
||||
exedir := @exedir@
|
||||
|
||||
git-label:=$(strip $(shell cd $(srcdir) && [ "$$(git rev-parse --show-toplevel)" = "$$(readlink -f .)" ] && git describe --always --dirty=-x 2>/dev/null))
|
||||
ifneq ($(git-label),)
|
||||
CFLAGS += -DGIT_LABEL="$(git-label)"
|
||||
endif
|
||||
|
||||
ifeq ($(objdir),.)
|
||||
objdir := $(realpath .)
|
||||
endif
|
||||
|
||||
ifeq ($(VERBOSE),)
|
||||
E:=@
|
||||
Q:=@
|
||||
else
|
||||
E:=@\#
|
||||
Q:=
|
||||
endif
|
||||
|
||||
ifneq ($(COLOR),)
|
||||
CFLAGS += -fdiagnostics-color=always
|
||||
endif
|
||||
|
||||
# Meta rules
|
||||
docgoals := docs userdocs progdocs
|
||||
testgoals := check test tests tests_run
|
||||
cleangoals := clean distclean testsclean
|
||||
.PHONY: all daemon cli $(docgoals) $(testgoals) $(cleangoals) tags cscope prepare
|
||||
|
||||
all: daemon cli
|
||||
|
||||
daemon: $(daemon)
|
||||
cli: $(client)
|
||||
|
||||
$(daemon): LIBS += $(DAEMON_LIBS)
|
||||
|
||||
# Include directories
|
||||
dirs := client conf doc filter lib nest test $(addprefix proto/,$(protocols)) @sysdep_dirs@
|
||||
|
||||
# conf/Makefile declarations needed for all other modules
|
||||
conf-lex-targets := $(addprefix $(objdir)/conf/,cf-lex.o)
|
||||
conf-y-targets := $(addprefix $(objdir)/conf/,cf-parse.y keywords.h commands.h)
|
||||
cf-local = $(conf-y-targets): $(s)config.Y
|
||||
|
||||
src-o-files = $(patsubst %.c,$(o)%.o,$(src))
|
||||
tests-target-files = $(patsubst %.c,$(o)%,$(tests_src))
|
||||
|
||||
all-daemon = $(daemon): $(obj)
|
||||
all-client = $(client): $(obj)
|
||||
|
||||
s = $(dir $(lastword $(MAKEFILE_LIST)))
|
||||
ifeq ($(srcdir),.)
|
||||
o = $(objdir)/$(s)
|
||||
else
|
||||
o = $(patsubst $(srcdir)%,$(objdir)%,$(s))
|
||||
endif
|
||||
|
||||
define clean_in =
|
||||
clean::
|
||||
rm -f $(addprefix $(o),$(1))
|
||||
endef
|
||||
|
||||
clean = $(eval $(call clean_in,$(1)))
|
||||
|
||||
# Include main Makefiles of the directories
|
||||
include $(addsuffix /Makefile,$(addprefix $(srcdir)/,$(dirs)))
|
||||
|
||||
# Generic rules
|
||||
# Object file rules
|
||||
$(objdir)/%.o: $(srcdir)/%.c | prepare
|
||||
$(E)echo CC -o $@ -c $<
|
||||
$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<
|
||||
|
||||
$(objdir)/%.o: $(objdir)/%.c | prepare
|
||||
$(E)echo CC -o $@ -c $<
|
||||
$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<
|
||||
|
||||
# Debug: Preprocessed source rules
|
||||
$(objdir)/%.E: $(srcdir)/%.c | prepare
|
||||
$(E)echo CC -o $@ -E $<
|
||||
$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -E $<
|
||||
|
||||
$(objdir)/%.E: $(objdir)/%.c | prepare
|
||||
$(E)echo CC -o $@ -E $<
|
||||
$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -E $<
|
||||
|
||||
# Debug: Assembler object rules
|
||||
$(objdir)/%.S: $(srcdir)/%.c | prepare
|
||||
$(E)echo CC -o $@ -S $<
|
||||
$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -S $<
|
||||
|
||||
$(objdir)/%.S: $(objdir)/%.c | prepare
|
||||
$(E)echo CC -o $@ -S $<
|
||||
$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -S $<
|
||||
|
||||
# Finally include the computed dependencies:
|
||||
DEPS = $(shell find $(objdir) -name '*.d')
|
||||
|
||||
# ## if there is at least one non-clean goal
|
||||
ifneq ($(filter-out $(cleangoals),$(MAKECMDGOALS)),)
|
||||
-include $(DEPS)
|
||||
endif
|
||||
|
||||
# ## if the implicit goal is called
|
||||
ifeq ($(MAKECMDGOALS),)
|
||||
-include $(DEPS)
|
||||
endif
|
||||
|
||||
# Rule for pre-generating all generated includables
|
||||
# before compiling any C file
|
||||
prepare: $(objdir)/sysdep/paths.h | $(objdir)/.dir-stamp
|
||||
|
||||
$(objdir)/.dir-stamp: Makefile
|
||||
$(E)echo MKDIR -p $(addprefix $(objdir)/,$(dirs) doc)
|
||||
$(Q)mkdir -p $(addprefix $(objdir)/,$(dirs) doc)
|
||||
$(Q)touch $@
|
||||
|
||||
$(client) $(daemon):
|
||||
$(E)echo LD $(LDFLAGS) -o $@ $^ $(LIBS)
|
||||
$(Q)$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
|
||||
|
||||
$(objdir)/sysdep/paths.h: Makefile
|
||||
echo >$@ "/* Generated by Makefile, don't edit manually! */"
|
||||
echo >>$@ "#define PATH_CONFIG_FILE \"@CONFIG_FILE@\""
|
||||
echo >>$@ "#define PATH_CONTROL_SOCKET \"@CONTROL_SOCKET@\""
|
||||
if test -n "@iproutedir@" ; then echo >>$@ "#define PATH_IPROUTE_DIR \"@iproutedir@\"" ; fi
|
||||
|
||||
# Unit tests rules
|
||||
|
||||
tests_targets_ok = $(addsuffix .ok,$(tests_targets))
|
||||
|
||||
$(tests_targets): %: %.o $(tests_objs) | prepare
|
||||
$(E)echo LD $(LDFLAGS) -o $@ $< "..." $(LIBS)
|
||||
$(Q)$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
|
||||
|
||||
# Hack to avoid problems with tests linking everything
|
||||
$(tests_targets): LIBS += $(DAEMON_LIBS)
|
||||
|
||||
$(tests_targets_ok): %.ok: %
|
||||
$(Q)$* 2>/dev/null && touch $*.ok
|
||||
|
||||
test: testsclean check
|
||||
check: tests tests_run
|
||||
tests: $(tests_targets)
|
||||
tests_run: $(tests_targets_ok)
|
||||
|
||||
STATIC_CHECKERS_ENABLE := nullability.NullableDereferenced nullability.NullablePassedToNonnull nullability.NullableReturnedFromNonnull optin.portability.UnixAPI valist.CopyToSelf valist.Uninitialized valist.Unterminated
|
||||
STATIC_CHECKERS_DISABLE := deadcode.DeadStores
|
||||
STATIC_SCAN_FLAGS := -o $(objdir)/static-scan/ $(addprefix -enable-checker ,$(STATIC_CHECKERS_ENABLE)) $(addprefix -disable-checker ,$(STATIC_CHECKERS_DISABLE))
|
||||
|
||||
static-scan:
|
||||
$(E)echo Running static code analysis
|
||||
$(Q)$(MAKE) clean
|
||||
$(Q)scan-build $(STATIC_SCAN_FLAGS) $(MAKE) -$(MAKEFLAGS)
|
||||
|
||||
tags:
|
||||
cd $(srcdir) ; etags -lc `find $(dirs) -name '*.[chY]'`
|
||||
|
||||
cscope:
|
||||
cd $(srcdir) ; find $(dirs) -name '*.[chY]' > cscope.files ; cscope -b
|
||||
|
||||
# Install
|
||||
|
||||
install: all
|
||||
$(INSTALL) -d $(DESTDIR)/$(sbindir) $(DESTDIR)/$(sysconfdir) $(DESTDIR)/$(runstatedir)
|
||||
for BIN in bird @CLIENT@ ; do \
|
||||
$(INSTALL_PROGRAM) $(exedir)/$$BIN $(DESTDIR)/$(sbindir)/$$BIN ; \
|
||||
done
|
||||
if ! test -f $(DESTDIR)/@CONFIG_FILE@ ; then \
|
||||
$(INSTALL_DATA) $(srcdir)/doc/bird.conf.example $(DESTDIR)/@CONFIG_FILE@ ; \
|
||||
else \
|
||||
echo "Not overwriting old bird.conf" ; \
|
||||
fi
|
||||
|
||||
install-docs:
|
||||
$(INSTALL) -d $(DESTDIR)/$(docdir)
|
||||
$(INSTALL_DATA) $(objdir)/doc/{bird,prog}{,-*}.html $(DESTDIR)/$(docdir)/
|
||||
|
||||
# Cleanup
|
||||
clean::
|
||||
rm -f $(objdir)/sysdep/paths.h
|
||||
rm -f $(addprefix $(exedir)/,bird birdc birdcl)
|
||||
find $(objdir) -name "*.[od]" -exec rm -f '{}' '+'
|
||||
|
||||
testsclean:
|
||||
rm -f $(tests_targets_ok)
|
||||
|
||||
ifeq ($(objdir),obj)
|
||||
distclean: clean
|
||||
rm -rf $(objdir)
|
||||
rm -f config.log config.status configure Makefile
|
||||
else
|
||||
distclean: clean
|
||||
rm -rf * .dir-stamp
|
||||
rm -f config.log config.status configure Makefile
|
||||
endif
|
364
NEWS
364
NEWS
@ -1,3 +1,367 @@
|
||||
Version 2.0.8 (2021-03-18)
|
||||
o Automatic channel reloads based on RPKI changes
|
||||
o Multiple static routes with the same network
|
||||
o Use bitmaps to keep track of exported routes
|
||||
o Per-channel debug flags
|
||||
o CLI commands show info from multiple protocols
|
||||
o Linux: IPv4 routes with IPv6 nexthops
|
||||
o Filter: Optimized redesign of prefix sets
|
||||
o Filter: Improved type checking of user filters
|
||||
o Filter: New src/dst accessors for Flowspec and SADR
|
||||
o Filter: New 'weight' route attribute
|
||||
o Filter: BGP path mask loop operator
|
||||
o Filter: Remove quitbird command
|
||||
o RIP: Demand circuit support (RFC 2091)
|
||||
o BGP: New 'allow as sets' and 'enforce first as' options
|
||||
o BGP: Support for BGP hostname capability
|
||||
o BGP: Support for MD5SIG with dynamic BGP
|
||||
o BFD: Optional separation of IPv4 / IPv6 BFD instances
|
||||
o BFD: Per-peer session options
|
||||
o RPKI: Allow build without libSSH
|
||||
o RPKI: New 'ignore max length' option
|
||||
o OSPF: Redesign of handling of unnumbered PtPs
|
||||
o OSPF: Allow key id 0 in authentication
|
||||
o Babel: Use onlink flag for routes with unreachable next hop
|
||||
o Many bugfixes
|
||||
|
||||
Notes:
|
||||
|
||||
Automatic channel reloads based on RPKI changes are enabled by default,
|
||||
but require import table enabled when used in BGP import filter.
|
||||
|
||||
BIRD now uses bitmaps to keep track of exported routes instead of
|
||||
re-evaluation of export filters. That should improve speed and accuracy in
|
||||
route export handling during reconfiguration, but takes some more memory.
|
||||
|
||||
Per-channel debug logging and some CLI commands (like 'show ospf neighbors')
|
||||
defaulting to all protocol instances lead to some minor changes in log and
|
||||
CLI output. Caution is recommended when logs or CLI output are monitored by
|
||||
scripts.
|
||||
|
||||
|
||||
Version 2.0.7 (2019-10-11)
|
||||
o BGP: Accumulated IGP metric (RFC 7311)
|
||||
o Important filter reconfiguration bugfix
|
||||
o Several other bugfixes
|
||||
|
||||
Version 2.0.6 (2019-09-10)
|
||||
o RAdv: Solicited unicast RAs
|
||||
o BGP: Optional Adj-RIB-Out
|
||||
o BGP: Extended optional parameters length
|
||||
o Filter: Sets and set expressions in path masks
|
||||
o Several important bugfixes
|
||||
|
||||
Version 2.0.5 (2019-08-01)
|
||||
o OSPF Graceful restart (RFC 3623, RFC 5187)
|
||||
o BGP: Dynamic BGP
|
||||
o BGP: Promiscuous ASN mode
|
||||
o BGP: Mandatory option for channels
|
||||
o BFD: Support for VRFs
|
||||
o Graceful restart command
|
||||
o Redesigned filtering code
|
||||
o Many bugfixes
|
||||
|
||||
Notes:
|
||||
|
||||
Previous version introduced an error in handling of OSPF NSSA-LSA, causing
|
||||
compatibility issues with proper implementations. The error is fixed in this
|
||||
version, therefore there are compatibility issues in OSPF NSSA areas between
|
||||
this and previous version.
|
||||
|
||||
|
||||
Version 2.0.4 (2019-02-27)
|
||||
o OSPF: Opaque LSAs (RFC 5250)
|
||||
o OSPF: DN-bit handling (RFC 4576)
|
||||
o Preferred route counters are back
|
||||
o Important BGP bugfix
|
||||
o Several bugfixes related to route propagation
|
||||
o some minor bugfixes
|
||||
|
||||
Version 2.0.3 (2019-01-05)
|
||||
o MRT table dumps (RFC 6396)
|
||||
o BGP Long-lived graceful restart
|
||||
o BGP: Optional import table (Adj-RIB-In)
|
||||
o BGP: Extend 'next hop keep' and 'next hop self' options
|
||||
o BGP: Improved VRF support
|
||||
o OSPF: Authentication trailer for OSPFv3 (RFC 7166)
|
||||
o Babel: New option to randomize router ID
|
||||
o Filter: Custom route attributes
|
||||
o Filter: Support for src accessor to SADR source prefix
|
||||
o Filter: Support for VPN_RD sets
|
||||
o Filter: Make ifname attribute modifiable
|
||||
o Perf: Protocol to measure BIRD performance internally
|
||||
o More verbose error messages in config processing
|
||||
o Log file size limit / log rotation
|
||||
o Many bugfixes
|
||||
|
||||
Notes:
|
||||
|
||||
Export of routes to RS EBGP (route server) sessions from other sources than
|
||||
RS EBGP sessions was changed that ASN is no longer prepended to BGP_PATH in
|
||||
that case. The change does not affect regular BGP configurations or regular
|
||||
route servers that have only RS EBGP peers.
|
||||
|
||||
For BGP route servers and route reflectors, the default value of option
|
||||
'next hop keep' was changed to a more appropriate value.
|
||||
|
||||
Attributes for OSPF and Babel metrics are no longer reset when exported to
|
||||
these protocols and could be set anywhere in BIRD. As a result, OSPF metric is
|
||||
kept when a route is reannounced between OSPF instances. Also, when route is
|
||||
exported to OSPF with both ospf_metric1 and ospf_metric2 attributes it is now
|
||||
propagated as OSPF-E2 route instead of as OSPF-E1 route.
|
||||
|
||||
Compiling BIRD with --enable-debug no longer automatically activates debug
|
||||
mode (-d option) nor local mode (-l option). Also, debug mode with output to
|
||||
file (-D option) no longer not forces foreground mode (-f option).
|
||||
|
||||
The configure script now uses standard option --runstatedir, the old option
|
||||
--with-runtimedir is deprecated.
|
||||
|
||||
|
||||
Version 2.0.2 (2018-03-22)
|
||||
o Source-specific routing support for Linux kernel and Babel
|
||||
o BGP: New option 'disable after cease'
|
||||
o Filter: Allow silent filter execution
|
||||
o Filter: Fixed stack overflow in BGP mask expressions.
|
||||
o Several bugfixes
|
||||
|
||||
Notes:
|
||||
|
||||
Syntax prefix:netmask for IPv4 prefixes was dropped. Just use prefix/pxlen.
|
||||
|
||||
|
||||
Version 2.0.1 (2018-01-16)
|
||||
o Linux MPLS kernel support
|
||||
o Better handling of channels inherited from templates
|
||||
o Default EBGP Route Propagation Behavior without Policies (RFC 8212)
|
||||
o Many bugfixes
|
||||
|
||||
Notes:
|
||||
|
||||
To satisfy requirements of RFC 8212, external BGP protocols now require
|
||||
explicit configuration of import and export policies.
|
||||
|
||||
|
||||
Version 2.0.0 (2017-12-11)
|
||||
o Integrated IPv4 + IPv6 design
|
||||
o Support for MPLS next hops
|
||||
o Support for VPNv4 and VPNv6 networks
|
||||
o Microsecond timers infrastructure
|
||||
o Basic VRF support
|
||||
o Babel: Support for dual-stack IPv4/IPv6
|
||||
o Babel: Many improvements and bugfixes
|
||||
o Major BGP protocol redesign
|
||||
o Full support for Multiprotocol BGP
|
||||
o BGP multicast support (SAFI 2)
|
||||
o BGP flowspec support (RFC 5575)
|
||||
o BGP with MPLS labels (RFC 3107)
|
||||
o BGP MPLS/VPN support (RFC 4364)
|
||||
o BGP 6PE - IPv6 NLRI over IPv4 MPLS (RFC 4798)
|
||||
o BGP IPv4 NLRI with an IPv6 Next Hop (RFC 5549)
|
||||
o BGP Confederations (RFC 5065)
|
||||
o BGP Shutdown communication (RFC 8203)
|
||||
o BGP: Allow exchanging LOCAL_PREF with eBGP peers
|
||||
o BGP: Allow to specify interface for regular sessions
|
||||
o OSPF: Support of address families in OSPFv3
|
||||
o OSPF: Enable ECMP and Link detection by default
|
||||
o RAdv: Support for more specific routes (RFC 4191)
|
||||
o RAdv: Proper handling of prefix retraction
|
||||
o RIP: Enable ECMP and Link detection by default
|
||||
o Redesign of RPKI handling
|
||||
o New RPKI-Router protocol
|
||||
o Static: Minor overhaul
|
||||
o Static: Support for all new route types
|
||||
o Kenrel: Default Linux kernel metric changed to 32
|
||||
o Kernel: Fix IPv6 ECMP handling with Linux 4.11+
|
||||
o Update of show route command
|
||||
o BIRD client persistent history
|
||||
o New build system
|
||||
o Unit tests
|
||||
o ...
|
||||
|
||||
Notes:
|
||||
|
||||
Tables are now defined with appropriate net type keyword. Protocols and tables
|
||||
are now connected by explicit channels, most related protocol options (table,
|
||||
import, export, ...) are now channel options. See doc/bird.conf.example2 for
|
||||
configuration examples. Some options were removed/replaced.
|
||||
|
||||
|
||||
Version 1.6.3 (2016-12-21)
|
||||
o Large BGP communities
|
||||
o BFD authentication (MD5, SHA1)
|
||||
o SHA1 and SHA2 authentication for RIP and OSPF
|
||||
o Improved documentation
|
||||
o Several bug fixes
|
||||
|
||||
Version 1.6.2 (2016-09-29)
|
||||
o Fixes serious bug introduced in the previous version
|
||||
|
||||
Version 1.6.1 (2016-09-22)
|
||||
o Support for IPv6 ECMP
|
||||
o Better handling of IPv6 tentative addresses
|
||||
o Several updates and fixes in Babel protocol
|
||||
o Filter: New !~ operator
|
||||
o Filter: ASN ranges in bgpmask
|
||||
o KRT: New kernel protocol option 'metric'
|
||||
o KRT: New route attribute 'krt_scope'
|
||||
o Improved BIRD help messages
|
||||
o Fixes memory leak in BGP multipath
|
||||
o Fixes handling of empty path segments in BGP AS_PATH
|
||||
o Several bug fixes
|
||||
|
||||
Version 1.6.0 (2016-04-29)
|
||||
o Major RIP protocol redesign
|
||||
o New Babel routing protocol
|
||||
o BGP multipath support
|
||||
o KRT: Add support for plenty of kernel route metrics
|
||||
o KRT: Allow more than 256 routing tables
|
||||
o Static: Allow to specify attributes for static routes
|
||||
o Static: Support for BFD controlled static routes
|
||||
o FreeBSD: Setup password for BGP MD5 authentication
|
||||
o IO: Remove socket number limit
|
||||
o Plenty of bug fixes
|
||||
|
||||
Upgrade notes:
|
||||
|
||||
For RIP, most protocol options were moved to interface blocks.
|
||||
|
||||
|
||||
Version 1.5.0 (2015-04-20)
|
||||
o Major OSPF protocol redesign.
|
||||
o OSPFv2 multi-instance extension (RFC 6549).
|
||||
o BGP AS-wide unique router ID (RFC 6286).
|
||||
o BGP enhanced route refresh (RFC 7313).
|
||||
o Link state support in BGP.
|
||||
o Latency tracking and internal watchdog.
|
||||
o Uses high port range for BFD on BSD.
|
||||
o Increase max symbol length to 64.
|
||||
o Allows to define unnamed protocols from templates.
|
||||
o Fixes two serious bugs in BGP.
|
||||
o Several bugfixes and minor improvements.
|
||||
o Several minor option changes:
|
||||
- OSPF: Protocol-wide 'instance id' option added.
|
||||
- BGP: Parameters to option 'neighbor' extended.
|
||||
- BGP: Separate option 'interface' added.
|
||||
- BGP: Option 'start delay time' renamed to 'connect delay time'.
|
||||
- BGP: Option 'route limit' deprecated.
|
||||
|
||||
Upgrade notes:
|
||||
|
||||
For OSPF, there are deep internal changes, but user-visible changes
|
||||
are limited to log messages and minor changes in formatting of command
|
||||
output.
|
||||
|
||||
For BGP, version 1.5.0 is essentially a minor release. There are two
|
||||
deprecated options ('start delay time' and 'route limit') and some
|
||||
minor formatting changes.
|
||||
|
||||
|
||||
Version 1.4.5 (2014-10-06)
|
||||
o New 'show route noexport' command option.
|
||||
o Port option for BGP sessions.
|
||||
o Better constant handling in set literals.
|
||||
o Better rate filtering of log messages.
|
||||
o Several minor bugfixes.
|
||||
|
||||
Version 1.4.4 (2014-07-09)
|
||||
o Extended OSPF multipath support.
|
||||
o Default router preference for RAdv.
|
||||
o Significant changes in socket layer.
|
||||
o Important bugfix in BGP.
|
||||
o Several minor bugfixes.
|
||||
|
||||
Version 1.4.3 (2014-04-14)
|
||||
o Important bugfix in IPv6 BGP.
|
||||
|
||||
Version 1.4.2 (2014-04-02)
|
||||
o Important bugfix in BFD.
|
||||
|
||||
Version 1.4.1 (2014-03-31)
|
||||
o BGP add-path support (RFC draft).
|
||||
o BGP graceful restart (RFC 4724).
|
||||
o OSPF: many changes in socket layer.
|
||||
o OSPF: support for secondary addresses in BSD.
|
||||
o OSPF: names for vlink pseudointerfaces (vlinkX).
|
||||
o Several bugfixes.
|
||||
|
||||
Version 1.4.0 (2013-11-25)
|
||||
o BFD protocol (RFC 5880).
|
||||
o BFD support for OSPF and BGP.
|
||||
o New 'allow local as' option for BGP.
|
||||
o Filters allows setting gw, ifname and ifindex.
|
||||
o Filter operator 'delete/filter' extended to bgp_paths.
|
||||
o Filter operator 'len' extended to [e]clists.
|
||||
o BIRD client now allows shorthands for noninteractive commands.
|
||||
o Flag -P for PID file support.
|
||||
o Flag -f added to force BIRD to run in foreground.
|
||||
o Protocol export/import/receive limits are checked during reconfiguration.
|
||||
o Several bugfixes and minor improvements.
|
||||
o Several minor but incompatible changes:
|
||||
- IBGP is multihop by default.
|
||||
- Changes primary address selection on BSD to the first one.
|
||||
- Integers in filters are handled as unsigned.
|
||||
- ISO 8601 time formats used by default.
|
||||
- Import of device routes from kernel protocol allowed.
|
||||
- Last state change now tracks just protocol state change.
|
||||
- Minor changes to default router ID calculation.
|
||||
|
||||
Version 1.3.11 (2013-07-27)
|
||||
o OSPF stub router option (RFC 3137).
|
||||
o TTL security for OSPF and RIP.
|
||||
o Protocol packet priority and traffic class handling.
|
||||
o Multiple routing tables support for FreeBSD and OpenBSD.
|
||||
o Extends constants to all filter data types.
|
||||
o Implements eval command.
|
||||
o 'bgppath ~ int set' filter operation.
|
||||
o Several bugfixes.
|
||||
|
||||
Version 1.3.10 (2013-04-30)
|
||||
o Lightweight BIRD client for embedded environments.
|
||||
o Dynamic IPv6 router advertisements.
|
||||
o New 'next hop keep' option for BGP.
|
||||
o Smart default routing table for 'show route export/preexport/protocol'.
|
||||
o Automatic router ID selection could be configured to use address of loopback.
|
||||
o Allows configured global addresses of NBMA neighbors in OSPFv3.
|
||||
o Allows BIRD commands from UNIX shell even in restricted mode.
|
||||
o Route limits inherited from templates can be disabled.
|
||||
o Symbol names enclosed by apostrophes can contain dots.
|
||||
o Several bugfixes.
|
||||
|
||||
Version 1.3.9 (2013-01-11)
|
||||
o BIRD can be configured to keep and show filtered routes.
|
||||
o Separate receive and import limits.
|
||||
o Several new reconfiguration cmd options (undo, timeout, check).
|
||||
o Configurable automatic router ID selection.
|
||||
o Dragonfly BSD support.
|
||||
o Fixed OSPFv3 vlinks.
|
||||
o Several minor bugfixes.
|
||||
|
||||
Version 1.3.8 (2012-08-07)
|
||||
o Generalized import and export route limits.
|
||||
o RDNSS and DNSSL support for RAdv.
|
||||
o Include in config file support wildcards.
|
||||
o History deduplication in BIRD client.
|
||||
o New route attributes krt_source, krt_metric.
|
||||
o Different instance ID support for OSPFv3.
|
||||
o Real broadcast mode for OSPFv2.
|
||||
o Several minor bugfixes.
|
||||
|
||||
Version 1.3.7 (2012-03-22)
|
||||
o Route Origin Authorization basics.
|
||||
o RIPng working again.
|
||||
o Extended clist operations in filters.
|
||||
o Fixes several bugs in BSD iface handling.
|
||||
o Several minor bugfixes and enhancements.
|
||||
|
||||
Version 1.3.6 (2012-01-20)
|
||||
o Important bugfix in BGP.
|
||||
|
||||
Version 1.3.5 (2012-01-10)
|
||||
o Protocol templates.
|
||||
o Deterministic MED option for BGP.
|
||||
o Support for link-local addresses in BGP and static protocols.
|
||||
o Several bugfixes.
|
||||
|
||||
Version 1.3.4 (2011-10-10)
|
||||
o Static recursive routes.
|
||||
|
149
README
149
README
@ -1,81 +1,104 @@
|
||||
BIRD Internet Routing Daemon
|
||||
BIRD Internet Routing Daemon
|
||||
|
||||
(c) 1998--2008 Martin Mares <mj@ucw.cz>
|
||||
Home page http://bird.network.cz/
|
||||
Mailing list bird-users@network.cz
|
||||
|
||||
(c) 1998--2008 Martin Mares <mj@ucw.cz>
|
||||
(c) 1998--2000 Pavel Machek <pavel@ucw.cz>
|
||||
(c) 1998--2008 Ondrej Filip <feela@network.cz>
|
||||
(c) 2009--2011 CZ.NIC z.s.p.o.
|
||||
(c) 2009--2019 CZ.NIC z.s.p.o.
|
||||
|
||||
================================================================================
|
||||
|
||||
The BIRD project is an attempt to create a routing daemon running on UNIX-like
|
||||
systems (but not necessarily limited to them) with full support of all modern
|
||||
routing protocols, easy to use configuration interface and powerful route
|
||||
filtering language.
|
||||
The BIRD project aims to develop a dynamic IP routing daemon with full support
|
||||
of all modern routing protocols, easy to use configuration interface and
|
||||
powerful route filtering language, primarily targeted on (but not limited to)
|
||||
Linux and other UNIX-like systems and distributed under the GNU General
|
||||
Public License.
|
||||
|
||||
What do we support
|
||||
==================
|
||||
|
||||
o Both IPv4 and IPv6
|
||||
o Multiple routing tables
|
||||
o Border Gateway Protocol (BGPv4)
|
||||
o Routing Information Protocol (RIPv2, RIPng)
|
||||
o Open Shortest Path First protocol (OSPFv2, OSPFv3)
|
||||
o Babel Routing Protocol (Babel)
|
||||
o Bidirectional Forwarding Detection (BFD)
|
||||
o IPv6 router advertisements
|
||||
o Static routes
|
||||
o Inter-table protocol
|
||||
o Command-line interface allowing on-line control and inspection of
|
||||
status of the daemon
|
||||
o Soft reconfiguration, no need to use complex online commands to
|
||||
change the configuration, just edit the configuration file and notify
|
||||
BIRD to re-read it and it will smoothly switch itself to the new
|
||||
configuration, not disturbing routing protocols unless they are
|
||||
affected by the configuration changes
|
||||
o Powerful language for route filtering, see doc/bird.conf.example
|
||||
o Linux, FreeBSD, NetBSD and OpenBSD ports
|
||||
|
||||
How to install BIRD
|
||||
===================
|
||||
|
||||
o From standard distribution package of your OS (recommended)
|
||||
o From official binary packages for Debian and Red Hat Linux
|
||||
ftp://bird.network.cz/pub/bird/debian/
|
||||
ftp://bird.network.cz/pub/bird/redhat/
|
||||
o From source code of the latest stable release version
|
||||
ftp://bird.network.cz/pub/bird/
|
||||
o From current development code in Git repository
|
||||
https://gitlab.labs.nic.cz/labs/bird/
|
||||
|
||||
See the file INSTALL for information about installation from source code.
|
||||
|
||||
Documentation
|
||||
=============
|
||||
|
||||
Online documentation is available at http://bird.network.cz/?get_doc or as HTML
|
||||
files in the doc directory, you can install it by `make install-docs' and
|
||||
rebuild it by `make docs', but you'll need SGMLtools and LaTeX to be installed
|
||||
on your machine. You can also download a neatly formatted PDF version as
|
||||
a separate archive (bird-doc-*.tar.gz) from ftp://bird.network.cz/pub/bird/
|
||||
|
||||
User support
|
||||
============
|
||||
|
||||
If you want to help us debugging, enhancing and porting BIRD or just lurk
|
||||
around to see what's going to develop from this strange creature, feel free
|
||||
to subscribe to the BIRD users mailing list (bird-users@bird.network.cz),
|
||||
send subscribes to majordomo at the same machine). Bug reports, suggestions,
|
||||
feature requests (: and code :) are welcome.
|
||||
around to see what's going to develop, feel free to subscribe to the BIRD
|
||||
users mailing list bird-users@network.cz, just send `subscribe' to
|
||||
bird-request@network.cz. Bug reports, suggestions, feature requests and
|
||||
code are welcome! We don't use gitlab issues for reporting, sorry.
|
||||
|
||||
You can download the latest version from ftp://bird.network.cz/pub/bird/
|
||||
and look at the BIRD home page at http://bird.network.cz/.
|
||||
Subscribe: http://bird.network.cz/mailman/listinfo/bird-users/
|
||||
Archive: http://bird.network.cz/pipermail/bird-users/
|
||||
|
||||
Licence
|
||||
=======
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
History
|
||||
=======
|
||||
|
||||
BIRD development started as a student project at the Faculty of Math
|
||||
and Physics, Charles University, Prague, Czech Republic under supervision
|
||||
of RNDr. Libor Forst <forst@cuni.cz>. BIRD has been developed and supported
|
||||
by CZ.NIC z.s.p.o. http://www.nic.cz/ since 2009.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
How to install BIRD:
|
||||
|
||||
./configure
|
||||
make
|
||||
make install
|
||||
vi /usr/local/etc/bird.conf
|
||||
|
||||
Online documentation is available as HTML files in the doc directory,
|
||||
you can install it by `make install-docs' and rebuild it by `make docs',
|
||||
but for the latter you need SGMLtools and LaTeX to be installed on your
|
||||
machine. You can also download a neatly formatted PostScript version
|
||||
as a separate archive (bird-doc-*.tar.gz).
|
||||
|
||||
What do we support:
|
||||
|
||||
o Both IPv4 and IPv6 (use --enable-ipv6 when configuring)
|
||||
o Multiple routing tables
|
||||
o BGP
|
||||
o RIP
|
||||
o OSPF
|
||||
o Static routes
|
||||
o Inter-table protocol
|
||||
o IPv6 router advertisements
|
||||
o Command-line interface (using the `birdc' client; to get
|
||||
some help, just press `?')
|
||||
o Soft reconfiguration -- no online commands for changing the
|
||||
configuration in very limited ways, just edit the configuration
|
||||
file and issue a `configure' command or send SIGHUP and BIRD
|
||||
will start using the new configuration, possibly restarting
|
||||
protocols affected by the configuration changes.
|
||||
o Powerful language for route filtering (see doc/bird.conf.example).
|
||||
|
||||
What is missing:
|
||||
|
||||
o See the TODO list
|
||||
|
||||
Good Luck and enjoy the BIRD :)
|
||||
The BIRD Team
|
||||
|
51
TODO
51
TODO
@ -1,51 +0,0 @@
|
||||
Core
|
||||
~~~~
|
||||
- socket open failure should not be fatal
|
||||
- &&,||: priorities
|
||||
- filters: function for BGP path length
|
||||
- static: allow specifying a per-route filter program for setting route attributes?
|
||||
|
||||
Globals
|
||||
~~~~~~~
|
||||
- right usage of DBG vs. debug
|
||||
- logging and tracing; use appropriate log levels
|
||||
- check incoming packets and log errors!!
|
||||
- check log calls for trailing newlines and log levels followed by comma
|
||||
- check if all protocols set proper packet priorities and TTL's.
|
||||
- try compiling with -Wunused
|
||||
- does everybody test return value of sk_open?
|
||||
- protocols: implement CLI hooks and per-procotol CLI commands
|
||||
- protocols: implement reconfigure hook
|
||||
- protocols: use locking
|
||||
- check use of system includes and sprintf()
|
||||
|
||||
Various ideas
|
||||
~~~~~~~~~~~~~
|
||||
- client: Ctrl-R eats one more enter
|
||||
- bgp: timing of updates?
|
||||
- netlink: realms
|
||||
- netlink: import Linux route attributes to our rta's, so that they can be filtered?
|
||||
- config: executable config files
|
||||
- filters: user defined attributes?
|
||||
- client: access control
|
||||
- io: use poll if available
|
||||
- real multipath (doesn't seem to be simple at all :()
|
||||
- fake multipath (even less simple)
|
||||
- route recalculation timing and flap dampening [see RFC2439 for algorithms]
|
||||
- aggregate engine: standard route aggregation and summarization [RFC2519]
|
||||
- aggregate engine: injection of manually configured pseudo-static routes
|
||||
- generate default route if any working BGP connection exists (aggregate engine again?)
|
||||
- generate default route to IGP's (aggregate engine yet another time?)
|
||||
- look at RFC 2386 (QoS-based routing)
|
||||
- cli: show tables?
|
||||
|
||||
OSPF
|
||||
~~~~
|
||||
- check incoming packets using neighbor cache
|
||||
- RFC2328 appendix E: Use a better algorithm
|
||||
- automatic generation of external route tags (RFC1403)
|
||||
- RFC3101 NSSA areas
|
||||
- RFC2370 opaque LSA's
|
||||
- Limit export rate of external LSAs (like Gated does)
|
||||
- Bugfix in link state retransmission list (aging)
|
||||
- Graceful OSPF restart - RFC3623
|
383
aclocal.m4
vendored
383
aclocal.m4
vendored
@ -1,178 +1,241 @@
|
||||
dnl ** Additional Autoconf tests for BIRD configure script
|
||||
dnl ** (c) 1999 Martin Mares <mj@ucw.cz>
|
||||
|
||||
AC_DEFUN(BIRD_CHECK_INTEGERS,
|
||||
[AC_CHECK_SIZEOF(char, 0)
|
||||
AC_CHECK_SIZEOF(short int, 0)
|
||||
AC_CHECK_SIZEOF(int, 0)
|
||||
AC_CHECK_SIZEOF(long int, 0)
|
||||
AC_CHECK_SIZEOF(long long int, 0)
|
||||
for size in 1 2 4 8; do
|
||||
bits=`expr $size "*" 8`
|
||||
AC_MSG_CHECKING([for $bits-bit type])
|
||||
if test $ac_cv_sizeof_int = $size ; then
|
||||
res=int
|
||||
elif test $ac_cv_sizeof_char = $size ; then
|
||||
res=char
|
||||
elif test $ac_cv_sizeof_short_int = $size ; then
|
||||
res="short int"
|
||||
elif test $ac_cv_sizeof_long_int = $size ; then
|
||||
res="long int"
|
||||
elif test $ac_cv_sizeof_long_long_int = $size ; then
|
||||
res="long long int"
|
||||
else
|
||||
AC_MSG_RESULT([not found])
|
||||
AC_MSG_ERROR([Cannot find $bits-bit integer type.])
|
||||
fi
|
||||
AC_MSG_RESULT($res)
|
||||
AC_DEFINE_UNQUOTED(INTEGER_$bits, $res)
|
||||
done
|
||||
AC_DEFUN([BIRD_CHECK_THREAD_LOCAL],
|
||||
[
|
||||
AC_CACHE_CHECK(
|
||||
[whether _Thread_local is known],
|
||||
[bird_cv_thread_local],
|
||||
AC_COMPILE_IFELSE([
|
||||
AC_LANG_PROGRAM(
|
||||
[
|
||||
_Thread_local static int x = 42;
|
||||
],
|
||||
[]
|
||||
)
|
||||
],
|
||||
[bird_cv_thread_local=yes],
|
||||
[bird_cv_thread_local=no]
|
||||
)
|
||||
)
|
||||
])
|
||||
|
||||
dnl BIRD_CHECK_ENDIAN is unused and obsolete
|
||||
AC_DEFUN(BIRD_CHECK_ENDIAN,
|
||||
[AC_CACHE_CHECK([CPU endianity], bird_cv_c_endian,[
|
||||
AC_TRY_RUN([
|
||||
#include <stdio.h>
|
||||
AC_DEFUN([BIRD_CHECK_PTHREADS],
|
||||
[
|
||||
bird_tmp_cflags="$CFLAGS"
|
||||
CFLAGS="$CFLAGS -pthread"
|
||||
|
||||
unsigned int x = 0x12345678;
|
||||
unsigned char *z = (unsigned char *) &x;
|
||||
AC_CACHE_CHECK(
|
||||
[whether POSIX threads are available],
|
||||
[bird_cv_lib_pthreads],
|
||||
[
|
||||
AC_LINK_IFELSE(
|
||||
[
|
||||
AC_LANG_PROGRAM(
|
||||
[ #include <pthread.h> ],
|
||||
[
|
||||
pthread_t pt;
|
||||
pthread_create(&pt, NULL, NULL, NULL);
|
||||
pthread_spinlock_t lock;
|
||||
pthread_spin_lock(&lock);
|
||||
]
|
||||
)
|
||||
],
|
||||
[bird_cv_lib_pthreads=yes],
|
||||
[bird_cv_lib_pthreads=no]
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
FILE *f = fopen("conftestresult", "w");
|
||||
if (!f) return 10;
|
||||
fprintf(f, "%02x %02x %02x %02x", *z, *(z+1), *(z+2), *(z+3));
|
||||
fclose(f);
|
||||
exit(0);
|
||||
}
|
||||
],[
|
||||
endian=`cat conftestresult`
|
||||
if test "$endian" = "12 34 56 78" ; then
|
||||
bird_cv_c_endian=big-endian
|
||||
elif test "$endian" = "78 56 34 12" ; then
|
||||
bird_cv_c_endian=little-endian
|
||||
fi
|
||||
],[endian="test program failed"],[endian="not available, we're cross compiling"])
|
||||
if test -z "$bird_cv_c_endian" ; then
|
||||
AC_MSG_RESULT($endian)
|
||||
AC_MSG_ERROR([Cannot determine CPU endianity.])
|
||||
fi
|
||||
])
|
||||
case $bird_cv_c_endian in
|
||||
big-endian) AC_DEFINE(CPU_BIG_ENDIAN) ;;
|
||||
little-endian) AC_DEFINE(CPU_LITTLE_ENDIAN) ;;
|
||||
esac
|
||||
CFLAGS="$bird_tmp_cflags"
|
||||
])
|
||||
|
||||
AC_DEFUN(BIRD_CHECK_STRUCT_ALIGN,
|
||||
[AC_CACHE_CHECK([usual alignment of structures],bird_cv_c_struct_align,[
|
||||
AC_TRY_RUN([
|
||||
#include <stdio.h>
|
||||
|
||||
struct { char x; long int y; } ary[2];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
FILE *f = fopen("conftestresult", "w");
|
||||
if (!f) return 10;
|
||||
fprintf(f, "%d", sizeof(ary)/2);
|
||||
fclose(f);
|
||||
exit(0);
|
||||
}
|
||||
],[
|
||||
bird_cv_c_struct_align=`cat conftestresult`
|
||||
],[
|
||||
AC_MSG_RESULT([test program failed])
|
||||
AC_MSG_ERROR([Cannot determine structure alignment])
|
||||
],[bird_cv_c_struct_align=16])
|
||||
])
|
||||
AC_DEFINE_UNQUOTED(CPU_STRUCT_ALIGN, $bird_cv_c_struct_align)
|
||||
AC_DEFUN([BIRD_CHECK_MPLS_KERNEL],
|
||||
[
|
||||
AC_CACHE_CHECK(
|
||||
[for Linux MPLS headers],
|
||||
[bird_cv_mpls_kernel],
|
||||
[
|
||||
AC_COMPILE_IFELSE(
|
||||
[
|
||||
AC_LANG_PROGRAM(
|
||||
[
|
||||
#include <linux/lwtunnel.h>
|
||||
#include <linux/netlink.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#include <sys/socket.h>
|
||||
void t(int arg);
|
||||
],
|
||||
[
|
||||
t(AF_MPLS);
|
||||
t(RTA_VIA);
|
||||
t(RTA_NEWDST);
|
||||
t(RTA_ENCAP_TYPE);
|
||||
t(RTA_ENCAP);
|
||||
struct rtvia rtvia;
|
||||
t(LWTUNNEL_ENCAP_MPLS);
|
||||
]
|
||||
)
|
||||
],
|
||||
[bird_cv_mpls_kernel=yes],
|
||||
[bird_cv_mpls_kernel=no]
|
||||
)
|
||||
]
|
||||
)
|
||||
])
|
||||
|
||||
AC_DEFUN(BIRD_CHECK_TIME_T,
|
||||
[AC_CACHE_CHECK([characteristics of time_t], bird_cv_type_time_t, [
|
||||
AC_TRY_RUN([
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
#include <limits.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
FILE *f = fopen("conftestresult", "w");
|
||||
if (!f) return 10;
|
||||
fprintf(f, "%d-bit ", sizeof(time_t)*CHAR_BIT);
|
||||
if ((time_t) -1 > 0) fprintf(f, "un");
|
||||
fprintf(f, "signed");
|
||||
fclose(f);
|
||||
exit(0);
|
||||
}
|
||||
],[bird_cv_type_time_t=`cat conftestresult`
|
||||
],[ AC_MSG_RESULT([test program failed])
|
||||
AC_MSG_ERROR([Cannot determine time_t size and signedness.])
|
||||
],[bird_cv_type_time_t="32-bit signed"])
|
||||
])
|
||||
case "$bird_cv_type_time_t" in
|
||||
*64-bit*) AC_DEFINE(TIME_T_IS_64BIT) ;;
|
||||
esac
|
||||
case "$bird_cv_type_time_t" in
|
||||
*unsigned*) ;;
|
||||
*) AC_DEFINE(TIME_T_IS_SIGNED) ;;
|
||||
esac
|
||||
AC_DEFUN([BIRD_CHECK_ANDROID_GLOB],
|
||||
[
|
||||
AC_CACHE_CHECK(
|
||||
[for glob.h],
|
||||
[bird_cv_lib_glob],
|
||||
AC_LINK_IFELSE([
|
||||
AC_LANG_PROGRAM(
|
||||
[
|
||||
#include <glob.h>
|
||||
#include <stdlib.h>
|
||||
],
|
||||
[ glob(NULL, 0, NULL, NULL); ]
|
||||
)
|
||||
],
|
||||
[bird_cv_lib_glob=yes],
|
||||
[
|
||||
bird_tmp_libs="$LIBS"
|
||||
LIBS="$LIBS -landroid-glob"
|
||||
AC_LINK_IFELSE([
|
||||
AC_LANG_PROGRAM(
|
||||
[
|
||||
#include <glob.h>
|
||||
#include <stdlib.h>
|
||||
],
|
||||
[ glob(NULL, 0, NULL, NULL); ]
|
||||
)
|
||||
],
|
||||
[bird_cv_lib_glob=-landroid-glob],
|
||||
[bird_cv_lib_glob=no]
|
||||
)
|
||||
LIBS="$bird_tmp_libs"
|
||||
]
|
||||
)
|
||||
)
|
||||
])
|
||||
|
||||
AC_DEFUN(BIRD_CHECK_STRUCT_IP_MREQN,
|
||||
[AC_CACHE_CHECK([for struct ip_mreqn], bird_cv_struct_ip_mreqn,[
|
||||
AC_TRY_COMPILE([#include <netinet/in.h>
|
||||
],[struct ip_mreqn x;
|
||||
],[bird_cv_struct_ip_mreqn=yes
|
||||
],[bird_cv_struct_ip_mreqn=no
|
||||
])])
|
||||
if test "$bird_cv_struct_ip_mreqn" = yes ; then
|
||||
AC_DEFINE(HAVE_STRUCT_IP_MREQN)
|
||||
fi
|
||||
AC_DEFUN([BIRD_CHECK_ANDROID_LOG],
|
||||
[
|
||||
AC_CACHE_CHECK(
|
||||
[for syslog lib flags],
|
||||
[bird_cv_lib_log],
|
||||
AC_LINK_IFELSE([
|
||||
AC_LANG_PROGRAM(
|
||||
[ #include <sys/syslog.h> ],
|
||||
[ syslog(0, ""); ]
|
||||
)
|
||||
],
|
||||
[bird_cv_lib_log=yes],
|
||||
[
|
||||
bird_tmp_libs="$LIBS"
|
||||
LIBS="$LIBS -llog"
|
||||
AC_LINK_IFELSE([
|
||||
AC_LANG_PROGRAM(
|
||||
[ #include <sys/syslog.h> ],
|
||||
[ syslog(0, ""); ]
|
||||
)
|
||||
],
|
||||
[bird_cv_lib_log=-llog],
|
||||
[bird_cv_lib_log=no]
|
||||
)
|
||||
LIBS="$bird_tmp_libs"
|
||||
]
|
||||
)
|
||||
)
|
||||
])
|
||||
|
||||
AC_DEFUN(BIRD_CHECK_LINUX_VERSION,
|
||||
[AC_CACHE_CHECK([Linux kernel version], bird_cv_sys_linux_version, [
|
||||
AC_REQUIRE_CPP()dnl
|
||||
cat > conftest.$ac_ext <<EOF
|
||||
[#]line __oline__ "configure"
|
||||
#include "confdefs.h"
|
||||
#include <linux/version.h>
|
||||
VERSION: UTS_RELEASE
|
||||
EOF
|
||||
bird_cv_sys_linux_version=`eval "$ac_cpp conftest.$ac_ext" 2>&AC_FD_CC | sed '/^VERSION/!d;s/^VERSION: "//;s/".*//'`
|
||||
rm -rf conftest*
|
||||
if test -z "$bird_cv_sys_linux_version" ; then
|
||||
AC_MSG_RESULT([unknown])
|
||||
AC_MSG_ERROR([Cannot determine kernel version])
|
||||
fi
|
||||
])])
|
||||
AC_DEFUN([BIRD_CHECK_LTO],
|
||||
[
|
||||
bird_tmp_cflags="$CFLAGS"
|
||||
bird_tmp_ldflags="$LDFLAGS"
|
||||
CFLAGS="-flto"
|
||||
LDFLAGS="-flto=4"
|
||||
|
||||
AC_DEFUN(BIRD_CHECK_GCC_OPTIONS,
|
||||
[AC_CACHE_VAL(bird_cv_c_option_no_pointer_sign, [
|
||||
cat >conftest.c <<EOF
|
||||
int main(void)
|
||||
{ return 0; }
|
||||
EOF
|
||||
if $CC -Wall -Wno-pointer-sign conftest.c >&AS_MESSAGE_LOG_FD 2>&1 ; then
|
||||
bird_cv_c_option_no_pointer_sign=yes
|
||||
else
|
||||
bird_cv_c_option_no_pointer_sign=no
|
||||
fi
|
||||
rm -rf conftest* a.out
|
||||
])])
|
||||
AC_CACHE_CHECK(
|
||||
[whether link time optimizer is available],
|
||||
[bird_cv_c_lto],
|
||||
[
|
||||
AC_LINK_IFELSE(
|
||||
[AC_LANG_PROGRAM()],
|
||||
[bird_cv_c_lto=yes],
|
||||
[bird_cv_c_lto=no]
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
CFLAGS="$bird_tmp_cflags"
|
||||
LDFLAGS="$bird_tmp_ldflags"
|
||||
])
|
||||
|
||||
|
||||
AC_DEFUN([BIRD_CHECK_GCC_OPTION],
|
||||
[
|
||||
bird_tmp_cflags="$CFLAGS"
|
||||
CFLAGS="$3 $2"
|
||||
|
||||
AC_CACHE_CHECK(
|
||||
[whether CC supports $2],
|
||||
[$1],
|
||||
[
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_PROGRAM()],
|
||||
[$1=yes],
|
||||
[$1=no]
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
CFLAGS="$bird_tmp_cflags"
|
||||
])
|
||||
|
||||
AC_DEFUN([BIRD_ADD_GCC_OPTION],
|
||||
[
|
||||
if test "$$1" = yes ; then
|
||||
CFLAGS="$CFLAGS $2"
|
||||
fi
|
||||
])
|
||||
|
||||
# BIRD_CHECK_PROG_FLAVOR_GNU(PROGRAM-PATH, IF-SUCCESS, [IF-FAILURE])
|
||||
# copied autoconf internal _AC_PATH_PROG_FLAVOR_GNU
|
||||
m4_define([BIRD_CHECK_PROG_FLAVOR_GNU],
|
||||
[# Check for GNU $1
|
||||
case `"$1" --version 2>&1` in
|
||||
*GNU*)
|
||||
$2;;
|
||||
m4_ifval([$3],
|
||||
[*)
|
||||
$3;;
|
||||
])esac
|
||||
])#
|
||||
# copied from autoconf internal _AC_PATH_PROG_FLAVOR_GNU
|
||||
AC_DEFUN([BIRD_CHECK_PROG_FLAVOR_GNU],
|
||||
[
|
||||
# Check for GNU $1
|
||||
case `"$1" --version 2>&1` in
|
||||
*GNU*)
|
||||
$2
|
||||
;;
|
||||
m4_ifval([$3],
|
||||
[*)
|
||||
$3
|
||||
;;
|
||||
]
|
||||
)
|
||||
esac
|
||||
])
|
||||
|
||||
AC_DEFUN([BIRD_CHECK_BISON_VERSION],
|
||||
[
|
||||
$1=`bison --version | ( read line; echo ${line##* } )`
|
||||
case "$$1" in
|
||||
1.* | 2.0* | 2.1* | 2.2* | 2.3*)
|
||||
AC_MSG_ERROR([Provided Bison version $$1 is too old, need at least 2.4])
|
||||
;;
|
||||
2.*)
|
||||
bird_bison_synclines=no
|
||||
bird_bison_enhanced_error=no
|
||||
;;
|
||||
3.* | 4.* | 5.* | 6.* | 7.* | 8.* | 9.*)
|
||||
bird_bison_synclines=yes
|
||||
bird_bison_enhanced_error=yes
|
||||
;;
|
||||
*)
|
||||
AC_MSG_ERROR([Couldn't parse Bison version $$1. Call the developers for help.])
|
||||
;;
|
||||
esac
|
||||
])
|
||||
|
154
bird-gdb.py
Normal file
154
bird-gdb.py
Normal file
@ -0,0 +1,154 @@
|
||||
class BIRDPrinter:
|
||||
def __init__(self, val):
|
||||
self.val = val
|
||||
|
||||
@classmethod
|
||||
def lookup(cls, val):
|
||||
if val.type.code != cls.typeCode:
|
||||
return None
|
||||
if val.type.tag != cls.typeTag:
|
||||
return None
|
||||
|
||||
return cls(val)
|
||||
|
||||
|
||||
class BIRDFValPrinter(BIRDPrinter):
|
||||
"Print BIRD\s struct f_val"
|
||||
typeCode = gdb.TYPE_CODE_STRUCT
|
||||
typeTag = "f_val"
|
||||
|
||||
codemap = {
|
||||
"T_INT": "i",
|
||||
"T_BOOL": "i",
|
||||
"T_PAIR": "i",
|
||||
"T_QUAD": "i",
|
||||
"T_ENUM_RTS": "i",
|
||||
"T_ENUM_BGP_ORIGIN": "i",
|
||||
"T_ENUM_SCOPE": "i",
|
||||
"T_ENUM_RTC": "i",
|
||||
"T_ENUM_RTD": "i",
|
||||
"T_ENUM_ROA": "i",
|
||||
"T_ENUM_NETTYPE": "i",
|
||||
"T_ENUM_RA_PREFERENCE": "i",
|
||||
"T_ENUM_AF": "i",
|
||||
"T_IP": "ip",
|
||||
"T_NET": "net",
|
||||
"T_STRING": "s",
|
||||
"T_PATH_MASK": "path_mask",
|
||||
"T_PATH": "ad",
|
||||
"T_CLIST": "ad",
|
||||
"T_EC": "ec",
|
||||
"T_ECLIST": "ad",
|
||||
"T_LC": "lc",
|
||||
"T_LCLIST": "ad",
|
||||
"T_RD": "ec",
|
||||
"T_PATH_MASK_ITEM": "pmi",
|
||||
"T_SET": "t",
|
||||
"T_PREFIX_SET": "ti",
|
||||
}
|
||||
|
||||
def to_string(self):
|
||||
code = self.val['type']
|
||||
if code.type.code != gdb.TYPE_CODE_ENUM or code.type.tag != "f_type":
|
||||
raise Exception("Strange 'type' element in f_val")
|
||||
|
||||
if str(code) == "T_VOID":
|
||||
return "T_VOID"
|
||||
else:
|
||||
return "(%(c)s) %(v)s" % { "c": code, "v": self.val['val'][self.codemap[str(code)]] }
|
||||
|
||||
def display_hint(self):
|
||||
return "map"
|
||||
|
||||
class BIRDFValStackPrinter(BIRDPrinter):
|
||||
"Print BIRD's struct f_val_stack"
|
||||
typeCode = gdb.TYPE_CODE_STRUCT
|
||||
typeTag = "f_val_stack"
|
||||
|
||||
def to_string(self):
|
||||
cnt = self.val['cnt']
|
||||
return ("Value stack (%(cnt)d):\n\t" % { "cnt": cnt }) + \
|
||||
"\n\t".join([ (".val[%(n) 3d] = " % { "n": n}) + str(self.val['val'][n]) for n in range(cnt-1, -1, -1) ])
|
||||
|
||||
def display_hint(self):
|
||||
return "map"
|
||||
|
||||
class BIRDFInstPrinter(BIRDPrinter):
|
||||
"Print BIRD's struct f_inst"
|
||||
typeCode = gdb.TYPE_CODE_STRUCT
|
||||
typeTag = "f_inst"
|
||||
|
||||
def to_string(self):
|
||||
code = self.val['fi_code']
|
||||
if str(code) == "FI_NOP":
|
||||
return str(code) + ": " + str(self.val.cast(gdb.lookup_type("const char [%(siz)d]" % { "siz": self.val.type.sizeof })))
|
||||
return "%(code)s:\t%(lineno) 6dL\t%(size)6dS\tnext = %(next)s: .i_%(code)s = %(union)s" % {
|
||||
"code": str(code),
|
||||
"lineno": self.val['lineno'],
|
||||
"size": self.val['size'],
|
||||
"next": str(self.val['next']),
|
||||
"union": str(self.val['i_' + str(code)])
|
||||
}
|
||||
|
||||
# def children(self): # children iterator
|
||||
def display_hint(self):
|
||||
return "map"
|
||||
|
||||
class BIRDFLineItemPrinter(BIRDPrinter):
|
||||
"Print BIRD's struct f_line_item"
|
||||
typeCode = gdb.TYPE_CODE_STRUCT
|
||||
typeTag = "f_line_item"
|
||||
|
||||
def to_string(self):
|
||||
code = self.val['fi_code']
|
||||
if str(code) == "FI_NOP":
|
||||
return str(code) + ": " + str(self.val.cast(gdb.lookup_type("const char [%(siz)d]" % { "siz": self.val.type.sizeof })))
|
||||
return "%(code)s:\t%(lineno) 6dL\t%(flags)2dF: .i_%(code)s = %(union)s" % {
|
||||
"code": str(code),
|
||||
"lineno": self.val['lineno'],
|
||||
"flags": self.val['flags'],
|
||||
"union": str(self.val['i_' + str(code)])
|
||||
}
|
||||
|
||||
class BIRDFLinePrinter(BIRDPrinter):
|
||||
"Print BIRD's struct f_line"
|
||||
typeCode = gdb.TYPE_CODE_STRUCT
|
||||
typeTag = "f_line"
|
||||
|
||||
def to_string(self):
|
||||
cnt = self.val['len']
|
||||
return ("FLine (%(cnt)d, args=%(args)d): " % { "cnt": cnt, "args" : self.val['args'] } + \
|
||||
", ".join([
|
||||
".items[%(n) 3d] = %(code)s" % {
|
||||
"n": n,
|
||||
"code": str(self.val['items'][n]['fi_code']),
|
||||
} if n % 8 == 0 else str(self.val['items'][n]['fi_code']) for n in range(cnt)]))
|
||||
|
||||
|
||||
class BIRDFExecStackPrinter(BIRDPrinter):
|
||||
"Print BIRD's struct f_exec_stack"
|
||||
typeCode = gdb.TYPE_CODE_STRUCT
|
||||
typeTag = "f_exec_stack"
|
||||
|
||||
def to_string(self):
|
||||
cnt = self.val['cnt']
|
||||
return ("Exec stack (%(cnt)d):\n\t" % { "cnt": cnt }) + \
|
||||
"\n\t".join([ ".item[%(n) 3d] = %(retflag)d V%(ventry) 3d P%(pos) 4d %(line)s" % {
|
||||
"retflag": self.val['item'][n]['emask'],
|
||||
"ventry": self.val['item'][n]['ventry'],
|
||||
"pos": self.val['item'][n]['pos'],
|
||||
"line": str(self.val['item'][n]['line'].dereference()),
|
||||
"n": n
|
||||
} for n in range(cnt-1, -1, -1) ])
|
||||
|
||||
def register_printers(objfile):
|
||||
objfile.pretty_printers.append(BIRDFInstPrinter.lookup)
|
||||
objfile.pretty_printers.append(BIRDFValPrinter.lookup)
|
||||
objfile.pretty_printers.append(BIRDFValStackPrinter.lookup)
|
||||
objfile.pretty_printers.append(BIRDFLineItemPrinter.lookup)
|
||||
objfile.pretty_printers.append(BIRDFLinePrinter.lookup)
|
||||
objfile.pretty_printers.append(BIRDFExecStackPrinter.lookup)
|
||||
|
||||
register_printers(gdb.current_objfile())
|
||||
|
||||
print("BIRD pretty printers loaded OK.")
|
58
bird.conf
58
bird.conf
@ -1,44 +1,58 @@
|
||||
/*
|
||||
* This is an example configuration file.
|
||||
* This is a simple example configuration file with no aim for completeness.
|
||||
* See documentation for full description.
|
||||
*/
|
||||
|
||||
# Yet another comment
|
||||
|
||||
# Router ID in IPv4 format
|
||||
router id 62.168.0.1;
|
||||
|
||||
define xyzzy = (120+10);
|
||||
# Load device information from kernel.
|
||||
protocol device {}
|
||||
|
||||
protocol device {
|
||||
# Generate direct routes for interfaces. Useful on BSD.
|
||||
protocol direct {
|
||||
ipv4;
|
||||
disabled;
|
||||
# interface "eth*", "ppp*";
|
||||
}
|
||||
|
||||
protocol direct {
|
||||
ipv6;
|
||||
disabled;
|
||||
}
|
||||
|
||||
# Feed routes to kernel FIB
|
||||
protocol kernel {
|
||||
disabled;
|
||||
# learn; # Learn all routes from the kernel
|
||||
ipv4 { export all; import all; };
|
||||
learn; # Learn all routes from the kernel
|
||||
# scan time 10; # Scan kernel tables every 10 seconds
|
||||
}
|
||||
|
||||
protocol kernel {
|
||||
ipv6 { import all; };
|
||||
learn;
|
||||
}
|
||||
|
||||
# Static route feed
|
||||
protocol static {
|
||||
# disabled;
|
||||
ipv4 { export all; };
|
||||
route 10.0.0.0/24 via 55.55.55.44;
|
||||
route 10.10.0.0/16 blackhole;
|
||||
route 10.20.0.0/20 unreachable;
|
||||
route 10.30.50.0/28 prohibit;
|
||||
}
|
||||
|
||||
route fec0:2::/64 reject;
|
||||
route fec0:3::/64 reject;
|
||||
route fec0:4::/64 reject;
|
||||
|
||||
# route 0.0.0.0/0 via 195.113.31.113;
|
||||
# route 62.168.0.0/25 reject;
|
||||
# route 1.2.3.4/32 via 195.113.31.124;
|
||||
# route 10.0.0.0/8 reject;
|
||||
# route 10.1.1.0:255.255.255.0 via 62.168.0.3;
|
||||
# route 10.1.2.0:255.255.255.0 via 62.168.0.3;
|
||||
# route 10.1.3.0:255.255.255.0 via 62.168.0.4;
|
||||
# route 10.2.0.0/24 via "arc0";
|
||||
export all;
|
||||
protocol static {
|
||||
ipv6 { export all; };
|
||||
route 2001:db8:1::/48 via 5555::6666;
|
||||
route 2001:db8:2::/48 blackhole;
|
||||
route 2001:db8:3::/48 prohibit;
|
||||
route 2001:db8:4::/48 unreachable;
|
||||
}
|
||||
|
||||
protocol rip {
|
||||
ipv4;
|
||||
}
|
||||
|
||||
protocol rip ng {
|
||||
ipv6;
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
source=client.c commands.c util.c
|
||||
root-rel=../
|
||||
dir-name=client
|
||||
src := commands.c util.c client.c
|
||||
obj := $(src-o-files)
|
||||
|
||||
include ../Rules
|
||||
$(all-client)
|
||||
$(conf-y-targets): $(s)cmds.Y
|
||||
|
||||
$(exedir)/birdc: $(o)birdc.o
|
||||
$(exedir)/birdc: LIBS += $(CLIENT_LIBS)
|
||||
|
||||
$(exedir)/birdcl: $(o)birdcl.o
|
||||
|
242
client/birdc.c
Normal file
242
client/birdc.c
Normal file
@ -0,0 +1,242 @@
|
||||
/*
|
||||
* BIRD Client - Readline variant I/O
|
||||
*
|
||||
* (c) 1999--2004 Martin Mares <mj@ucw.cz>
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <termios.h>
|
||||
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
#include <curses.h>
|
||||
|
||||
#include "nest/bird.h"
|
||||
#include "lib/resource.h"
|
||||
#include "lib/string.h"
|
||||
#include "client/client.h"
|
||||
|
||||
static int input_hidden_end;
|
||||
static int prompt_active;
|
||||
|
||||
/*** Input ***/
|
||||
|
||||
/* HACK: libreadline internals we need to access */
|
||||
extern int _rl_vis_botlin;
|
||||
extern void _rl_move_vert(int);
|
||||
|
||||
#define HISTORY "/.birdc_history"
|
||||
static char *history_file;
|
||||
|
||||
static void
|
||||
add_history_dedup(char *cmd)
|
||||
{
|
||||
/* Add history line if it differs from the last one */
|
||||
HIST_ENTRY *he = history_get(history_length);
|
||||
if (!he || strcmp(he->line, cmd))
|
||||
add_history(cmd);
|
||||
}
|
||||
|
||||
static void
|
||||
input_got_line(char *cmd_buffer)
|
||||
{
|
||||
if (!cmd_buffer)
|
||||
{
|
||||
cleanup();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (cmd_buffer[0])
|
||||
{
|
||||
add_history_dedup(cmd_buffer);
|
||||
submit_command(cmd_buffer);
|
||||
}
|
||||
|
||||
free(cmd_buffer);
|
||||
}
|
||||
|
||||
void
|
||||
input_start_list(void)
|
||||
{
|
||||
/* Leave the currently edited line and make space for listing */
|
||||
_rl_move_vert(_rl_vis_botlin);
|
||||
#ifdef HAVE_RL_CRLF
|
||||
rl_crlf();
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
input_stop_list(void)
|
||||
{
|
||||
/* Reprint the currently edited line after listing */
|
||||
rl_on_new_line();
|
||||
rl_redisplay();
|
||||
}
|
||||
|
||||
static int
|
||||
input_complete(int arg UNUSED, int key UNUSED)
|
||||
{
|
||||
static int complete_flag;
|
||||
char buf[256];
|
||||
|
||||
if (rl_last_func != input_complete)
|
||||
complete_flag = 0;
|
||||
switch (cmd_complete(rl_line_buffer, rl_point, buf, complete_flag))
|
||||
{
|
||||
case 0:
|
||||
complete_flag = 1;
|
||||
break;
|
||||
case 1:
|
||||
rl_insert_text(buf);
|
||||
break;
|
||||
default:
|
||||
complete_flag = 1;
|
||||
#ifdef HAVE_RL_DING
|
||||
rl_ding();
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
input_help(int arg, int key UNUSED)
|
||||
{
|
||||
int i, in_string, in_bracket;
|
||||
|
||||
if (arg != 1)
|
||||
return rl_insert(arg, '?');
|
||||
|
||||
in_string = in_bracket = 0;
|
||||
for (i = 0; i < rl_point; i++)
|
||||
{
|
||||
|
||||
if (rl_line_buffer[i] == '"')
|
||||
in_string = ! in_string;
|
||||
else if (! in_string)
|
||||
{
|
||||
if (rl_line_buffer[i] == '[')
|
||||
in_bracket++;
|
||||
else if (rl_line_buffer[i] == ']')
|
||||
in_bracket--;
|
||||
}
|
||||
}
|
||||
|
||||
/* `?' inside string or path -> insert */
|
||||
if (in_string || in_bracket)
|
||||
return rl_insert(1, '?');
|
||||
|
||||
rl_begin_undo_group(); /* HACK: We want to display `?' at point position */
|
||||
rl_insert_text("?");
|
||||
rl_redisplay();
|
||||
rl_end_undo_group();
|
||||
input_start_list();
|
||||
cmd_help(rl_line_buffer, rl_point);
|
||||
rl_undo_command(1, 0);
|
||||
input_stop_list();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
history_init(void)
|
||||
{
|
||||
const char *homedir = getenv("HOME");
|
||||
if (!homedir)
|
||||
homedir = ".";
|
||||
history_file = malloc(strlen(homedir) + sizeof(HISTORY));
|
||||
if (!history_file)
|
||||
die("couldn't alloc enough memory for history file name");
|
||||
|
||||
sprintf(history_file, "%s%s", homedir, HISTORY);
|
||||
read_history(history_file);
|
||||
}
|
||||
|
||||
void
|
||||
input_init(void)
|
||||
{
|
||||
if (interactive)
|
||||
history_init();
|
||||
rl_readline_name = "birdc";
|
||||
rl_add_defun("bird-complete", input_complete, '\t');
|
||||
rl_add_defun("bird-help", input_help, '?');
|
||||
rl_callback_handler_install("bird> ", input_got_line);
|
||||
|
||||
// rl_get_screen_size();
|
||||
term_lns = LINES;
|
||||
term_cls = COLS;
|
||||
|
||||
prompt_active = 1;
|
||||
|
||||
// readline library does strange things when stdin is nonblocking.
|
||||
// if (fcntl(0, F_SETFL, O_NONBLOCK) < 0)
|
||||
// DIE("fcntl");
|
||||
}
|
||||
|
||||
static void
|
||||
input_reveal(void)
|
||||
{
|
||||
/* need this, otherwise some lib seems to eat pending output when
|
||||
the prompt is displayed */
|
||||
fflush(stdout);
|
||||
tcdrain(STDOUT_FILENO);
|
||||
|
||||
rl_end = input_hidden_end;
|
||||
rl_expand_prompt("bird> ");
|
||||
rl_forced_update_display();
|
||||
|
||||
prompt_active = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
input_hide(void)
|
||||
{
|
||||
input_hidden_end = rl_end;
|
||||
rl_end = 0;
|
||||
rl_expand_prompt("");
|
||||
rl_redisplay();
|
||||
|
||||
prompt_active = 0;
|
||||
}
|
||||
|
||||
void
|
||||
input_notify(int prompt)
|
||||
{
|
||||
if (prompt == prompt_active)
|
||||
return;
|
||||
|
||||
if (prompt)
|
||||
input_reveal();
|
||||
else
|
||||
input_hide();
|
||||
}
|
||||
|
||||
void
|
||||
input_read(void)
|
||||
{
|
||||
rl_callback_read_char();
|
||||
}
|
||||
|
||||
void
|
||||
more_begin(void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
more_end(void)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
cleanup(void)
|
||||
{
|
||||
if (init)
|
||||
return;
|
||||
|
||||
input_hide();
|
||||
if (interactive)
|
||||
write_history(history_file);
|
||||
rl_callback_handler_remove();
|
||||
}
|
161
client/birdcl.c
Normal file
161
client/birdcl.c
Normal file
@ -0,0 +1,161 @@
|
||||
/*
|
||||
* BIRD Client - Light variant I/O
|
||||
*
|
||||
* (c) 1999--2004 Martin Mares <mj@ucw.cz>
|
||||
* (c) 2013 Tomas Hlavacek <tomas.hlavacek@nic.cz>
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <termios.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "nest/bird.h"
|
||||
#include "lib/resource.h"
|
||||
#include "lib/string.h"
|
||||
#include "client/client.h"
|
||||
#include "sysdep/unix/unix.h"
|
||||
|
||||
#define INPUT_BUF_LEN 2048
|
||||
|
||||
struct termios tty_save;
|
||||
|
||||
void
|
||||
input_start_list(void)
|
||||
{
|
||||
/* Empty in non-ncurses version. */
|
||||
}
|
||||
|
||||
void
|
||||
input_stop_list(void)
|
||||
{
|
||||
/* Empty in non-ncurses version. */
|
||||
}
|
||||
|
||||
void
|
||||
input_notify(int prompt)
|
||||
{
|
||||
/* No ncurses -> no status to reveal/hide, print prompt manually. */
|
||||
if (!prompt)
|
||||
return;
|
||||
|
||||
printf("bird> ");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
lastnb(char *str, int i)
|
||||
{
|
||||
while (i--)
|
||||
if ((str[i] != ' ') && (str[i] != '\t'))
|
||||
return str[i];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
input_read(void)
|
||||
{
|
||||
char buf[INPUT_BUF_LEN];
|
||||
|
||||
if ((fgets(buf, INPUT_BUF_LEN, stdin) == NULL) || (buf[0] == 0))
|
||||
{
|
||||
putchar('\n');
|
||||
cleanup();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int l = strlen(buf);
|
||||
if ((l+1) == INPUT_BUF_LEN)
|
||||
{
|
||||
printf("Input too long.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (buf[l-1] == '\n')
|
||||
buf[--l] = '\0';
|
||||
|
||||
if (!interactive)
|
||||
printf("%s\n", buf);
|
||||
|
||||
if (l == 0)
|
||||
return;
|
||||
|
||||
if (lastnb(buf, l) == '?')
|
||||
{
|
||||
cmd_help(buf, strlen(buf));
|
||||
return;
|
||||
}
|
||||
|
||||
submit_command(buf);
|
||||
}
|
||||
|
||||
static struct termios stored_tty;
|
||||
static int more_active = 0;
|
||||
|
||||
void
|
||||
more_begin(void)
|
||||
{
|
||||
static struct termios tty;
|
||||
|
||||
tty = stored_tty;
|
||||
tty.c_lflag &= (~ECHO);
|
||||
tty.c_lflag &= (~ICANON);
|
||||
|
||||
if (tcsetattr (0, TCSANOW, &tty) < 0)
|
||||
DIE("tcsetattr");
|
||||
|
||||
more_active = 1;
|
||||
}
|
||||
|
||||
void
|
||||
more_end(void)
|
||||
{
|
||||
more_active = 0;
|
||||
|
||||
if (tcsetattr (0, TCSANOW, &stored_tty) < 0)
|
||||
DIE("tcsetattr");
|
||||
}
|
||||
|
||||
static void
|
||||
sig_handler(int signal UNUSED)
|
||||
{
|
||||
cleanup();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void
|
||||
input_init(void)
|
||||
{
|
||||
if (!interactive)
|
||||
return;
|
||||
|
||||
if (tcgetattr(0, &stored_tty) < 0)
|
||||
DIE("tcgetattr");
|
||||
|
||||
if (signal(SIGINT, sig_handler) == SIG_IGN)
|
||||
signal(SIGINT, SIG_IGN);
|
||||
if (signal(SIGTERM, sig_handler) == SIG_IGN)
|
||||
signal(SIGTERM, SIG_IGN);
|
||||
|
||||
struct winsize tws;
|
||||
if (ioctl(0, TIOCGWINSZ, &tws) == 0)
|
||||
{
|
||||
term_lns = tws.ws_row;
|
||||
term_cls = tws.ws_col;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
cleanup(void)
|
||||
{
|
||||
if (more_active)
|
||||
more_end();
|
||||
}
|
362
client/client.c
362
client/client.c
@ -2,22 +2,33 @@
|
||||
* BIRD Client
|
||||
*
|
||||
* (c) 1999--2004 Martin Mares <mj@ucw.cz>
|
||||
* (c) 2013 Tomas Hlavacek <tmshlvck@gmail.com>
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
/**
|
||||
* DOC: BIRD client
|
||||
*
|
||||
* There are two variants of BIRD client: regular and light. regular
|
||||
* variant depends on readline and ncurses libraries, while light
|
||||
* variant uses just libc. Most of the code and the main() is common
|
||||
* for both variants (in client.c file) and just a few functions are
|
||||
* different (in birdc.c for regular and birdcl.c for light). Two
|
||||
* binaries are generated by linking common object files like client.o
|
||||
* (which is compiled from client.c just once) with either birdc.o or
|
||||
* birdcl.o for each variant.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <termios.h>
|
||||
#include <errno.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/types.h>
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
#include <curses.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
#include "nest/bird.h"
|
||||
#include "lib/resource.h"
|
||||
@ -25,39 +36,38 @@
|
||||
#include "client/client.h"
|
||||
#include "sysdep/unix/unix.h"
|
||||
|
||||
static char *opt_list = "s:vr";
|
||||
static int verbose;
|
||||
#define SERVER_READ_BUF_LEN 4096
|
||||
|
||||
static char *opt_list = "s:vrl";
|
||||
static int verbose, restricted, once;
|
||||
static char *init_cmd;
|
||||
static int once;
|
||||
|
||||
static char *server_path = PATH_CONTROL_SOCKET;
|
||||
static int server_fd;
|
||||
static byte server_read_buf[4096];
|
||||
static byte server_read_buf[SERVER_READ_BUF_LEN];
|
||||
static byte *server_read_pos = server_read_buf;
|
||||
|
||||
#define STATE_PROMPT 0
|
||||
#define STATE_CMD_SERVER 1
|
||||
#define STATE_CMD_USER 2
|
||||
int init = 1; /* During intial sequence */
|
||||
int busy = 1; /* Executing BIRD command */
|
||||
int interactive; /* Whether stdin is terminal */
|
||||
|
||||
static int input_initialized;
|
||||
static int input_hidden_end;
|
||||
static int cstate = STATE_CMD_SERVER;
|
||||
static int nstate = STATE_CMD_SERVER;
|
||||
static int num_lines, skip_input;
|
||||
int term_lns, term_cls;
|
||||
|
||||
static int num_lines, skip_input, interactive;
|
||||
|
||||
/*** Parsing of arguments ***/
|
||||
|
||||
static void
|
||||
usage(void)
|
||||
usage(char *name)
|
||||
{
|
||||
fprintf(stderr, "Usage: birdc [-s <control-socket>] [-v] [-r]\n");
|
||||
fprintf(stderr, "Usage: %s [-s <control-socket>] [-v] [-r] [-l]\n", name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void
|
||||
parse_args(int argc, char **argv)
|
||||
{
|
||||
int server_changed = 0;
|
||||
int c;
|
||||
|
||||
while ((c = getopt(argc, argv, opt_list)) >= 0)
|
||||
@ -65,15 +75,20 @@ parse_args(int argc, char **argv)
|
||||
{
|
||||
case 's':
|
||||
server_path = optarg;
|
||||
server_changed = 1;
|
||||
break;
|
||||
case 'v':
|
||||
verbose++;
|
||||
break;
|
||||
case 'r':
|
||||
init_cmd = "restrict";
|
||||
restricted = 1;
|
||||
break;
|
||||
case 'l':
|
||||
if (!server_changed)
|
||||
server_path = xbasename(server_path);
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
usage(argv[0]);
|
||||
}
|
||||
|
||||
/* If some arguments are not options, we take it as commands */
|
||||
@ -83,9 +98,6 @@ parse_args(int argc, char **argv)
|
||||
int i;
|
||||
int len = 0;
|
||||
|
||||
if (init_cmd)
|
||||
usage();
|
||||
|
||||
for (i = optind; i < argc; i++)
|
||||
len += strlen(argv[i]) + 1;
|
||||
|
||||
@ -99,17 +111,14 @@ parse_args(int argc, char **argv)
|
||||
tmp[-1] = 0;
|
||||
|
||||
once = 1;
|
||||
interactive = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*** Input ***/
|
||||
|
||||
static void server_send(char *);
|
||||
|
||||
/* HACK: libreadline internals we need to access */
|
||||
extern int _rl_vis_botlin;
|
||||
extern void _rl_move_vert(int);
|
||||
extern Function *rl_last_func;
|
||||
static void server_send(char *cmd);
|
||||
|
||||
static int
|
||||
handle_internal_command(char *cmd)
|
||||
@ -127,217 +136,95 @@ handle_internal_command(char *cmd)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
submit_server_command(char *cmd)
|
||||
{
|
||||
server_send(cmd);
|
||||
nstate = STATE_CMD_SERVER;
|
||||
busy = 1;
|
||||
num_lines = 2;
|
||||
server_send(cmd);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
got_line(char *cmd_buffer)
|
||||
static inline void
|
||||
submit_init_command(char *cmd_raw)
|
||||
{
|
||||
char *cmd;
|
||||
char *cmd = cmd_expand(cmd_raw);
|
||||
|
||||
if (!cmd_buffer)
|
||||
{
|
||||
cleanup();
|
||||
exit(0);
|
||||
}
|
||||
if (cmd_buffer[0])
|
||||
{
|
||||
cmd = cmd_expand(cmd_buffer);
|
||||
if (cmd)
|
||||
{
|
||||
add_history(cmd);
|
||||
if (!cmd)
|
||||
{
|
||||
cleanup();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (!handle_internal_command(cmd))
|
||||
submit_server_command(cmd);
|
||||
|
||||
free(cmd);
|
||||
}
|
||||
else
|
||||
add_history(cmd_buffer);
|
||||
}
|
||||
free(cmd_buffer);
|
||||
submit_server_command(cmd);
|
||||
free(cmd);
|
||||
}
|
||||
|
||||
void
|
||||
input_start_list(void) /* Leave the currently edited line and make space for listing */
|
||||
submit_command(char *cmd_raw)
|
||||
{
|
||||
_rl_move_vert(_rl_vis_botlin);
|
||||
#ifdef HAVE_RL_CRLF
|
||||
rl_crlf();
|
||||
#endif
|
||||
}
|
||||
char *cmd = cmd_expand(cmd_raw);
|
||||
|
||||
void
|
||||
input_stop_list(void) /* Reprint the currently edited line after listing */
|
||||
{
|
||||
rl_on_new_line();
|
||||
rl_redisplay();
|
||||
}
|
||||
|
||||
static int
|
||||
input_complete(int arg UNUSED, int key UNUSED)
|
||||
{
|
||||
static int complete_flag;
|
||||
char buf[256];
|
||||
|
||||
if (rl_last_func != input_complete)
|
||||
complete_flag = 0;
|
||||
switch (cmd_complete(rl_line_buffer, rl_point, buf, complete_flag))
|
||||
{
|
||||
case 0:
|
||||
complete_flag = 1;
|
||||
break;
|
||||
case 1:
|
||||
rl_insert_text(buf);
|
||||
break;
|
||||
default:
|
||||
complete_flag = 1;
|
||||
#ifdef HAVE_RL_DING
|
||||
rl_ding();
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
input_help(int arg, int key UNUSED)
|
||||
{
|
||||
int i, in_string, in_bracket;
|
||||
|
||||
if (arg != 1)
|
||||
return rl_insert(arg, '?');
|
||||
|
||||
in_string = in_bracket = 0;
|
||||
for (i = 0; i < rl_point; i++)
|
||||
{
|
||||
|
||||
if (rl_line_buffer[i] == '"')
|
||||
in_string = ! in_string;
|
||||
else if (! in_string)
|
||||
{
|
||||
if (rl_line_buffer[i] == '[')
|
||||
in_bracket++;
|
||||
else if (rl_line_buffer[i] == ']')
|
||||
in_bracket--;
|
||||
}
|
||||
}
|
||||
|
||||
/* `?' inside string or path -> insert */
|
||||
if (in_string || in_bracket)
|
||||
return rl_insert(1, '?');
|
||||
|
||||
rl_begin_undo_group(); /* HACK: We want to display `?' at point position */
|
||||
rl_insert_text("?");
|
||||
rl_redisplay();
|
||||
rl_end_undo_group();
|
||||
input_start_list();
|
||||
cmd_help(rl_line_buffer, rl_point);
|
||||
rl_undo_command(1, 0);
|
||||
input_stop_list();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
input_init(void)
|
||||
{
|
||||
rl_readline_name = "birdc";
|
||||
rl_add_defun("bird-complete", input_complete, '\t');
|
||||
rl_add_defun("bird-help", input_help, '?');
|
||||
rl_callback_handler_install("bird> ", got_line);
|
||||
input_initialized = 1;
|
||||
// readline library does strange things when stdin is nonblocking.
|
||||
// if (fcntl(0, F_SETFL, O_NONBLOCK) < 0)
|
||||
// die("fcntl: %m");
|
||||
}
|
||||
|
||||
static void
|
||||
input_hide(void)
|
||||
{
|
||||
input_hidden_end = rl_end;
|
||||
rl_end = 0;
|
||||
rl_expand_prompt("");
|
||||
rl_redisplay();
|
||||
}
|
||||
|
||||
static void
|
||||
input_reveal(void)
|
||||
{
|
||||
/* need this, otherwise some lib seems to eat pending output when
|
||||
the prompt is displayed */
|
||||
fflush(stdout);
|
||||
tcdrain(fileno(stdout));
|
||||
|
||||
rl_end = input_hidden_end;
|
||||
rl_expand_prompt("bird> ");
|
||||
rl_forced_update_display();
|
||||
}
|
||||
|
||||
void
|
||||
cleanup(void)
|
||||
{
|
||||
if (input_initialized)
|
||||
{
|
||||
input_initialized = 0;
|
||||
input_hide();
|
||||
rl_callback_handler_remove();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
update_state(void)
|
||||
{
|
||||
if (nstate == cstate)
|
||||
if (!cmd)
|
||||
return;
|
||||
|
||||
if (!handle_internal_command(cmd))
|
||||
submit_server_command(cmd);
|
||||
|
||||
free(cmd);
|
||||
}
|
||||
|
||||
static void
|
||||
init_commands(void)
|
||||
{
|
||||
if (restricted)
|
||||
{
|
||||
submit_server_command("restrict");
|
||||
restricted = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (init_cmd)
|
||||
{
|
||||
/* First transition - client received hello from BIRD
|
||||
and there is waiting initial command */
|
||||
submit_server_command(init_cmd);
|
||||
submit_init_command(init_cmd);
|
||||
init_cmd = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!init_cmd && once)
|
||||
if (once)
|
||||
{
|
||||
/* Initial command is finished and we want to exit */
|
||||
cleanup();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (nstate == STATE_PROMPT)
|
||||
{
|
||||
if (input_initialized)
|
||||
input_reveal();
|
||||
else
|
||||
input_init();
|
||||
}
|
||||
input_init();
|
||||
|
||||
if (nstate != STATE_PROMPT)
|
||||
input_hide();
|
||||
term_lns = (term_lns > 0) ? term_lns : 25;
|
||||
term_cls = (term_cls > 0) ? term_cls : 80;
|
||||
|
||||
cstate = nstate;
|
||||
init = 0;
|
||||
}
|
||||
|
||||
|
||||
/*** Output ***/
|
||||
|
||||
void
|
||||
more(void)
|
||||
{
|
||||
more_begin();
|
||||
printf("--More--\015");
|
||||
fflush(stdout);
|
||||
|
||||
redo:
|
||||
switch (getchar())
|
||||
{
|
||||
case 32:
|
||||
case ' ':
|
||||
num_lines = 2;
|
||||
break;
|
||||
case 13:
|
||||
case '\n':
|
||||
case '\r':
|
||||
num_lines--;
|
||||
break;
|
||||
case 'q':
|
||||
@ -349,6 +236,7 @@ more(void)
|
||||
|
||||
printf(" \015");
|
||||
fflush(stdout);
|
||||
more_end();
|
||||
}
|
||||
|
||||
|
||||
@ -361,7 +249,7 @@ server_connect(void)
|
||||
|
||||
server_fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (server_fd < 0)
|
||||
die("Cannot create socket: %m");
|
||||
DIE("Cannot create socket");
|
||||
|
||||
if (strlen(server_path) >= sizeof(sa.sun_path))
|
||||
die("server_connect: path too long");
|
||||
@ -370,11 +258,12 @@ server_connect(void)
|
||||
sa.sun_family = AF_UNIX;
|
||||
strcpy(sa.sun_path, server_path);
|
||||
if (connect(server_fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) < 0)
|
||||
die("Unable to connect to server control socket (%s): %m", server_path);
|
||||
DIE("Unable to connect to server control socket (%s)", server_path);
|
||||
if (fcntl(server_fd, F_SETFL, O_NONBLOCK) < 0)
|
||||
die("fcntl: %m");
|
||||
DIE("fcntl");
|
||||
}
|
||||
|
||||
|
||||
#define PRINTF(LEN, PARGS...) do { if (!skip_input) len = printf(PARGS); } while(0)
|
||||
|
||||
static void
|
||||
@ -383,36 +272,32 @@ server_got_reply(char *x)
|
||||
int code;
|
||||
int len = 0;
|
||||
|
||||
if (*x == '+') /* Async reply */
|
||||
if (*x == '+') /* Async reply */
|
||||
PRINTF(len, ">>> %s\n", x+1);
|
||||
else if (x[0] == ' ') /* Continuation */
|
||||
else if (x[0] == ' ') /* Continuation */
|
||||
PRINTF(len, "%s%s\n", verbose ? " " : "", x+1);
|
||||
else if (strlen(x) > 4 &&
|
||||
sscanf(x, "%d", &code) == 1 && code >= 0 && code < 10000 &&
|
||||
(x[4] == ' ' || x[4] == '-'))
|
||||
sscanf(x, "%d", &code) == 1 && code >= 0 && code < 10000 &&
|
||||
(x[4] == ' ' || x[4] == '-'))
|
||||
{
|
||||
if (code)
|
||||
PRINTF(len, "%s\n", verbose ? x : x+5);
|
||||
PRINTF(len, "%s\n", verbose ? x : x+5);
|
||||
|
||||
if (x[4] == ' ')
|
||||
{
|
||||
nstate = STATE_PROMPT;
|
||||
skip_input = 0;
|
||||
return;
|
||||
busy = 0;
|
||||
skip_input = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
PRINTF(len, "??? <%s>\n", x);
|
||||
|
||||
if (skip_input)
|
||||
return;
|
||||
|
||||
if (interactive && input_initialized && (len > 0))
|
||||
if (interactive && busy && !skip_input && !init && (len > 0))
|
||||
{
|
||||
int lns = LINES ? LINES : 25;
|
||||
int cls = COLS ? COLS : 80;
|
||||
num_lines += (len + cls - 1) / cls; /* Divide and round up */
|
||||
if ((num_lines >= lns) && (cstate == STATE_CMD_SERVER))
|
||||
more();
|
||||
num_lines += (len + term_cls - 1) / term_cls; /* Divide and round up */
|
||||
if (num_lines >= term_lns)
|
||||
more();
|
||||
}
|
||||
}
|
||||
|
||||
@ -425,13 +310,13 @@ server_read(void)
|
||||
redo:
|
||||
c = read(server_fd, server_read_pos, server_read_buf + sizeof(server_read_buf) - server_read_pos);
|
||||
if (!c)
|
||||
die("Connection closed by server.");
|
||||
die("Connection closed by server");
|
||||
if (c < 0)
|
||||
{
|
||||
if (errno == EINTR)
|
||||
goto redo;
|
||||
else
|
||||
die("Server read error: %m");
|
||||
DIE("Server read error");
|
||||
}
|
||||
|
||||
start = server_read_buf;
|
||||
@ -457,19 +342,23 @@ server_read(void)
|
||||
}
|
||||
}
|
||||
|
||||
static fd_set select_fds;
|
||||
|
||||
static void
|
||||
select_loop(void)
|
||||
{
|
||||
int rv;
|
||||
while (1)
|
||||
{
|
||||
if (init && !busy)
|
||||
init_commands();
|
||||
|
||||
if (!init)
|
||||
input_notify(!busy);
|
||||
|
||||
fd_set select_fds;
|
||||
FD_ZERO(&select_fds);
|
||||
|
||||
if (cstate != STATE_CMD_USER)
|
||||
FD_SET(server_fd, &select_fds);
|
||||
if (cstate != STATE_CMD_SERVER)
|
||||
FD_SET(server_fd, &select_fds);
|
||||
if (!busy)
|
||||
FD_SET(0, &select_fds);
|
||||
|
||||
rv = select(server_fd+1, &select_fds, NULL, NULL, NULL);
|
||||
@ -478,19 +367,19 @@ select_loop(void)
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
else
|
||||
die("select: %m");
|
||||
DIE("select");
|
||||
}
|
||||
|
||||
if (FD_ISSET(0, &select_fds))
|
||||
{
|
||||
input_read();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (FD_ISSET(server_fd, &select_fds))
|
||||
{
|
||||
server_read();
|
||||
update_state();
|
||||
}
|
||||
|
||||
if (FD_ISSET(0, &select_fds))
|
||||
{
|
||||
rl_callback_read_char();
|
||||
update_state();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -511,7 +400,7 @@ wait_for_write(int fd)
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
else
|
||||
die("select: %m");
|
||||
DIE("select");
|
||||
}
|
||||
|
||||
if (FD_ISSET(server_fd, &set))
|
||||
@ -538,7 +427,7 @@ server_send(char *cmd)
|
||||
else if (errno == EINTR)
|
||||
continue;
|
||||
else
|
||||
die("Server write error: %m");
|
||||
DIE("Server write error");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -551,11 +440,6 @@ server_send(char *cmd)
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
#ifdef HAVE_LIBDMALLOC
|
||||
if (!getenv("DMALLOC_OPTIONS"))
|
||||
dmalloc_debug(0x2f03d00);
|
||||
#endif
|
||||
|
||||
interactive = isatty(0);
|
||||
parse_args(argc, argv);
|
||||
cmd_build_tree();
|
||||
|
@ -6,15 +6,34 @@
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
/* client.c */
|
||||
|
||||
void cleanup(void);
|
||||
extern int init, busy, interactive;
|
||||
extern int term_lns, term_cls;
|
||||
|
||||
/* birdc.c / birdcl.c */
|
||||
|
||||
void input_start_list(void);
|
||||
void input_stop_list(void);
|
||||
|
||||
void input_init(void);
|
||||
void input_notify(int prompt);
|
||||
void input_read(void);
|
||||
|
||||
void more_begin(void);
|
||||
void more_end(void);
|
||||
|
||||
void cleanup(void);
|
||||
|
||||
/* commands.c */
|
||||
|
||||
void cmd_build_tree(void);
|
||||
void cmd_help(char *cmd, int len);
|
||||
int cmd_complete(char *cmd, int len, char *buf, int again);
|
||||
char *cmd_expand(char *cmd);
|
||||
|
||||
/* client.c */
|
||||
|
||||
void submit_command(char *cmd_raw);
|
||||
|
||||
/* die() with system error messages */
|
||||
#define DIE(x, y...) die(x ": %s", ##y, strerror(errno))
|
||||
|
@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "nest/bird.h"
|
||||
@ -29,15 +30,18 @@ struct cmd_node {
|
||||
struct cmd_node *sibling, *son, **plastson;
|
||||
struct cmd_info *cmd, *help;
|
||||
int len;
|
||||
signed char prio;
|
||||
char token[1];
|
||||
};
|
||||
|
||||
static struct cmd_node cmd_root;
|
||||
|
||||
#define isspace_(X) isspace((unsigned char) (X))
|
||||
|
||||
void
|
||||
cmd_build_tree(void)
|
||||
{
|
||||
unsigned int i;
|
||||
uint i;
|
||||
|
||||
cmd_root.plastson = &cmd_root.son;
|
||||
|
||||
@ -51,7 +55,7 @@ cmd_build_tree(void)
|
||||
while (*c)
|
||||
{
|
||||
char *d = c;
|
||||
while (*c && !isspace(*c))
|
||||
while (*c && !isspace_(*c))
|
||||
c++;
|
||||
for(new=old->son; new; new=new->sibling)
|
||||
if (new->len == c-d && !memcmp(new->token, d, c-d))
|
||||
@ -59,16 +63,17 @@ cmd_build_tree(void)
|
||||
if (!new)
|
||||
{
|
||||
int size = sizeof(struct cmd_node) + c-d;
|
||||
new = xmalloc(size);
|
||||
new = malloc(size);
|
||||
bzero(new, size);
|
||||
*old->plastson = new;
|
||||
old->plastson = &new->sibling;
|
||||
new->plastson = &new->son;
|
||||
new->len = c-d;
|
||||
memcpy(new->token, d, c-d);
|
||||
new->prio = (new->len == 3 && (!memcmp(new->token, "roa", 3) || !memcmp(new->token, "rip", 3))) ? 0 : 1; /* Hack */
|
||||
}
|
||||
old = new;
|
||||
while (isspace(*c))
|
||||
while (isspace_(*c))
|
||||
c++;
|
||||
}
|
||||
if (cmd->is_real_cmd)
|
||||
@ -108,7 +113,10 @@ cmd_find_abbrev(struct cmd_node *root, char *cmd, int len, int *pambiguous)
|
||||
return m;
|
||||
if (m->len > len && !memcmp(m->token, cmd, len))
|
||||
{
|
||||
best2 = best;
|
||||
if (best && best->prio > m->prio)
|
||||
continue;
|
||||
if (best && best->prio == m->prio)
|
||||
best2 = best;
|
||||
best = m;
|
||||
}
|
||||
}
|
||||
@ -126,7 +134,7 @@ cmd_list_ambiguous(struct cmd_node *root, char *cmd, int len)
|
||||
struct cmd_node *m;
|
||||
|
||||
for(m=root->son; m; m=m->sibling)
|
||||
if (m->len > len && !memcmp(m->token, cmd, len))
|
||||
if (m->len > len && !memcmp(m->token, cmd, len))
|
||||
cmd_display_help(m->help, m->cmd);
|
||||
}
|
||||
|
||||
@ -141,13 +149,13 @@ cmd_help(char *cmd, int len)
|
||||
n = &cmd_root;
|
||||
while (cmd < end)
|
||||
{
|
||||
if (isspace(*cmd))
|
||||
if (isspace_(*cmd))
|
||||
{
|
||||
cmd++;
|
||||
continue;
|
||||
}
|
||||
z = cmd;
|
||||
while (cmd < end && !isspace(*cmd))
|
||||
while (cmd < end && !isspace_(*cmd))
|
||||
cmd++;
|
||||
m = cmd_find_abbrev(n, z, cmd-z, &ambig);
|
||||
if (ambig)
|
||||
@ -168,19 +176,31 @@ static int
|
||||
cmd_find_common_match(struct cmd_node *root, char *cmd, int len, int *pcount, char *buf)
|
||||
{
|
||||
struct cmd_node *m;
|
||||
int best, i;
|
||||
int best, best_prio, i;
|
||||
|
||||
*pcount = 0;
|
||||
best = -1;
|
||||
best_prio = -1;
|
||||
for(m=root->son; m; m=m->sibling)
|
||||
{
|
||||
if (m->len < len || memcmp(m->token, cmd, len))
|
||||
continue;
|
||||
|
||||
if (best_prio > m->prio)
|
||||
continue;
|
||||
|
||||
if (best_prio < m->prio)
|
||||
{
|
||||
*pcount = 0;
|
||||
best = -1;
|
||||
}
|
||||
|
||||
(*pcount)++;
|
||||
if (best < 0)
|
||||
{
|
||||
strcpy(buf, m->token + len);
|
||||
best = m->len - len;
|
||||
best_prio = m->prio;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -204,20 +224,20 @@ cmd_complete(char *cmd, int len, char *buf, int again)
|
||||
int ambig, cnt = 0, common;
|
||||
|
||||
/* Find the last word we want to complete */
|
||||
for(fin=end; fin > start && !isspace(fin[-1]); fin--)
|
||||
for(fin=end; fin > start && !isspace_(fin[-1]); fin--)
|
||||
;
|
||||
|
||||
/* Find the context */
|
||||
n = &cmd_root;
|
||||
while (cmd < fin && n->son)
|
||||
{
|
||||
if (isspace(*cmd))
|
||||
if (isspace_(*cmd))
|
||||
{
|
||||
cmd++;
|
||||
continue;
|
||||
}
|
||||
z = cmd;
|
||||
while (cmd < fin && !isspace(*cmd))
|
||||
while (cmd < fin && !isspace_(*cmd))
|
||||
cmd++;
|
||||
m = cmd_find_abbrev(n, z, cmd-z, &ambig);
|
||||
if (ambig)
|
||||
@ -272,13 +292,13 @@ cmd_expand(char *cmd)
|
||||
n = &cmd_root;
|
||||
while (*c)
|
||||
{
|
||||
if (isspace(*c))
|
||||
if (isspace_(*c))
|
||||
{
|
||||
c++;
|
||||
continue;
|
||||
}
|
||||
b = c;
|
||||
while (*c && !isspace(*c))
|
||||
while (*c && !isspace_(*c))
|
||||
c++;
|
||||
m = cmd_find_abbrev(n, b, c-b, &ambig);
|
||||
if (!m)
|
||||
@ -297,7 +317,7 @@ cmd_expand(char *cmd)
|
||||
puts("No such command. Press `?' for help.");
|
||||
return NULL;
|
||||
}
|
||||
b = xmalloc(strlen(n->cmd->command) + strlen(args) + 1);
|
||||
b = malloc(strlen(n->cmd->command) + strlen(args) + 1);
|
||||
sprintf(b, "%s%s", n->cmd->command, args);
|
||||
return b;
|
||||
}
|
||||
|
@ -17,18 +17,21 @@
|
||||
/* Client versions of logging functions */
|
||||
|
||||
static void
|
||||
vlog(char *msg, va_list args)
|
||||
vlog(const char *msg, va_list args)
|
||||
{
|
||||
char buf[1024];
|
||||
|
||||
if (bvsnprintf(buf, sizeof(buf)-1, msg, args) < 0)
|
||||
bsprintf(buf + sizeof(buf) - 100, " ... <too long>");
|
||||
int n = vsnprintf(buf, sizeof(buf), msg, args);
|
||||
if (n < 0)
|
||||
snprintf(buf, sizeof(buf), "???");
|
||||
else if (n >= (int) sizeof(buf))
|
||||
snprintf(buf + sizeof(buf) - 100, 100, " ... <too long>");
|
||||
fputs(buf, stderr);
|
||||
fputc('\n', stderr);
|
||||
}
|
||||
|
||||
void
|
||||
bug(char *msg, ...)
|
||||
bug(const char *msg, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
@ -37,16 +40,18 @@ bug(char *msg, ...)
|
||||
fputs("Internal error: ", stderr);
|
||||
vlog(msg, args);
|
||||
vfprintf(stderr, msg, args);
|
||||
va_end(args);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void
|
||||
die(char *msg, ...)
|
||||
die(const char *msg, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, msg);
|
||||
cleanup();
|
||||
vlog(msg, args);
|
||||
va_end(args);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -1,31 +1,34 @@
|
||||
source=cf-parse.tab.c cf-lex.c conf.c
|
||||
root-rel=../
|
||||
src := cf-parse.tab.c cf-lex.c conf.c
|
||||
obj := $(src-o-files)
|
||||
|
||||
include ../Rules
|
||||
$(all-daemon)
|
||||
|
||||
conf-src=$(srcdir)/conf
|
||||
conf-fragments=$(conf-src)/confbase.Y @CONFS@ $(addsuffix /config.Y,$(static-dir-paths))
|
||||
tests_objs := $(tests_objs) $(src-o-files)
|
||||
|
||||
ifdef DEBUG
|
||||
BISON_DEBUG=-t
|
||||
#FLEX_DEBUG=-d
|
||||
endif
|
||||
|
||||
cf-parse.tab.h: cf-parse.tab.c
|
||||
$(o)cf-parse.y: $(s)gen_parser.m4
|
||||
$(o)keywords.h: $(s)gen_keywords.m4
|
||||
$(o)commands.h: $(s)gen_commands.m4
|
||||
|
||||
cf-parse.tab.c: cf-parse.y
|
||||
$(BISON) -bcf-parse -dv -pcf_ $(BISON_DEBUG) cf-parse.y
|
||||
$(conf-y-targets): $(s)confbase.Y $(s)flowspec.Y
|
||||
$(M4) $(M4FLAGS) -P $(if $(word 2,$(filter %.m4,$^)),$(error "Too many M4 scripts for one target"),$(filter %.m4,$^)) $(filter %.Y,$^) >$@
|
||||
|
||||
cf-parse.y: $(conf-fragments) $(conf-src)/gen_parser.m4
|
||||
$(M4) -P $(conf-src)/gen_parser.m4 $(conf-fragments) >cf-parse.y
|
||||
$(o)cf-parse.tab.h: $(o)cf-parse.tab.c
|
||||
|
||||
keywords.h: $(conf-fragments) $(conf-src)/gen_keywords.m4
|
||||
$(M4) -P $(conf-src)/gen_keywords.m4 $(conf-fragments) >keywords.h
|
||||
$(o)cf-parse.tab.c: $(o)cf-parse.y
|
||||
$(BISON) $(BISON_DEBUG) $(BISONFLAGS) -dv -pcf_ -b $(@:.tab.c=) $<
|
||||
|
||||
commands.h: $(conf-fragments) $(conf-src)/gen_commands.m4 $(srcdir)/client/cmds.m4
|
||||
$(M4) -P $(conf-src)/gen_commands.m4 $(srcdir)/client/cmds.m4 $(conf-fragments) | sort >commands.h
|
||||
$(o)cf-lex.c: $(s)cf-lex.l
|
||||
$(FLEX) $(FLEX_DEBUG) -f -s -B -8 -Pcf_ -o$@ $<
|
||||
|
||||
cf-lex.c: cf-lex.l
|
||||
$(FLEX) $(FLEX_DEBUG) -s -B -8 -ocf-lex.c -Pcf_ cf-lex.l
|
||||
$(o)cf-lex.o: CFLAGS+=-Wno-sign-compare -Wno-unused-function
|
||||
|
||||
depend: keywords.h commands.h cf-parse.tab.c cf-lex.c
|
||||
prepare: $(o)keywords.h $(o)commands.h $(o)cf-parse.tab.h
|
||||
|
||||
$(addprefix $(o), cf-parse.y keywords.h commands.h cf-parse.tab.h cf-parse.tab.c cf-lex.c): $(objdir)/.dir-stamp
|
||||
|
||||
$(call clean,cf-parse.tab.h cf-parse.tab.c cf-parse.y keywords.h commands.h cf-lex.c cf-parse.output)
|
||||
|
731
conf/cf-lex.l
731
conf/cf-lex.l
@ -15,10 +15,10 @@
|
||||
* symbols and keywords.
|
||||
*
|
||||
* Each symbol is represented by a &symbol structure containing name
|
||||
* of the symbol, its lexical scope, symbol class (%SYM_PROTO for a name of a protocol,
|
||||
* %SYM_NUMBER for a numeric constant etc.) and class dependent data.
|
||||
* When an unknown symbol is encountered, it's automatically added to the
|
||||
* symbol table with class %SYM_VOID.
|
||||
* of the symbol, its lexical scope, symbol class (%SYM_PROTO for a
|
||||
* name of a protocol, %SYM_CONSTANT for a constant etc.) and class
|
||||
* dependent data. When an unknown symbol is encountered, it's
|
||||
* automatically added to the symbol table with class %SYM_VOID.
|
||||
*
|
||||
* The keyword tables are generated from the grammar templates
|
||||
* using the |gen_keywords.m4| script.
|
||||
@ -30,6 +30,14 @@
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <libgen.h>
|
||||
#include <glob.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define PARSER 1
|
||||
|
||||
@ -37,9 +45,11 @@
|
||||
#include "nest/route.h"
|
||||
#include "nest/protocol.h"
|
||||
#include "filter/filter.h"
|
||||
#include "filter/f-inst.h"
|
||||
#include "conf/conf.h"
|
||||
#include "conf/cf-parse.tab.h"
|
||||
#include "lib/string.h"
|
||||
#include "lib/hash.h"
|
||||
|
||||
struct keyword {
|
||||
byte *name;
|
||||
@ -49,41 +59,63 @@ struct keyword {
|
||||
|
||||
#include "conf/keywords.h"
|
||||
|
||||
#define KW_HASH_SIZE 64
|
||||
static struct keyword *kw_hash[KW_HASH_SIZE];
|
||||
static int kw_hash_inited;
|
||||
/* Could be defined by Bison in cf-parse.tab.h, inteferes with SYM hash */
|
||||
#ifdef SYM
|
||||
#undef SYM
|
||||
#endif
|
||||
|
||||
#define SYM_HASH_SIZE 128
|
||||
#define SYM_MAX_LEN 32
|
||||
|
||||
struct sym_scope {
|
||||
struct sym_scope *next; /* Next on scope stack */
|
||||
struct symbol *name; /* Name of this scope */
|
||||
int active; /* Currently entered */
|
||||
};
|
||||
static struct sym_scope *conf_this_scope;
|
||||
static uint cf_hash(const byte *c);
|
||||
|
||||
#define MAX_INCLUDE_DEPTH 5
|
||||
#define KW_KEY(n) n->name
|
||||
#define KW_NEXT(n) n->next
|
||||
#define KW_EQ(a,b) !strcmp(a,b)
|
||||
#define KW_FN(k) cf_hash(k)
|
||||
#define KW_ORDER 8 /* Fixed */
|
||||
|
||||
static struct include_file_stack *ifs_head;
|
||||
static int ifs_depth;
|
||||
#define SYM_KEY(n) n->name, n->scope->active
|
||||
#define SYM_NEXT(n) n->next
|
||||
#define SYM_EQ(a,s1,b,s2) !strcmp(a,b) && s1 == s2
|
||||
#define SYM_FN(k,s) cf_hash(k)
|
||||
#define SYM_ORDER 6 /* Initial */
|
||||
|
||||
static int cf_hash(byte *c);
|
||||
static struct symbol *cf_find_sym(byte *c, unsigned int h0);
|
||||
#define SYM_REHASH sym_rehash
|
||||
#define SYM_PARAMS /8, *1, 2, 2, 6, 20
|
||||
|
||||
|
||||
HASH_DEFINE_REHASH_FN(SYM, struct symbol)
|
||||
|
||||
HASH(struct keyword) kw_hash;
|
||||
|
||||
|
||||
struct sym_scope *conf_this_scope;
|
||||
|
||||
linpool *cfg_mem;
|
||||
|
||||
int (*cf_read_hook)(byte *buf, unsigned int max, int fd);
|
||||
int (*cf_open_hook)(char *filename);
|
||||
struct include_file_stack *ifs;
|
||||
static struct include_file_stack *ifs_head;
|
||||
|
||||
#define YY_INPUT(buf,result,max) result = cf_read_hook(buf, max, ifs->conf_fd);
|
||||
#define QUOTED_BUFFER_SIZE 4096
|
||||
static BUFFER_(char) quoted_buffer;
|
||||
static char quoted_buffer_data[QUOTED_BUFFER_SIZE];
|
||||
static inline void quoted_buffer_init(void) {
|
||||
quoted_buffer.used = 0;
|
||||
quoted_buffer.size = QUOTED_BUFFER_SIZE;
|
||||
quoted_buffer.data = quoted_buffer_data;
|
||||
}
|
||||
|
||||
#define MAX_INCLUDE_DEPTH 8
|
||||
|
||||
#define YY_INPUT(buf,result,max) result = cf_read_hook(buf, max, ifs->fd);
|
||||
#define YY_NO_UNPUT
|
||||
#define YY_FATAL_ERROR(msg) cf_error(msg)
|
||||
#define YY_USER_ACTION ifs->chno += yyleng; ifs->toklen = yyleng;
|
||||
|
||||
static void new_include(void);
|
||||
static void cf_include(char *arg, int alen);
|
||||
static int check_eof(void);
|
||||
static struct include_file_stack *new_stack(struct include_file_stack *old);
|
||||
|
||||
static enum yytokentype cf_lex_symbol(const char *data);
|
||||
|
||||
%}
|
||||
|
||||
@ -92,46 +124,149 @@ static struct include_file_stack *new_stack(struct include_file_stack *old);
|
||||
%option nounput
|
||||
%option noreject
|
||||
|
||||
%x COMMENT CCOMM CLI
|
||||
%x COMMENT CCOMM CLI QUOTED APOSTROPHED INCLUDE
|
||||
|
||||
ALPHA [a-zA-Z_]
|
||||
DIGIT [0-9]
|
||||
XIGIT [0-9a-fA-F]
|
||||
ALNUM [a-zA-Z_0-9]
|
||||
WHITE [ \t]
|
||||
include ^{WHITE}*include{WHITE}*\".*\"{WHITE}*;
|
||||
|
||||
%%
|
||||
{include} { if(cf_open_hook) new_include(); }
|
||||
^{WHITE}*include{WHITE}*\" {
|
||||
if (!ifs->depth)
|
||||
cf_error("Include not allowed in CLI");
|
||||
|
||||
BEGIN(INCLUDE);
|
||||
}
|
||||
|
||||
<INCLUDE>[^"\n]+["]{WHITE}*; {
|
||||
char *start, *end;
|
||||
|
||||
start = yytext;
|
||||
|
||||
end = strchr(start, '"');
|
||||
*end = 0;
|
||||
|
||||
if (start == end)
|
||||
cf_error("Include with empty argument");
|
||||
|
||||
cf_include(start, end-start);
|
||||
|
||||
BEGIN(INITIAL);
|
||||
}
|
||||
|
||||
<INCLUDE>["] cf_error("Include with empty argument");
|
||||
<INCLUDE>. cf_error("Unterminated include");
|
||||
<INCLUDE>\n cf_error("Unterminated include");
|
||||
<INCLUDE><<EOF>> cf_error("Unterminated include");
|
||||
|
||||
|
||||
{DIGIT}+:{DIGIT}+ {
|
||||
uint len1 UNUSED, len2;
|
||||
u64 l;
|
||||
char *e;
|
||||
|
||||
errno = 0;
|
||||
l = bstrtoul10(yytext, &e);
|
||||
if (!e || (*e != ':') || (errno == ERANGE) || (l >> 32))
|
||||
cf_error("ASN out of range");
|
||||
|
||||
if (l >> 16)
|
||||
{
|
||||
len1 = 32;
|
||||
len2 = 16;
|
||||
cf_lval.i64 = (2ULL << 48) | (((u64) l) << len2);
|
||||
}
|
||||
else
|
||||
{
|
||||
len1 = 16;
|
||||
len2 = 32;
|
||||
cf_lval.i64 = 0 | (((u64) l) << len2);
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
l = bstrtoul10(e+1, &e);
|
||||
if (!e || *e || (errno == ERANGE) || (l >> len2))
|
||||
cf_error("Number out of range");
|
||||
cf_lval.i64 |= l;
|
||||
|
||||
return VPN_RD;
|
||||
}
|
||||
|
||||
[02]:{DIGIT}+:{DIGIT}+ {
|
||||
uint len1, len2;
|
||||
u64 l;
|
||||
char *e;
|
||||
|
||||
if (yytext[0] == '0')
|
||||
{
|
||||
cf_lval.i64 = 0;
|
||||
len1 = 16;
|
||||
len2 = 32;
|
||||
}
|
||||
else
|
||||
{
|
||||
cf_lval.i64 = 2ULL << 48;
|
||||
len1 = 32;
|
||||
len2 = 16;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
l = bstrtoul10(yytext+2, &e);
|
||||
if (!e || (*e != ':') || (errno == ERANGE) || (l >> len1))
|
||||
cf_error("ASN out of range");
|
||||
cf_lval.i64 |= ((u64) l) << len2;
|
||||
|
||||
errno = 0;
|
||||
l = bstrtoul10(e+1, &e);
|
||||
if (!e || *e || (errno == ERANGE) || (l >> len2))
|
||||
cf_error("Number out of range");
|
||||
cf_lval.i64 |= l;
|
||||
|
||||
return VPN_RD;
|
||||
}
|
||||
|
||||
{DIGIT}+\.{DIGIT}+\.{DIGIT}+\.{DIGIT}+:{DIGIT}+ {
|
||||
unsigned long int l;
|
||||
ip4_addr ip4;
|
||||
char *e;
|
||||
|
||||
cf_lval.i64 = 1ULL << 48;
|
||||
|
||||
e = strchr(yytext, ':');
|
||||
*e++ = '\0';
|
||||
if (!ip4_pton(yytext, &ip4))
|
||||
cf_error("Invalid IPv4 address %s in Route Distinguisher", yytext);
|
||||
cf_lval.i64 |= ((u64) ip4_to_u32(ip4)) << 16;
|
||||
|
||||
errno = 0;
|
||||
l = bstrtoul10(e, &e);
|
||||
if (!e || *e || (errno == ERANGE) || (l >> 16))
|
||||
cf_error("Number out of range");
|
||||
cf_lval.i64 |= l;
|
||||
|
||||
return VPN_RD;
|
||||
}
|
||||
|
||||
{DIGIT}+\.{DIGIT}+\.{DIGIT}+\.{DIGIT}+ {
|
||||
#ifdef IPV6
|
||||
if (ipv4_pton_u32(yytext, &cf_lval.i32))
|
||||
return RTRID;
|
||||
cf_error("Invalid IPv4 address %s", yytext);
|
||||
#else
|
||||
if (ip_pton(yytext, &cf_lval.a))
|
||||
return IPA;
|
||||
cf_error("Invalid IP address %s", yytext);
|
||||
#endif
|
||||
if (!ip4_pton(yytext, &cf_lval.ip4))
|
||||
cf_error("Invalid IPv4 address %s", yytext);
|
||||
return IP4;
|
||||
}
|
||||
|
||||
({XIGIT}*::|({XIGIT}*:){3,})({XIGIT}*|{DIGIT}+\.{DIGIT}+\.{DIGIT}+\.{DIGIT}+) {
|
||||
#ifdef IPV6
|
||||
if (ip_pton(yytext, &cf_lval.a))
|
||||
return IPA;
|
||||
cf_error("Invalid IP address %s", yytext);
|
||||
#else
|
||||
cf_error("This is an IPv4 router, therefore IPv6 addresses are not supported");
|
||||
#endif
|
||||
if (!ip6_pton(yytext, &cf_lval.ip6))
|
||||
cf_error("Invalid IPv6 address %s", yytext);
|
||||
return IP6;
|
||||
}
|
||||
|
||||
0x{XIGIT}+ {
|
||||
char *e;
|
||||
long int l;
|
||||
unsigned long int l;
|
||||
errno = 0;
|
||||
l = strtoul(yytext+2, &e, 16);
|
||||
if (e && *e || errno == ERANGE || (long int)(int) l != l)
|
||||
l = bstrtoul16(yytext+2, &e);
|
||||
if (!e || *e || errno == ERANGE || (unsigned long int)(unsigned int) l != l)
|
||||
cf_error("Number out of range");
|
||||
cf_lval.i = l;
|
||||
return NUM;
|
||||
@ -139,10 +274,10 @@ include ^{WHITE}*include{WHITE}*\".*\"{WHITE}*;
|
||||
|
||||
{DIGIT}+ {
|
||||
char *e;
|
||||
long int l;
|
||||
unsigned long int l;
|
||||
errno = 0;
|
||||
l = strtoul(yytext, &e, 10);
|
||||
if (e && *e || errno == ERANGE || (long int)(int) l != l)
|
||||
l = bstrtoul10(yytext, &e);
|
||||
if (!e || *e || errno == ERANGE || (unsigned long int)(unsigned int) l != l)
|
||||
cf_error("Number out of range");
|
||||
cf_lval.i = l;
|
||||
return NUM;
|
||||
@ -153,29 +288,23 @@ else: {
|
||||
return ELSECOL;
|
||||
}
|
||||
|
||||
({ALPHA}{ALNUM}*|[']({ALNUM}|[-])*[']) {
|
||||
if(*yytext == '\'') {
|
||||
yytext[yyleng-1] = 0;
|
||||
yytext++;
|
||||
}
|
||||
unsigned int h = cf_hash(yytext);
|
||||
struct keyword *k = kw_hash[h & (KW_HASH_SIZE-1)];
|
||||
while (k)
|
||||
{
|
||||
if (!strcmp(k->name, yytext))
|
||||
{
|
||||
if (k->value > 0)
|
||||
return k->value;
|
||||
else
|
||||
{
|
||||
cf_lval.i = -k->value;
|
||||
return ENUM;
|
||||
}
|
||||
}
|
||||
k=k->next;
|
||||
}
|
||||
cf_lval.s = cf_find_sym(yytext, h);
|
||||
return SYM;
|
||||
['] {
|
||||
BEGIN(APOSTROPHED);
|
||||
quoted_buffer_init();
|
||||
}
|
||||
|
||||
<APOSTROPHED>{ALNUM}|[-]|[.:] BUFFER_PUSH(quoted_buffer) = yytext[0];
|
||||
<APOSTROPHED>\n cf_error("Unterminated symbol");
|
||||
<APOSTROPHED><<EOF>> cf_error("Unterminated symbol");
|
||||
<APOSTROPHED>['] {
|
||||
BEGIN(INITIAL);
|
||||
BUFFER_PUSH(quoted_buffer) = 0;
|
||||
return cf_lex_symbol(quoted_buffer_data);
|
||||
}
|
||||
<APOSTROPHED>. cf_error("Invalid character in apostrophed symbol");
|
||||
|
||||
({ALPHA}{ALNUM}*) {
|
||||
return cf_lex_symbol(yytext);
|
||||
}
|
||||
|
||||
<CLI>(.|\n) {
|
||||
@ -191,19 +320,27 @@ else: {
|
||||
return yytext[0];
|
||||
}
|
||||
|
||||
["][^"\n]*["] {
|
||||
yytext[yyleng-1] = 0;
|
||||
cf_lval.t = cfg_strdup(yytext+1);
|
||||
["] {
|
||||
BEGIN(QUOTED);
|
||||
quoted_buffer_init();
|
||||
}
|
||||
|
||||
<QUOTED>\n cf_error("Unterminated string");
|
||||
<QUOTED><<EOF>> cf_error("Unterminated string");
|
||||
<QUOTED>["] {
|
||||
BEGIN(INITIAL);
|
||||
BUFFER_PUSH(quoted_buffer) = 0;
|
||||
cf_lval.t = cfg_strdup(quoted_buffer_data);
|
||||
return TEXT;
|
||||
}
|
||||
|
||||
["][^"\n]*\n cf_error("Unterminated string");
|
||||
<QUOTED>. BUFFER_PUSH(quoted_buffer) = yytext[0];
|
||||
|
||||
<INITIAL,COMMENT><<EOF>> { if(check_eof()) return END; }
|
||||
<INITIAL,COMMENT><<EOF>> { if (check_eof()) return END; }
|
||||
|
||||
{WHITE}+
|
||||
|
||||
\n ifs->conf_lino++;
|
||||
\n ifs->lino++; ifs->chno = 0;
|
||||
|
||||
# BEGIN(COMMENT);
|
||||
|
||||
@ -212,19 +349,21 @@ else: {
|
||||
. cf_error("Unknown character");
|
||||
|
||||
<COMMENT>\n {
|
||||
ifs->conf_lino++;
|
||||
ifs->lino++;
|
||||
ifs->chno = 0;
|
||||
BEGIN(INITIAL);
|
||||
}
|
||||
|
||||
<COMMENT>.
|
||||
|
||||
<CCOMM>\*\/ BEGIN(INITIAL);
|
||||
<CCOMM>\n ifs->conf_lino++;
|
||||
<CCOMM>\n ifs->lino++; ifs->chno = 0;
|
||||
<CCOMM>\/\* cf_error("Comment nesting not supported");
|
||||
<CCOMM><<EOF>> cf_error("Unterminated comment");
|
||||
<CCOMM>.
|
||||
|
||||
\!\= return NEQ;
|
||||
\!\~ return NMA;
|
||||
\<\= return LEQ;
|
||||
\>\= return GEQ;
|
||||
\&\& return AND;
|
||||
@ -235,134 +374,275 @@ else: {
|
||||
|
||||
%%
|
||||
|
||||
static int
|
||||
cf_hash(byte *c)
|
||||
static uint
|
||||
cf_hash(const byte *c)
|
||||
{
|
||||
unsigned int h = 13;
|
||||
uint h = 13 << 24;
|
||||
|
||||
while (*c)
|
||||
h = (h * 37) + *c++;
|
||||
h = h + (h >> 2) + (h >> 5) + ((uint) *c++ << 24);
|
||||
return h;
|
||||
}
|
||||
|
||||
/* Open included file with properly swapped buffers */
|
||||
static void
|
||||
new_include(void)
|
||||
/*
|
||||
* IFS stack - it contains structures needed for recursive processing
|
||||
* of include in config files. On the top of the stack is a structure
|
||||
* for currently processed file. Other structures are either for
|
||||
* active files interrupted because of include directive (these have
|
||||
* fd and flex buffer) or for inactive files scheduled to be processed
|
||||
* later (when parent requested including of several files by wildcard
|
||||
* match - these do not have fd and flex buffer yet).
|
||||
*
|
||||
* FIXME: Most of these ifs and include functions are really sysdep/unix.
|
||||
*/
|
||||
|
||||
static struct include_file_stack *
|
||||
push_ifs(struct include_file_stack *old)
|
||||
{
|
||||
char *fname, *p = NULL;
|
||||
struct include_file_stack *ret;
|
||||
ret = cfg_allocz(sizeof(struct include_file_stack));
|
||||
ret->lino = 1;
|
||||
ret->prev = old;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((fname = strchr(yytext, '"')) != NULL) {
|
||||
static struct include_file_stack *
|
||||
pop_ifs(struct include_file_stack *old)
|
||||
{
|
||||
yy_delete_buffer(old->buffer);
|
||||
close(old->fd);
|
||||
return old->prev;
|
||||
}
|
||||
|
||||
if ((p = strchr(++fname, '"')) != NULL) *p = '\0';
|
||||
static void
|
||||
enter_ifs(struct include_file_stack *new)
|
||||
{
|
||||
if (!new->buffer)
|
||||
{
|
||||
new->fd = open(new->file_name, O_RDONLY);
|
||||
if (new->fd < 0)
|
||||
{
|
||||
ifs = ifs->up;
|
||||
cf_error("Unable to open included file %s: %m", new->file_name);
|
||||
}
|
||||
|
||||
if (ifs_depth >= MAX_INCLUDE_DEPTH)
|
||||
cf_error("Max include depth reached.");
|
||||
new->buffer = yy_create_buffer(NULL, YY_BUF_SIZE);
|
||||
}
|
||||
|
||||
/* Save current stack */
|
||||
ifs->stack = YY_CURRENT_BUFFER;
|
||||
/* Prepare new stack */
|
||||
ifs->next = new_stack(ifs);
|
||||
ifs = ifs->next;
|
||||
strcpy(ifs->conf_fname, fname); /* XXX: strlcpy should be here */
|
||||
ifs->conf_fd = cf_open_hook(fname);
|
||||
yy_switch_to_buffer(new->buffer);
|
||||
}
|
||||
|
||||
yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
|
||||
}
|
||||
/**
|
||||
* cf_lex_unwind - unwind lexer state during error
|
||||
*
|
||||
* cf_lex_unwind() frees the internal state on IFS stack when the lexical
|
||||
* analyzer is terminated by cf_error().
|
||||
*/
|
||||
void
|
||||
cf_lex_unwind(void)
|
||||
{
|
||||
struct include_file_stack *n;
|
||||
|
||||
for (n = ifs; n != ifs_head; n = n->prev)
|
||||
{
|
||||
/* Memory is freed automatically */
|
||||
if (n->buffer)
|
||||
yy_delete_buffer(n->buffer);
|
||||
if (n->fd)
|
||||
close(n->fd);
|
||||
}
|
||||
|
||||
ifs = ifs_head;
|
||||
}
|
||||
|
||||
static void
|
||||
cf_include(char *arg, int alen)
|
||||
{
|
||||
struct include_file_stack *base_ifs = ifs;
|
||||
int new_depth, rv, i;
|
||||
char *patt;
|
||||
glob_t g = {};
|
||||
|
||||
new_depth = ifs->depth + 1;
|
||||
if (new_depth > MAX_INCLUDE_DEPTH)
|
||||
cf_error("Max include depth reached");
|
||||
|
||||
/* expand arg to properly handle relative filenames */
|
||||
if (*arg != '/')
|
||||
{
|
||||
int dlen = strlen(ifs->file_name);
|
||||
char *dir = alloca(dlen + 1);
|
||||
patt = alloca(dlen + alen + 2);
|
||||
memcpy(dir, ifs->file_name, dlen + 1);
|
||||
sprintf(patt, "%s/%s", dirname(dir), arg);
|
||||
}
|
||||
else
|
||||
patt = arg;
|
||||
|
||||
/* Skip globbing if there are no wildcards, mainly to get proper
|
||||
response when the included config file is missing */
|
||||
if (!strpbrk(arg, "?*["))
|
||||
{
|
||||
ifs = push_ifs(ifs);
|
||||
ifs->file_name = cfg_strdup(patt);
|
||||
ifs->depth = new_depth;
|
||||
ifs->up = base_ifs;
|
||||
enter_ifs(ifs);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Expand the pattern */
|
||||
rv = glob(patt, GLOB_ERR | GLOB_NOESCAPE, NULL, &g);
|
||||
if (rv == GLOB_ABORTED)
|
||||
cf_error("Unable to match pattern %s: %m", patt);
|
||||
if ((rv != 0) || (g.gl_pathc <= 0))
|
||||
return;
|
||||
|
||||
/*
|
||||
* Now we put all found files to ifs stack in reverse order, they
|
||||
* will be activated and processed in order as ifs stack is popped
|
||||
* by pop_ifs() and enter_ifs() in check_eof().
|
||||
*/
|
||||
for(i = g.gl_pathc - 1; i >= 0; i--)
|
||||
{
|
||||
char *fname = g.gl_pathv[i];
|
||||
struct stat fs;
|
||||
|
||||
if (stat(fname, &fs) < 0)
|
||||
{
|
||||
globfree(&g);
|
||||
cf_error("Unable to stat included file %s: %m", fname);
|
||||
}
|
||||
|
||||
if (fs.st_mode & S_IFDIR)
|
||||
continue;
|
||||
|
||||
/* Prepare new stack item */
|
||||
ifs = push_ifs(ifs);
|
||||
ifs->file_name = cfg_strdup(fname);
|
||||
ifs->depth = new_depth;
|
||||
ifs->up = base_ifs;
|
||||
}
|
||||
|
||||
globfree(&g);
|
||||
enter_ifs(ifs);
|
||||
}
|
||||
|
||||
static int
|
||||
check_eof(void)
|
||||
{
|
||||
if (ifs == ifs_head) {
|
||||
/* EOF in main config file */
|
||||
ifs->conf_lino = 1;
|
||||
return 1;
|
||||
}
|
||||
if (ifs == ifs_head)
|
||||
{
|
||||
/* EOF in main config file */
|
||||
ifs->lino = 1; /* Why this? */
|
||||
return 1;
|
||||
}
|
||||
|
||||
ifs_depth--;
|
||||
close(ifs->conf_fd);
|
||||
ifs = ifs->prev;
|
||||
ifs->next = NULL;
|
||||
|
||||
yy_delete_buffer(YY_CURRENT_BUFFER);
|
||||
yy_switch_to_buffer(ifs->stack);
|
||||
return 0;
|
||||
ifs = pop_ifs(ifs);
|
||||
enter_ifs(ifs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct symbol *
|
||||
cf_new_sym(byte *c, unsigned int h)
|
||||
cf_new_symbol(const byte *c)
|
||||
{
|
||||
struct symbol *s, **ht;
|
||||
int l;
|
||||
struct symbol *s;
|
||||
|
||||
if (!new_config->sym_hash)
|
||||
new_config->sym_hash = cfg_allocz(SYM_HASH_SIZE * sizeof(struct keyword *));
|
||||
ht = new_config->sym_hash;
|
||||
l = strlen(c);
|
||||
uint l = strlen(c);
|
||||
if (l > SYM_MAX_LEN)
|
||||
cf_error("Symbol too long");
|
||||
s = cfg_alloc(sizeof(struct symbol) + l);
|
||||
s->next = ht[h];
|
||||
ht[h] = s;
|
||||
s->scope = conf_this_scope;
|
||||
s->class = SYM_VOID;
|
||||
s->def = NULL;
|
||||
s->aux = 0;
|
||||
|
||||
s = cfg_allocz(sizeof(struct symbol) + l + 1);
|
||||
*s = (struct symbol) { .scope = conf_this_scope, .class = SYM_VOID, };
|
||||
strcpy(s->name, c);
|
||||
|
||||
if (!new_config->sym_hash.data)
|
||||
HASH_INIT(new_config->sym_hash, new_config->pool, SYM_ORDER);
|
||||
|
||||
HASH_INSERT2(new_config->sym_hash, SYM, new_config->pool, s);
|
||||
|
||||
add_tail(&(new_config->symbols), &(s->n));
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
static struct symbol *
|
||||
cf_find_sym(byte *c, unsigned int h0)
|
||||
{
|
||||
unsigned int h = h0 & (SYM_HASH_SIZE-1);
|
||||
struct symbol *s, **ht;
|
||||
|
||||
if (ht = new_config->sym_hash)
|
||||
{
|
||||
for(s = ht[h]; s; s=s->next)
|
||||
if (!strcmp(s->name, c) && s->scope->active)
|
||||
return s;
|
||||
}
|
||||
if (new_config->sym_fallback)
|
||||
{
|
||||
/* We know only top-level scope is active */
|
||||
for(s = new_config->sym_fallback[h]; s; s=s->next)
|
||||
if (!strcmp(s->name, c) && s->scope->active)
|
||||
return s;
|
||||
}
|
||||
return cf_new_sym(c, h);
|
||||
}
|
||||
|
||||
/**
|
||||
* cf_find_symbol - find a symbol by name
|
||||
* @cfg: specificed config
|
||||
* @c: symbol name
|
||||
*
|
||||
* This functions searches the symbol table for a symbol of given
|
||||
* name. First it examines the current scope, then the second recent
|
||||
* one and so on until it either finds the symbol and returns a pointer
|
||||
* to its &symbol structure or reaches the end of the scope chain
|
||||
* and returns %NULL to signify no match.
|
||||
* This functions searches the symbol table in the config @cfg for a symbol of
|
||||
* given name. First it examines the current scope, then the second recent one
|
||||
* and so on until it either finds the symbol and returns a pointer to its
|
||||
* &symbol structure or reaches the end of the scope chain and returns %NULL to
|
||||
* signify no match.
|
||||
*/
|
||||
struct symbol *
|
||||
cf_find_symbol(byte *c)
|
||||
cf_find_symbol(const struct config *cfg, const byte *c)
|
||||
{
|
||||
return cf_find_sym(c, cf_hash(c));
|
||||
struct symbol *s;
|
||||
|
||||
if (cfg->sym_hash.data &&
|
||||
(s = HASH_FIND(cfg->sym_hash, SYM, c, 1)))
|
||||
return s;
|
||||
|
||||
/* In CLI command parsing, fallback points to the current config, otherwise it is NULL. */
|
||||
if (cfg->fallback &&
|
||||
cfg->fallback->sym_hash.data &&
|
||||
(s = HASH_FIND(cfg->fallback->sym_hash, SYM, c, 1)))
|
||||
return s;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* cf_get_symbol - get a symbol by name
|
||||
* @c: symbol name
|
||||
*
|
||||
* This functions searches the symbol table of the currently parsed config
|
||||
* (@new_config) for a symbol of given name. It returns either the already
|
||||
* existing symbol or a newly allocated undefined (%SYM_VOID) symbol if no
|
||||
* existing symbol is found.
|
||||
*/
|
||||
struct symbol *
|
||||
cf_get_symbol(const byte *c)
|
||||
{
|
||||
return cf_find_symbol(new_config, c) ?: cf_new_symbol(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* cf_localize_symbol - get the local instance of given symbol
|
||||
* @sym: the symbol to localize
|
||||
*
|
||||
* This functions finds the symbol that is local to current scope
|
||||
* for purposes of cf_define_symbol().
|
||||
*/
|
||||
struct symbol *
|
||||
cf_localize_symbol(struct symbol *sym)
|
||||
{
|
||||
/* If the symbol type is void, it has been recently allocated just in this scope. */
|
||||
if (!sym->class)
|
||||
return sym;
|
||||
|
||||
/* If the scope is the current, it is already defined in this scope. */
|
||||
if (sym->scope == conf_this_scope)
|
||||
cf_error("Symbol already defined");
|
||||
|
||||
/* Not allocated here yet, doing it now. */
|
||||
return cf_new_symbol(sym->name);
|
||||
}
|
||||
|
||||
struct symbol *
|
||||
cf_default_name(char *template, int *counter)
|
||||
{
|
||||
char buf[32];
|
||||
char buf[SYM_MAX_LEN];
|
||||
struct symbol *s;
|
||||
char *perc = strchr(template, '%');
|
||||
|
||||
for(;;)
|
||||
{
|
||||
bsprintf(buf, template, ++(*counter));
|
||||
s = cf_find_sym(buf, cf_hash(buf));
|
||||
if (!s)
|
||||
break;
|
||||
s = cf_get_symbol(buf);
|
||||
if (s->class == SYM_VOID)
|
||||
return s;
|
||||
if (!perc)
|
||||
@ -371,62 +651,48 @@ cf_default_name(char *template, int *counter)
|
||||
cf_error("Unable to generate default name");
|
||||
}
|
||||
|
||||
/**
|
||||
* cf_define_symbol - define meaning of a symbol
|
||||
* @sym: symbol to be defined
|
||||
* @type: symbol class to assign
|
||||
* @def: class dependent data
|
||||
*
|
||||
* Defines new meaning of a symbol. If the symbol is an undefined
|
||||
* one (%SYM_VOID), it's just re-defined to the new type. If it's defined
|
||||
* in different scope, a new symbol in current scope is created and the
|
||||
* meaning is assigned to it. If it's already defined in the current scope,
|
||||
* an error is reported via cf_error().
|
||||
*
|
||||
* Result: Pointer to the newly defined symbol. If we are in the top-level
|
||||
* scope, it's the same @sym as passed to the function.
|
||||
*/
|
||||
struct symbol *
|
||||
cf_define_symbol(struct symbol *sym, int type, void *def)
|
||||
static enum yytokentype
|
||||
cf_lex_symbol(const char *data)
|
||||
{
|
||||
if (sym->class)
|
||||
/* Have we defined such a symbol? */
|
||||
struct symbol *sym = cf_get_symbol(data);
|
||||
cf_lval.s = sym;
|
||||
|
||||
if (sym->class != SYM_VOID)
|
||||
return CF_SYM_KNOWN;
|
||||
|
||||
/* Is it a keyword? */
|
||||
struct keyword *k = HASH_FIND(kw_hash, KW, data);
|
||||
if (k)
|
||||
{
|
||||
if (k->value > 0)
|
||||
return k->value;
|
||||
else
|
||||
{
|
||||
if (sym->scope == conf_this_scope)
|
||||
cf_error("Symbol already defined");
|
||||
sym = cf_new_sym(sym->name, cf_hash(sym->name) & (SYM_HASH_SIZE-1));
|
||||
cf_lval.i = -k->value;
|
||||
return ENUM;
|
||||
}
|
||||
sym->class = type;
|
||||
sym->def = def;
|
||||
return sym;
|
||||
}
|
||||
|
||||
/* OK, undefined symbol */
|
||||
cf_lval.s = sym;
|
||||
return CF_SYM_UNDEFINED;
|
||||
}
|
||||
|
||||
static void
|
||||
cf_lex_init_kh(void)
|
||||
{
|
||||
HASH_INIT(kw_hash, &root_pool, KW_ORDER);
|
||||
|
||||
struct keyword *k;
|
||||
|
||||
for(k=keyword_list; k->name; k++)
|
||||
{
|
||||
unsigned h = cf_hash(k->name) & (KW_HASH_SIZE-1);
|
||||
k->next = kw_hash[h];
|
||||
kw_hash[h] = k;
|
||||
}
|
||||
kw_hash_inited = 1;
|
||||
}
|
||||
|
||||
static struct include_file_stack *
|
||||
new_stack(struct include_file_stack *old)
|
||||
{
|
||||
struct include_file_stack *ret;
|
||||
ret = cfg_allocz(sizeof(struct include_file_stack));
|
||||
ret->conf_lino = 1;
|
||||
ret->prev = old;
|
||||
return ret;
|
||||
for (k=keyword_list; k->name; k++)
|
||||
HASH_INSERT(kw_hash, KW, k);
|
||||
}
|
||||
|
||||
/**
|
||||
* cf_lex_init - initialize the lexer
|
||||
* @is_cli: true if we're going to parse CLI command, false for configuration
|
||||
* @c: configuration structure
|
||||
*
|
||||
* cf_lex_init() initializes the lexical analyzer and prepares it for
|
||||
* parsing of a new input.
|
||||
@ -434,22 +700,27 @@ new_stack(struct include_file_stack *old)
|
||||
void
|
||||
cf_lex_init(int is_cli, struct config *c)
|
||||
{
|
||||
if (!kw_hash_inited)
|
||||
if (!kw_hash.data)
|
||||
cf_lex_init_kh();
|
||||
ifs_head = new_stack(NULL);
|
||||
ifs = ifs_head;
|
||||
ifs_depth = 0;
|
||||
if (!is_cli) {
|
||||
ifs->conf_fd = c->file_fd;
|
||||
ifs_depth = 1;
|
||||
strcpy(ifs->conf_fname, c->file_name);
|
||||
}
|
||||
|
||||
ifs_head = ifs = push_ifs(NULL);
|
||||
if (!is_cli)
|
||||
{
|
||||
ifs->file_name = c->file_name;
|
||||
ifs->fd = c->file_fd;
|
||||
ifs->depth = 1;
|
||||
}
|
||||
|
||||
yyrestart(NULL);
|
||||
ifs->buffer = YY_CURRENT_BUFFER;
|
||||
|
||||
if (is_cli)
|
||||
BEGIN(CLI);
|
||||
else
|
||||
BEGIN(INITIAL);
|
||||
conf_this_scope = cfg_allocz(sizeof(struct sym_scope));
|
||||
|
||||
c->root_scope = cfg_allocz(sizeof(struct sym_scope));
|
||||
conf_this_scope = c->root_scope;
|
||||
conf_this_scope->active = 1;
|
||||
}
|
||||
|
||||
@ -466,12 +737,13 @@ cf_lex_init(int is_cli, struct config *c)
|
||||
void
|
||||
cf_push_scope(struct symbol *sym)
|
||||
{
|
||||
struct sym_scope *s = cfg_alloc(sizeof(struct sym_scope));
|
||||
struct sym_scope *s = cfg_allocz(sizeof(struct sym_scope));
|
||||
|
||||
s->next = conf_this_scope;
|
||||
conf_this_scope = s;
|
||||
s->active = 1;
|
||||
s->name = sym;
|
||||
s->slots = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -486,25 +758,8 @@ cf_pop_scope(void)
|
||||
{
|
||||
conf_this_scope->active = 0;
|
||||
conf_this_scope = conf_this_scope->next;
|
||||
ASSERT(conf_this_scope);
|
||||
}
|
||||
|
||||
struct symbol *
|
||||
cf_walk_symbols(struct config *cf, struct symbol *sym, int *pos)
|
||||
{
|
||||
for(;;)
|
||||
{
|
||||
if (!sym)
|
||||
{
|
||||
if (*pos >= SYM_HASH_SIZE)
|
||||
return NULL;
|
||||
sym = cf->sym_hash[(*pos)++];
|
||||
}
|
||||
else
|
||||
sym = sym->next;
|
||||
if (sym && sym->scope->active)
|
||||
return sym;
|
||||
}
|
||||
ASSERT(conf_this_scope);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -523,16 +778,20 @@ cf_symbol_class_name(struct symbol *sym)
|
||||
return "undefined";
|
||||
case SYM_PROTO:
|
||||
return "protocol";
|
||||
case SYM_NUMBER:
|
||||
return "numeric constant";
|
||||
case SYM_TEMPLATE:
|
||||
return "protocol template";
|
||||
case SYM_FUNCTION:
|
||||
return "function";
|
||||
case SYM_FILTER:
|
||||
return "filter";
|
||||
case SYM_TABLE:
|
||||
return "routing table";
|
||||
case SYM_IPA:
|
||||
return "network address";
|
||||
case SYM_ATTRIBUTE:
|
||||
return "custom attribute";
|
||||
case SYM_CONSTANT_RANGE:
|
||||
return "constant";
|
||||
case SYM_VARIABLE_RANGE:
|
||||
return "variable";
|
||||
default:
|
||||
return "unknown type";
|
||||
}
|
||||
|
405
conf/conf.c
405
conf/conf.c
@ -20,16 +20,19 @@
|
||||
*
|
||||
* There can exist up to four different configurations at one time: an active
|
||||
* one (pointed to by @config), configuration we are just switching from
|
||||
* (@old_config), one queued for the next reconfiguration (@future_config;
|
||||
* if it's non-%NULL and the user wants to reconfigure once again, we just
|
||||
* free the previous queued config and replace it with the new one) and
|
||||
* finally a config being parsed (@new_config).
|
||||
* (@old_config), one queued for the next reconfiguration (@future_config; if
|
||||
* there is one and the user wants to reconfigure once again, we just free the
|
||||
* previous queued config and replace it with the new one) and finally a config
|
||||
* being parsed (@new_config). The stored @old_config is also used for undo
|
||||
* reconfiguration, which works in a similar way. Reconfiguration could also
|
||||
* have timeout (using @config_timer) and undo is automatically called if the
|
||||
* new configuration is not confirmed later. The new config (@new_config) and
|
||||
* associated linear pool (@cfg_mem) is non-NULL only during parsing.
|
||||
*
|
||||
* Loading of new configuration is very simple: just call config_alloc()
|
||||
* to get a new &config structure, then use config_parse() to parse a
|
||||
* configuration file and fill all fields of the structure
|
||||
* and finally ask the config manager to switch to the new
|
||||
* config by calling config_commit().
|
||||
* Loading of new configuration is very simple: just call config_alloc() to get
|
||||
* a new &config structure, then use config_parse() to parse a configuration
|
||||
* file and fill all fields of the structure and finally ask the config manager
|
||||
* to switch to the new config by calling config_commit().
|
||||
*
|
||||
* CLI commands are parsed in a very similar way -- there is also a stripped-down
|
||||
* &config structure associated with them and they are lex-ed and parsed by the
|
||||
@ -52,13 +55,28 @@
|
||||
#include "lib/timer.h"
|
||||
#include "conf/conf.h"
|
||||
#include "filter/filter.h"
|
||||
#include "sysdep/unix/unix.h"
|
||||
|
||||
|
||||
static jmp_buf conf_jmpbuf;
|
||||
|
||||
struct config *config, *new_config, *old_config, *future_config;
|
||||
static event *config_event;
|
||||
int shutting_down, future_type;
|
||||
bird_clock_t boot_time;
|
||||
struct config *config, *new_config;
|
||||
|
||||
static struct config *old_config; /* Old configuration */
|
||||
static struct config *future_config; /* New config held here if recon requested during recon */
|
||||
static int old_cftype; /* Type of transition old_config -> config (RECONFIG_SOFT/HARD) */
|
||||
static int future_cftype; /* Type of scheduled transition, may also be RECONFIG_UNDO */
|
||||
/* Note that when future_cftype is RECONFIG_UNDO, then future_config is NULL,
|
||||
therefore proper check for future scheduled config checks future_cftype */
|
||||
|
||||
static event *config_event; /* Event for finalizing reconfiguration */
|
||||
static timer *config_timer; /* Timer for scheduled configuration rollback */
|
||||
|
||||
/* These are public just for cmd_show_status(), should not be accessed elsewhere */
|
||||
int shutting_down; /* Shutdown requested, do not accept new config changes */
|
||||
int configuring; /* Reconfiguration is running */
|
||||
int undo_available; /* Undo was not requested from last reconfiguration */
|
||||
/* Note that both shutting_down and undo_available are related to requests, not processing */
|
||||
|
||||
/**
|
||||
* config_alloc - allocate a new configuration
|
||||
@ -69,21 +87,28 @@ bird_clock_t boot_time;
|
||||
* further use. Returns a pointer to the structure.
|
||||
*/
|
||||
struct config *
|
||||
config_alloc(byte *name)
|
||||
config_alloc(const char *name)
|
||||
{
|
||||
pool *p = rp_new(&root_pool, "Config");
|
||||
linpool *l = lp_new(p, 4080);
|
||||
linpool *l = lp_new_default(p);
|
||||
struct config *c = lp_allocz(l, sizeof(struct config));
|
||||
|
||||
/* Duplication of name string in local linear pool */
|
||||
uint nlen = strlen(name) + 1;
|
||||
char *ndup = lp_allocu(l, nlen);
|
||||
memcpy(ndup, name, nlen);
|
||||
|
||||
init_list(&c->tests);
|
||||
init_list(&c->symbols);
|
||||
c->mrtdump_file = -1; /* Hack, this should be sysdep-specific */
|
||||
c->pool = p;
|
||||
cfg_mem = c->mem = l;
|
||||
c->file_name = cfg_strdup(name);
|
||||
c->load_time = now;
|
||||
c->tf_base.fmt1 = c->tf_log.fmt1 = "%d-%m-%Y %T";
|
||||
c->mem = l;
|
||||
c->file_name = ndup;
|
||||
c->load_time = current_time();
|
||||
c->tf_route = c->tf_proto = TM_ISO_SHORT_MS;
|
||||
c->tf_base = c->tf_log = TM_ISO_LONG_MS;
|
||||
c->gr_wait = DEFAULT_GR_WAIT;
|
||||
|
||||
if (!boot_time)
|
||||
boot_time = now;
|
||||
return c;
|
||||
}
|
||||
|
||||
@ -103,24 +128,33 @@ config_alloc(byte *name)
|
||||
int
|
||||
config_parse(struct config *c)
|
||||
{
|
||||
int done = 0;
|
||||
DBG("Parsing configuration file `%s'\n", c->file_name);
|
||||
new_config = c;
|
||||
cfg_mem = c->mem;
|
||||
if (setjmp(conf_jmpbuf))
|
||||
return 0;
|
||||
goto cleanup;
|
||||
|
||||
cf_lex_init(0, c);
|
||||
sysdep_preconfig(c);
|
||||
protos_preconfig(c);
|
||||
rt_preconfig(c);
|
||||
cf_parse();
|
||||
protos_postconfig(c);
|
||||
|
||||
if (EMPTY_LIST(c->protos))
|
||||
cf_error("No protocol is specified in the config file");
|
||||
#ifdef IPV6
|
||||
|
||||
/*
|
||||
if (!c->router_id)
|
||||
cf_error("Router ID must be configured manually on IPv6 routers");
|
||||
#endif
|
||||
return 1;
|
||||
cf_error("Router ID must be configured manually");
|
||||
*/
|
||||
|
||||
done = 1;
|
||||
|
||||
cleanup:
|
||||
new_config = NULL;
|
||||
cfg_mem = NULL;
|
||||
return done;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -133,14 +167,22 @@ config_parse(struct config *c)
|
||||
int
|
||||
cli_parse(struct config *c)
|
||||
{
|
||||
int done = 0;
|
||||
c->fallback = config;
|
||||
new_config = c;
|
||||
c->sym_fallback = config->sym_hash;
|
||||
cfg_mem = c->mem;
|
||||
if (setjmp(conf_jmpbuf))
|
||||
return 0;
|
||||
goto cleanup;
|
||||
|
||||
cf_lex_init(1, c);
|
||||
cf_parse();
|
||||
return 1;
|
||||
done = 1;
|
||||
|
||||
cleanup:
|
||||
c->fallback = NULL;
|
||||
new_config = NULL;
|
||||
cfg_mem = NULL;
|
||||
return done;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -153,7 +195,8 @@ cli_parse(struct config *c)
|
||||
void
|
||||
config_free(struct config *c)
|
||||
{
|
||||
rfree(c->pool);
|
||||
if (c)
|
||||
rfree(c->pool);
|
||||
}
|
||||
|
||||
void
|
||||
@ -168,82 +211,102 @@ config_del_obstacle(struct config *c)
|
||||
{
|
||||
DBG("+++ deleting obstacle %d\n", c->obstacle_count);
|
||||
c->obstacle_count--;
|
||||
if (!c->obstacle_count)
|
||||
{
|
||||
ASSERT(config_event);
|
||||
ev_schedule(config_event);
|
||||
}
|
||||
if (!c->obstacle_count && (c != config))
|
||||
ev_schedule(config_event);
|
||||
}
|
||||
|
||||
static int
|
||||
global_commit(struct config *new, struct config *old)
|
||||
{
|
||||
if (!new->hostname)
|
||||
{
|
||||
new->hostname = get_hostname(new->mem);
|
||||
|
||||
if (!new->hostname)
|
||||
log(L_WARN "Cannot determine hostname");
|
||||
}
|
||||
|
||||
if (!old)
|
||||
return 0;
|
||||
|
||||
if (!ipa_equal(old->listen_bgp_addr, new->listen_bgp_addr) ||
|
||||
(old->listen_bgp_port != new->listen_bgp_port) ||
|
||||
(old->listen_bgp_flags != new->listen_bgp_flags))
|
||||
log(L_WARN "Reconfiguration of BGP listening socket not implemented, please restart BIRD.");
|
||||
|
||||
if (!new->router_id)
|
||||
new->router_id = old->router_id;
|
||||
if (new->router_id != old->router_id)
|
||||
return 1;
|
||||
{
|
||||
new->router_id = old->router_id;
|
||||
|
||||
if (new->router_id_from)
|
||||
{
|
||||
u32 id = if_choose_router_id(new->router_id_from, old->router_id);
|
||||
if (!id)
|
||||
log(L_WARN "Cannot determine router ID, using old one");
|
||||
else
|
||||
new->router_id = id;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
config_do_commit(struct config *c, int type)
|
||||
{
|
||||
int force_restart, nobs;
|
||||
if (type == RECONFIG_UNDO)
|
||||
{
|
||||
c = old_config;
|
||||
type = old_cftype;
|
||||
}
|
||||
else
|
||||
config_free(old_config);
|
||||
|
||||
DBG("do_commit\n");
|
||||
old_config = config;
|
||||
config = new_config = c;
|
||||
old_cftype = type;
|
||||
config = c;
|
||||
|
||||
configuring = 1;
|
||||
if (old_config && !config->shutdown)
|
||||
log(L_INFO "Reconfiguring");
|
||||
|
||||
if (old_config)
|
||||
old_config->obstacle_count++;
|
||||
|
||||
DBG("filter_commit\n");
|
||||
filter_commit(c, old_config);
|
||||
DBG("sysdep_commit\n");
|
||||
force_restart = sysdep_commit(c, old_config);
|
||||
int force_restart = sysdep_commit(c, old_config);
|
||||
DBG("global_commit\n");
|
||||
force_restart |= global_commit(c, old_config);
|
||||
DBG("rt_commit\n");
|
||||
rt_commit(c, old_config);
|
||||
DBG("protos_commit\n");
|
||||
protos_commit(c, old_config, force_restart, type);
|
||||
new_config = NULL; /* Just to be sure nobody uses that now */
|
||||
|
||||
int obs = 0;
|
||||
if (old_config)
|
||||
nobs = --old_config->obstacle_count;
|
||||
else
|
||||
nobs = 0;
|
||||
DBG("do_commit finished with %d obstacles remaining\n", nobs);
|
||||
return !nobs;
|
||||
obs = --old_config->obstacle_count;
|
||||
|
||||
DBG("do_commit finished with %d obstacles remaining\n", obs);
|
||||
return !obs;
|
||||
}
|
||||
|
||||
static void
|
||||
config_done(void *unused UNUSED)
|
||||
{
|
||||
struct config *c;
|
||||
if (config->shutdown)
|
||||
sysdep_shutdown_done();
|
||||
|
||||
DBG("config_done\n");
|
||||
for(;;)
|
||||
configuring = 0;
|
||||
if (old_config)
|
||||
log(L_INFO "Reconfigured");
|
||||
|
||||
if (future_cftype)
|
||||
{
|
||||
if (config->shutdown)
|
||||
sysdep_shutdown_done();
|
||||
log(L_INFO "Reconfigured");
|
||||
if (old_config)
|
||||
{
|
||||
config_free(old_config);
|
||||
old_config = NULL;
|
||||
}
|
||||
if (!future_config)
|
||||
break;
|
||||
c = future_config;
|
||||
int type = future_cftype;
|
||||
struct config *conf = future_config;
|
||||
future_cftype = RECONFIG_NONE;
|
||||
future_config = NULL;
|
||||
|
||||
log(L_INFO "Reconfiguring to queued configuration");
|
||||
if (!config_do_commit(c, future_type))
|
||||
break;
|
||||
if (config_do_commit(conf, type))
|
||||
config_done(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -251,6 +314,7 @@ config_done(void *unused UNUSED)
|
||||
* config_commit - commit a configuration
|
||||
* @c: new configuration
|
||||
* @type: type of reconfiguration (RECONFIG_SOFT or RECONFIG_HARD)
|
||||
* @timeout: timeout for undo (in seconds; or 0 for no timeout)
|
||||
*
|
||||
* When a configuration is parsed and prepared for use, the
|
||||
* config_commit() function starts the process of reconfiguration.
|
||||
@ -263,6 +327,10 @@ config_done(void *unused UNUSED)
|
||||
* using config_del_obstacle(), the old configuration is freed and
|
||||
* everything runs according to the new one.
|
||||
*
|
||||
* When @timeout is nonzero, the undo timer is activated with given
|
||||
* timeout. The timer is deactivated when config_commit(),
|
||||
* config_confirm() or config_undo() is called.
|
||||
*
|
||||
* Result: %CONF_DONE if the configuration has been accepted immediately,
|
||||
* %CONF_PROGRESS if it will take some time to switch to it, %CONF_QUEUED
|
||||
* if it's been queued due to another reconfiguration being in progress now
|
||||
@ -270,49 +338,165 @@ config_done(void *unused UNUSED)
|
||||
* are accepted.
|
||||
*/
|
||||
int
|
||||
config_commit(struct config *c, int type)
|
||||
config_commit(struct config *c, int type, uint timeout)
|
||||
{
|
||||
if (!config) /* First-time configuration */
|
||||
if (shutting_down)
|
||||
{
|
||||
config_do_commit(c, RECONFIG_HARD);
|
||||
return CONF_DONE;
|
||||
config_free(c);
|
||||
return CONF_SHUTDOWN;
|
||||
}
|
||||
if (old_config) /* Reconfiguration already in progress */
|
||||
|
||||
undo_available = 1;
|
||||
if (timeout)
|
||||
tm_start(config_timer, timeout S);
|
||||
else
|
||||
tm_stop(config_timer);
|
||||
|
||||
if (configuring)
|
||||
{
|
||||
if (shutting_down == 2)
|
||||
{
|
||||
log(L_INFO "New configuration discarded due to shutdown");
|
||||
config_free(c);
|
||||
return CONF_SHUTDOWN;
|
||||
}
|
||||
if (future_config)
|
||||
if (future_cftype)
|
||||
{
|
||||
log(L_INFO "Queueing new configuration, ignoring the one already queued");
|
||||
config_free(future_config);
|
||||
}
|
||||
else
|
||||
log(L_INFO "Queued new configuration");
|
||||
log(L_INFO "Queueing new configuration");
|
||||
|
||||
future_cftype = type;
|
||||
future_config = c;
|
||||
future_type = type;
|
||||
return CONF_QUEUED;
|
||||
}
|
||||
|
||||
if (!shutting_down)
|
||||
log(L_INFO "Reconfiguring");
|
||||
|
||||
if (config_do_commit(c, type))
|
||||
{
|
||||
config_done(NULL);
|
||||
return CONF_DONE;
|
||||
}
|
||||
if (!config_event)
|
||||
return CONF_PROGRESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* config_confirm - confirm a commited configuration
|
||||
*
|
||||
* When the undo timer is activated by config_commit() with nonzero timeout,
|
||||
* this function can be used to deactivate it and therefore confirm
|
||||
* the current configuration.
|
||||
*
|
||||
* Result: %CONF_CONFIRM when the current configuration is confirmed,
|
||||
* %CONF_NONE when there is nothing to confirm (i.e. undo timer is not active).
|
||||
*/
|
||||
int
|
||||
config_confirm(void)
|
||||
{
|
||||
if (config_timer->expires == 0)
|
||||
return CONF_NOTHING;
|
||||
|
||||
tm_stop(config_timer);
|
||||
|
||||
return CONF_CONFIRM;
|
||||
}
|
||||
|
||||
/**
|
||||
* config_undo - undo a configuration
|
||||
*
|
||||
* Function config_undo() can be used to change the current
|
||||
* configuration back to stored %old_config. If no reconfiguration is
|
||||
* running, this stored configuration is commited in the same way as a
|
||||
* new configuration in config_commit(). If there is already a
|
||||
* reconfiguration in progress and no next reconfiguration is
|
||||
* scheduled, then the undo is scheduled for later processing as
|
||||
* usual, but if another reconfiguration is already scheduled, then
|
||||
* such reconfiguration is removed instead (i.e. undo is applied on
|
||||
* the last commit that scheduled it).
|
||||
*
|
||||
* Result: %CONF_DONE if the configuration has been accepted immediately,
|
||||
* %CONF_PROGRESS if it will take some time to switch to it, %CONF_QUEUED
|
||||
* if it's been queued due to another reconfiguration being in progress now,
|
||||
* %CONF_UNQUEUED if a scheduled reconfiguration is removed, %CONF_NOTHING
|
||||
* if there is no relevant configuration to undo (the previous config request
|
||||
* was config_undo() too) or %CONF_SHUTDOWN if BIRD is in shutdown mode and
|
||||
* no new configuration changes are accepted.
|
||||
*/
|
||||
int
|
||||
config_undo(void)
|
||||
{
|
||||
if (shutting_down)
|
||||
return CONF_SHUTDOWN;
|
||||
|
||||
if (!undo_available || !old_config)
|
||||
return CONF_NOTHING;
|
||||
|
||||
undo_available = 0;
|
||||
tm_stop(config_timer);
|
||||
|
||||
if (configuring)
|
||||
{
|
||||
config_event = ev_new(&root_pool);
|
||||
config_event->hook = config_done;
|
||||
if (future_cftype)
|
||||
{
|
||||
config_free(future_config);
|
||||
future_config = NULL;
|
||||
|
||||
log(L_INFO "Removing queued configuration");
|
||||
future_cftype = RECONFIG_NONE;
|
||||
return CONF_UNQUEUED;
|
||||
}
|
||||
else
|
||||
{
|
||||
log(L_INFO "Queueing undo configuration");
|
||||
future_cftype = RECONFIG_UNDO;
|
||||
return CONF_QUEUED;
|
||||
}
|
||||
}
|
||||
|
||||
if (config_do_commit(NULL, RECONFIG_UNDO))
|
||||
{
|
||||
config_done(NULL);
|
||||
return CONF_DONE;
|
||||
}
|
||||
return CONF_PROGRESS;
|
||||
}
|
||||
|
||||
int
|
||||
config_status(void)
|
||||
{
|
||||
if (shutting_down)
|
||||
return CONF_SHUTDOWN;
|
||||
|
||||
if (configuring)
|
||||
return future_cftype ? CONF_QUEUED : CONF_PROGRESS;
|
||||
|
||||
return CONF_DONE;
|
||||
}
|
||||
|
||||
btime
|
||||
config_timer_status(void)
|
||||
{
|
||||
return tm_active(config_timer) ? tm_remains(config_timer) : -1;
|
||||
}
|
||||
|
||||
extern void cmd_reconfig_undo_notify(void);
|
||||
|
||||
static void
|
||||
config_timeout(timer *t UNUSED)
|
||||
{
|
||||
log(L_INFO "Config timeout expired, starting undo");
|
||||
cmd_reconfig_undo_notify();
|
||||
|
||||
int r = config_undo();
|
||||
if (r < 0)
|
||||
log(L_ERR "Undo request failed");
|
||||
}
|
||||
|
||||
void
|
||||
config_init(void)
|
||||
{
|
||||
config_event = ev_new(&root_pool);
|
||||
config_event->hook = config_done;
|
||||
|
||||
config_timer = tm_new(&root_pool);
|
||||
config_timer->hook = config_timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* order_shutdown - order BIRD shutdown
|
||||
*
|
||||
@ -320,21 +504,27 @@ config_commit(struct config *c, int type)
|
||||
* for switching to an empty configuration.
|
||||
*/
|
||||
void
|
||||
order_shutdown(void)
|
||||
order_shutdown(int gr)
|
||||
{
|
||||
struct config *c;
|
||||
|
||||
if (shutting_down)
|
||||
return;
|
||||
log(L_INFO "Shutting down");
|
||||
|
||||
if (!gr)
|
||||
log(L_INFO "Shutting down");
|
||||
else
|
||||
log(L_INFO "Shutting down for graceful restart");
|
||||
|
||||
c = lp_alloc(config->mem, sizeof(struct config));
|
||||
memcpy(c, config, sizeof(struct config));
|
||||
init_list(&c->protos);
|
||||
init_list(&c->tables);
|
||||
c->shutdown = 1;
|
||||
c->gr_down = gr;
|
||||
|
||||
config_commit(c, RECONFIG_HARD, 0);
|
||||
shutting_down = 1;
|
||||
config_commit(c, RECONFIG_HARD);
|
||||
shutting_down = 2;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -346,7 +536,7 @@ order_shutdown(void)
|
||||
* error in the configuration.
|
||||
*/
|
||||
void
|
||||
cf_error(char *msg, ...)
|
||||
cf_error(const char *msg, ...)
|
||||
{
|
||||
char buf[1024];
|
||||
va_list args;
|
||||
@ -354,9 +544,12 @@ cf_error(char *msg, ...)
|
||||
va_start(args, msg);
|
||||
if (bvsnprintf(buf, sizeof(buf), msg, args) < 0)
|
||||
strcpy(buf, "<bug: error message too long>");
|
||||
va_end(args);
|
||||
new_config->err_msg = cfg_strdup(buf);
|
||||
new_config->err_lino = ifs->conf_lino;
|
||||
new_config->err_file_name = ifs->conf_fname;
|
||||
new_config->err_lino = ifs->lino;
|
||||
new_config->err_chno = ifs->chno - ifs->toklen + 1;
|
||||
new_config->err_file_name = ifs->file_name;
|
||||
cf_lex_unwind();
|
||||
longjmp(conf_jmpbuf, 1);
|
||||
}
|
||||
|
||||
@ -370,10 +563,26 @@ cf_error(char *msg, ...)
|
||||
* and we want to preserve it for further use.
|
||||
*/
|
||||
char *
|
||||
cfg_strdup(char *c)
|
||||
cfg_strdup(const char *c)
|
||||
{
|
||||
int l = strlen(c) + 1;
|
||||
char *z = cfg_allocu(l);
|
||||
memcpy(z, c, l);
|
||||
return z;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
cfg_copy_list(list *dest, list *src, unsigned node_size)
|
||||
{
|
||||
node *dn, *sn;
|
||||
|
||||
init_list(dest);
|
||||
WALK_LIST(sn, *src)
|
||||
{
|
||||
dn = cfg_alloc(node_size);
|
||||
memcpy(dn, sn, node_size);
|
||||
memset(dn, 0, sizeof(node));
|
||||
add_tail(dest, dn);
|
||||
}
|
||||
}
|
||||
|
172
conf/conf.h
172
conf/conf.h
@ -9,11 +9,12 @@
|
||||
#ifndef _BIRD_CONF_H_
|
||||
#define _BIRD_CONF_H_
|
||||
|
||||
#include "sysdep/config.h"
|
||||
#include "lib/ip.h"
|
||||
#include "lib/hash.h"
|
||||
#include "lib/resource.h"
|
||||
#include "lib/timer.h"
|
||||
|
||||
#define BIRD_FNAME_MAX 255 /* Would be better to use some UNIX define */
|
||||
|
||||
/* Configuration structure */
|
||||
|
||||
struct config {
|
||||
@ -21,60 +22,78 @@ struct config {
|
||||
linpool *mem; /* Linear pool containing configuration data */
|
||||
list protos; /* Configured protocol instances (struct proto_config) */
|
||||
list tables; /* Configured routing tables (struct rtable_config) */
|
||||
list logfiles; /* Configured log fils (sysdep) */
|
||||
list logfiles; /* Configured log files (sysdep) */
|
||||
list tests; /* Configured unit tests (f_bt_test_suite) */
|
||||
list symbols; /* Configured symbols in config order */
|
||||
|
||||
int mrtdump_file; /* Configured MRTDump file (sysdep, fd in unix) */
|
||||
char *syslog_name; /* Name used for syslog (NULL -> no syslog) */
|
||||
struct rtable_config *master_rtc; /* Configuration of master routing table */
|
||||
const char *syslog_name; /* Name used for syslog (NULL -> no syslog) */
|
||||
struct rtable_config *def_tables[NET_MAX]; /* Default routing tables for each network */
|
||||
struct iface_patt *router_id_from; /* Configured list of router ID iface patterns */
|
||||
|
||||
u32 router_id; /* Our Router ID */
|
||||
ip_addr listen_bgp_addr; /* Listening BGP socket should use this address */
|
||||
unsigned listen_bgp_port; /* Listening BGP socket should use this port (0 is default) */
|
||||
u32 listen_bgp_flags; /* Listening BGP socket should use these flags */
|
||||
unsigned proto_default_debug; /* Default protocol debug mask */
|
||||
unsigned proto_default_mrtdump; /* Default protocol mrtdump mask */
|
||||
u32 proto_default_debug; /* Default protocol debug mask */
|
||||
u32 proto_default_mrtdump; /* Default protocol mrtdump mask */
|
||||
u32 channel_default_debug; /* Default channel debug mask */
|
||||
struct timeformat tf_route; /* Time format for 'show route' */
|
||||
struct timeformat tf_proto; /* Time format for 'show protocol' */
|
||||
struct timeformat tf_log; /* Time format for the logfile */
|
||||
struct timeformat tf_base; /* Time format for other purposes */
|
||||
u32 gr_wait; /* Graceful restart wait timeout (sec) */
|
||||
const char *hostname; /* Hostname */
|
||||
|
||||
int cli_debug; /* Tracing of CLI connections and commands */
|
||||
int latency_debug; /* I/O loop tracks duration of each event */
|
||||
u32 latency_limit; /* Events with longer duration are logged (us) */
|
||||
u32 watchdog_warning; /* I/O loop watchdog limit for warning (us) */
|
||||
u32 watchdog_timeout; /* Watchdog timeout (in seconds, 0 = disabled) */
|
||||
char *err_msg; /* Parser error message */
|
||||
int err_lino; /* Line containing error */
|
||||
int err_chno; /* Character where the parser stopped */
|
||||
char *err_file_name; /* File name containing error */
|
||||
char *file_name; /* Name of main configuration file */
|
||||
int file_fd; /* File descriptor of main configuration file */
|
||||
struct symbol **sym_hash; /* Lexer: symbol hash table */
|
||||
struct symbol **sym_fallback; /* Lexer: fallback symbol hash table */
|
||||
HASH(struct symbol) sym_hash; /* Lexer: symbol hash table */
|
||||
struct config *fallback; /* Link to regular config for CLI parsing */
|
||||
struct sym_scope *root_scope; /* Scope for root symbols */
|
||||
int obstacle_count; /* Number of items blocking freeing of this config */
|
||||
int shutdown; /* This is a pseudo-config for daemon shutdown */
|
||||
bird_clock_t load_time; /* When we've got this configuration */
|
||||
int gr_down; /* This is a pseudo-config for graceful restart */
|
||||
btime load_time; /* When we've got this configuration */
|
||||
};
|
||||
|
||||
/* Please don't use these variables in protocols. Use proto_config->global instead. */
|
||||
extern struct config *config; /* Currently active configuration */
|
||||
extern struct config *new_config; /* Configuration being parsed */
|
||||
extern struct config *old_config; /* Old configuration when reconfiguration is in progress */
|
||||
extern struct config *future_config; /* New config held here if recon requested during recon */
|
||||
|
||||
extern int shutting_down;
|
||||
extern bird_clock_t boot_time;
|
||||
|
||||
struct config *config_alloc(byte *name);
|
||||
struct config *config_alloc(const char *name);
|
||||
int config_parse(struct config *);
|
||||
int cli_parse(struct config *);
|
||||
void config_free(struct config *);
|
||||
int config_commit(struct config *, int type);
|
||||
#define RECONFIG_HARD 0
|
||||
#define RECONFIG_SOFT 1
|
||||
void cf_error(char *msg, ...) NORET;
|
||||
int config_commit(struct config *, int type, uint timeout);
|
||||
int config_confirm(void);
|
||||
int config_undo(void);
|
||||
int config_status(void);
|
||||
btime config_timer_status(void);
|
||||
void config_init(void);
|
||||
void cf_error(const char *msg, ...) NORET;
|
||||
void config_add_obstacle(struct config *);
|
||||
void config_del_obstacle(struct config *);
|
||||
void order_shutdown(void);
|
||||
void order_shutdown(int gr);
|
||||
|
||||
#define RECONFIG_NONE 0
|
||||
#define RECONFIG_HARD 1
|
||||
#define RECONFIG_SOFT 2
|
||||
#define RECONFIG_UNDO 3
|
||||
|
||||
#define CONF_DONE 0
|
||||
#define CONF_PROGRESS 1
|
||||
#define CONF_QUEUED 2
|
||||
#define CONF_UNQUEUED 3
|
||||
#define CONF_CONFIRM 4
|
||||
#define CONF_SHUTDOWN -1
|
||||
#define CONF_NOTHING -2
|
||||
|
||||
#define CONF_DONE 0
|
||||
#define CONF_PROGRESS 1
|
||||
#define CONF_QUEUED 2
|
||||
#define CONF_SHUTDOWN 3
|
||||
|
||||
/* Pools */
|
||||
|
||||
@ -83,58 +102,117 @@ extern linpool *cfg_mem;
|
||||
#define cfg_alloc(size) lp_alloc(cfg_mem, size)
|
||||
#define cfg_allocu(size) lp_allocu(cfg_mem, size)
|
||||
#define cfg_allocz(size) lp_allocz(cfg_mem, size)
|
||||
char *cfg_strdup(char *c);
|
||||
char *cfg_strdup(const char *c);
|
||||
void cfg_copy_list(list *dest, list *src, unsigned node_size);
|
||||
|
||||
/* Lexer */
|
||||
|
||||
extern int (*cf_read_hook)(byte *buf, unsigned int max, int fd);
|
||||
extern int (*cf_open_hook)(char *filename);
|
||||
extern int (*cf_read_hook)(byte *buf, uint max, int fd);
|
||||
|
||||
struct symbol {
|
||||
node n; /* In list of symbols in config */
|
||||
struct symbol *next;
|
||||
struct sym_scope *scope;
|
||||
int class;
|
||||
int aux;
|
||||
void *aux2;
|
||||
void *def;
|
||||
char name[1];
|
||||
int class; /* SYM_* */
|
||||
uint flags; /* SYM_FLAG_* */
|
||||
|
||||
union {
|
||||
struct proto_config *proto; /* For SYM_PROTO and SYM_TEMPLATE */
|
||||
const struct f_line *function; /* For SYM_FUNCTION */
|
||||
const struct filter *filter; /* For SYM_FILTER */
|
||||
struct rtable_config *table; /* For SYM_TABLE */
|
||||
struct f_dynamic_attr *attribute; /* For SYM_ATTRIBUTE */
|
||||
struct f_val *val; /* For SYM_CONSTANT */
|
||||
uint offset; /* For SYM_VARIABLE */
|
||||
};
|
||||
|
||||
char name[0];
|
||||
};
|
||||
|
||||
struct sym_scope {
|
||||
struct sym_scope *next; /* Next on scope stack */
|
||||
struct symbol *name; /* Name of this scope */
|
||||
uint slots; /* Variable slots */
|
||||
int active; /* Currently entered */
|
||||
};
|
||||
|
||||
#define SYM_MAX_LEN 64
|
||||
|
||||
/* Remember to update cf_symbol_class_name() */
|
||||
#define SYM_VOID 0
|
||||
#define SYM_PROTO 1
|
||||
#define SYM_NUMBER 2
|
||||
#define SYM_TEMPLATE 2
|
||||
#define SYM_FUNCTION 3
|
||||
#define SYM_FILTER 4
|
||||
#define SYM_TABLE 5
|
||||
#define SYM_IPA 6
|
||||
#define SYM_ATTRIBUTE 6
|
||||
|
||||
#define SYM_VARIABLE 0x100 /* 0x100-0x1ff are variable types */
|
||||
#define SYM_VARIABLE_RANGE SYM_VARIABLE ... (SYM_VARIABLE | 0xff)
|
||||
#define SYM_CONSTANT 0x200 /* 0x200-0x2ff are variable types */
|
||||
#define SYM_CONSTANT_RANGE SYM_CONSTANT ... (SYM_CONSTANT | 0xff)
|
||||
|
||||
#define SYM_TYPE(s) ((s)->val->type)
|
||||
#define SYM_VAL(s) ((s)->val->val)
|
||||
|
||||
/* Symbol flags */
|
||||
#define SYM_FLAG_SAME 0x1 /* For SYM_FUNCTION and SYM_FILTER */
|
||||
|
||||
struct include_file_stack {
|
||||
void *stack; /* Internal lexer state */
|
||||
unsigned int conf_lino; /* Current file lineno (at include) */
|
||||
char conf_fname[BIRD_FNAME_MAX]; /* Current file name */
|
||||
int conf_fd; /* Current file descriptor */
|
||||
struct include_file_stack *prev;
|
||||
struct include_file_stack *next;
|
||||
void *buffer; /* Internal lexer state */
|
||||
char *file_name; /* File name */
|
||||
int fd; /* File descriptor */
|
||||
int lino; /* Current line num */
|
||||
int chno; /* Current char num (on current line) */
|
||||
int toklen; /* Current token length */
|
||||
int depth; /* Include depth, 0 = cannot include */
|
||||
|
||||
struct include_file_stack *prev; /* Previous record in stack */
|
||||
struct include_file_stack *up; /* Parent (who included this file) */
|
||||
};
|
||||
|
||||
extern struct include_file_stack *ifs;
|
||||
|
||||
extern struct sym_scope *conf_this_scope;
|
||||
|
||||
int cf_lex(void);
|
||||
void cf_lex_init(int is_cli, struct config *c);
|
||||
struct symbol *cf_find_symbol(byte *c);
|
||||
void cf_lex_unwind(void);
|
||||
|
||||
struct symbol *cf_find_symbol(const struct config *cfg, const byte *c);
|
||||
|
||||
struct symbol *cf_get_symbol(const byte *c);
|
||||
struct symbol *cf_default_name(char *template, int *counter);
|
||||
struct symbol *cf_define_symbol(struct symbol *symbol, int type, void *def);
|
||||
struct symbol *cf_localize_symbol(struct symbol *sym);
|
||||
|
||||
/**
|
||||
* cf_define_symbol - define meaning of a symbol
|
||||
* @sym: symbol to be defined
|
||||
* @type: symbol class to assign
|
||||
* @def: class dependent data
|
||||
*
|
||||
* Defines new meaning of a symbol. If the symbol is an undefined
|
||||
* one (%SYM_VOID), it's just re-defined to the new type. If it's defined
|
||||
* in different scope, a new symbol in current scope is created and the
|
||||
* meaning is assigned to it. If it's already defined in the current scope,
|
||||
* an error is reported via cf_error().
|
||||
*
|
||||
* Result: Pointer to the newly defined symbol. If we are in the top-level
|
||||
* scope, it's the same @sym as passed to the function.
|
||||
*/
|
||||
#define cf_define_symbol(osym_, type_, var_, def_) ({ \
|
||||
struct symbol *sym_ = cf_localize_symbol(osym_); \
|
||||
sym_->class = type_; \
|
||||
sym_->var_ = def_; \
|
||||
sym_; })
|
||||
|
||||
void cf_push_scope(struct symbol *);
|
||||
void cf_pop_scope(void);
|
||||
struct symbol *cf_walk_symbols(struct config *cf, struct symbol *sym, int *pos);
|
||||
char *cf_symbol_class_name(struct symbol *sym);
|
||||
|
||||
/* Parser */
|
||||
|
||||
extern char *cf_text;
|
||||
int cf_parse(void);
|
||||
|
||||
/* Sysdep hooks */
|
||||
|
324
conf/confbase.Y
324
conf/confbase.Y
@ -19,6 +19,7 @@ CF_HDR
|
||||
#include "nest/protocol.h"
|
||||
#include "nest/iface.h"
|
||||
#include "nest/route.h"
|
||||
#include "nest/bfd.h"
|
||||
#include "nest/cli.h"
|
||||
#include "filter/filter.h"
|
||||
|
||||
@ -27,60 +28,104 @@ CF_HDR
|
||||
CF_DEFINES
|
||||
|
||||
static void
|
||||
check_u16(unsigned val)
|
||||
check_u16(uint val)
|
||||
{
|
||||
if (val > 0xFFFF)
|
||||
cf_error("Value %d out of range (0-65535)", val);
|
||||
cf_error("Value %u out of range (0-65535)", val);
|
||||
}
|
||||
|
||||
#define cf_assert(cond, ...) do { if (!(cond)) cf_error(__VA_ARGS__); } while (0)
|
||||
static inline void cf_assert_symbol(const struct symbol *sym, uint class) {
|
||||
switch (class) {
|
||||
case SYM_PROTO: cf_assert(sym->class == SYM_PROTO, "Protocol name required"); break;
|
||||
case SYM_TEMPLATE: cf_assert(sym->class == SYM_TEMPLATE, "Protocol template name required"); break;
|
||||
case SYM_FUNCTION: cf_assert(sym->class == SYM_FUNCTION, "Function name required"); break;
|
||||
case SYM_FILTER: cf_assert(sym->class == SYM_FILTER, "Filter name required"); break;
|
||||
case SYM_TABLE: cf_assert(sym->class == SYM_TABLE, "Table name required"); break;
|
||||
case SYM_ATTRIBUTE: cf_assert(sym->class == SYM_ATTRIBUTE, "Custom attribute name required"); break;
|
||||
case SYM_VARIABLE: cf_assert((sym->class & ~0xff) == SYM_VARIABLE, "Variable name required"); break;
|
||||
case SYM_CONSTANT: cf_assert((sym->class & ~0xff) == SYM_CONSTANT, "Constant name required"); break;
|
||||
default: bug("This shall not happen");
|
||||
}
|
||||
}
|
||||
|
||||
CF_DECLS
|
||||
|
||||
%union {
|
||||
int i;
|
||||
uint i;
|
||||
u32 i32;
|
||||
u64 i64;
|
||||
ip_addr a;
|
||||
ip4_addr ip4;
|
||||
ip6_addr ip6;
|
||||
net_addr net;
|
||||
net_addr *net_ptr;
|
||||
struct symbol *s;
|
||||
char *t;
|
||||
const char *t;
|
||||
struct rtable_config *r;
|
||||
struct channel_config *cc;
|
||||
struct channel *c;
|
||||
struct f_inst *x;
|
||||
struct filter *f;
|
||||
struct {
|
||||
struct f_inst *begin, *end;
|
||||
} xp;
|
||||
enum filter_return fret;
|
||||
enum ec_subtype ecs;
|
||||
struct f_dynamic_attr fda;
|
||||
struct f_static_attr fsa;
|
||||
struct f_lval flv;
|
||||
struct f_line *fl;
|
||||
const struct filter *f;
|
||||
struct f_tree *e;
|
||||
struct f_trie *trie;
|
||||
struct f_val v;
|
||||
struct f_path_mask *h;
|
||||
struct password_item *p;
|
||||
struct rt_show_data *ra;
|
||||
struct sym_show_data *sd;
|
||||
struct lsadb_show_data *ld;
|
||||
struct mrt_dump_data *md;
|
||||
struct iface *iface;
|
||||
void *g;
|
||||
bird_clock_t time;
|
||||
struct prefix px;
|
||||
btime time;
|
||||
struct f_prefix px;
|
||||
struct proto_spec ps;
|
||||
struct channel_limit cl;
|
||||
struct timeformat *tf;
|
||||
mpls_label_stack *mls;
|
||||
}
|
||||
|
||||
%token END CLI_MARKER INVALID_TOKEN ELSECOL DDOT
|
||||
%token GEQ LEQ NEQ AND OR
|
||||
%token PO PC
|
||||
%token <i> NUM ENUM
|
||||
%token <i32> RTRID
|
||||
%token <a> IPA
|
||||
%token <s> SYM
|
||||
%token <ip4> IP4
|
||||
%token <ip6> IP6
|
||||
%token <i64> VPN_RD
|
||||
%token <s> CF_SYM_KNOWN CF_SYM_UNDEFINED
|
||||
%token <t> TEXT
|
||||
%type <iface> ipa_scope
|
||||
|
||||
%type <i> expr bool pxlen
|
||||
%type <time> datetime
|
||||
%type <i> expr bool pxlen4
|
||||
%type <time> expr_us time
|
||||
%type <a> ipa
|
||||
%type <px> prefix prefix_or_ipa
|
||||
%type <t> text_or_none
|
||||
%type <net> net_ip4_ net_ip6_ net_ip6 net_ip_ net_ip net_or_ipa
|
||||
%type <net_ptr> net_ net_any net_vpn4_ net_vpn6_ net_vpn_ net_roa4_ net_roa6_ net_roa_ net_ip6_sadr_ net_mpls_
|
||||
%type <mls> label_stack_start label_stack
|
||||
|
||||
%type <t> text opttext
|
||||
%type <s> symbol
|
||||
|
||||
%nonassoc PREFIX_DUMMY
|
||||
%left AND OR
|
||||
%nonassoc '=' '<' '>' '~' GEQ LEQ NEQ PO PC
|
||||
%nonassoc '=' '<' '>' '~' GEQ LEQ NEQ NMA PO PC
|
||||
%left '+' '-'
|
||||
%left '*' '/' '%'
|
||||
%left '!'
|
||||
%nonassoc '.'
|
||||
|
||||
CF_KEYWORDS(DEFINE, ON, OFF, YES, NO)
|
||||
%start config
|
||||
|
||||
CF_KEYWORDS(DEFINE, ON, OFF, YES, NO, S, MS, US, PORT, VPN, MPLS, FROM)
|
||||
|
||||
CF_GRAMMAR
|
||||
|
||||
@ -95,34 +140,41 @@ conf_entries:
|
||||
| conf_entries conf
|
||||
;
|
||||
|
||||
CF_ADDTO(conf, ';')
|
||||
conf: ';' ;
|
||||
|
||||
|
||||
/* Constant expressions */
|
||||
|
||||
conf: definition ;
|
||||
|
||||
definition:
|
||||
DEFINE symbol '=' term ';' {
|
||||
struct f_val *val = cfg_allocz(sizeof(struct f_val));
|
||||
if (f_eval(f_linearize($4), cfg_mem, val) > F_RETURN) cf_error("Runtime error");
|
||||
cf_define_symbol($2, SYM_CONSTANT | val->type, val, val);
|
||||
}
|
||||
;
|
||||
|
||||
expr:
|
||||
NUM
|
||||
| '(' term ')' { $$ = f_eval_int($2); }
|
||||
| SYM { if ($1->class != SYM_NUMBER) cf_error("Number expected"); else $$ = $1->aux; }
|
||||
| '(' term ')' { $$ = f_eval_int(f_linearize($2)); }
|
||||
| CF_SYM_KNOWN {
|
||||
if ($1->class != (SYM_CONSTANT | T_INT)) cf_error("Number constant expected");
|
||||
$$ = SYM_VAL($1).i; }
|
||||
;
|
||||
|
||||
/* expr_u16: expr { check_u16($1); $$ = $1; }; */
|
||||
|
||||
CF_ADDTO(conf, definition)
|
||||
definition:
|
||||
DEFINE SYM '=' expr ';' {
|
||||
cf_define_symbol($2, SYM_NUMBER, NULL);
|
||||
$2->aux = $4;
|
||||
}
|
||||
| DEFINE SYM '=' IPA ';' {
|
||||
cf_define_symbol($2, SYM_IPA, cfg_alloc(sizeof(ip_addr)));
|
||||
*(ip_addr *)$2->def = $4;
|
||||
}
|
||||
expr_us:
|
||||
expr S { $$ = $1 S_; }
|
||||
| expr MS { $$ = $1 MS_; }
|
||||
| expr US { $$ = $1 US_; }
|
||||
;
|
||||
|
||||
symbol: CF_SYM_UNDEFINED | CF_SYM_KNOWN ;
|
||||
|
||||
/* Switches */
|
||||
|
||||
bool:
|
||||
expr {$$ = !!$1; }
|
||||
expr { $$ = !!$1; }
|
||||
| ON { $$ = 1; }
|
||||
| YES { $$ = 1; }
|
||||
| OFF { $$ = 0; }
|
||||
@ -130,52 +182,206 @@ bool:
|
||||
| /* Silence means agreement */ { $$ = 1; }
|
||||
;
|
||||
|
||||
/* Addresses, prefixes and netmasks */
|
||||
|
||||
/* Addresses */
|
||||
|
||||
ipa:
|
||||
IPA
|
||||
| SYM {
|
||||
if ($1->class != SYM_IPA) cf_error("IP address expected");
|
||||
$$ = *(ip_addr *)$1->def;
|
||||
IP4 { $$ = ipa_from_ip4($1); }
|
||||
| IP6 { $$ = ipa_from_ip6($1); }
|
||||
| CF_SYM_KNOWN {
|
||||
if ($1->class != (SYM_CONSTANT | T_IP)) cf_error("IP address constant expected");
|
||||
$$ = SYM_VAL($1).ip;
|
||||
}
|
||||
;
|
||||
|
||||
prefix:
|
||||
ipa pxlen {
|
||||
if (!ip_is_prefix($1, $2)) cf_error("Invalid prefix");
|
||||
$$.addr = $1; $$.len = $2;
|
||||
}
|
||||
ipa_scope:
|
||||
/* empty */ { $$ = NULL; }
|
||||
| '%' symbol { $$ = if_get_by_name($2->name); }
|
||||
;
|
||||
|
||||
prefix_or_ipa:
|
||||
prefix
|
||||
| ipa { $$.addr = $1; $$.len = BITS_PER_IP_ADDRESS; }
|
||||
;
|
||||
|
||||
pxlen:
|
||||
'/' expr {
|
||||
if ($2 < 0 || $2 > BITS_PER_IP_ADDRESS) cf_error("Invalid prefix length %d", $2);
|
||||
/* Networks - internal */
|
||||
|
||||
pxlen4:
|
||||
'/' NUM {
|
||||
if ($2 > IP4_MAX_PREFIX_LENGTH) cf_error("Invalid prefix length %u", $2);
|
||||
$$ = $2;
|
||||
}
|
||||
| ':' ipa {
|
||||
$$ = ipa_mklen($2);
|
||||
if ($$ < 0) cf_error("Invalid netmask %I", $2);
|
||||
;
|
||||
|
||||
net_ip4_: IP4 pxlen4
|
||||
{
|
||||
net_fill_ip4(&($$), $1, $2);
|
||||
|
||||
net_addr_ip4 *n = (void *) &($$);
|
||||
if (!net_validate_ip4(n))
|
||||
cf_error("Invalid IPv4 prefix %I4/%d, maybe you wanted %I4/%d",
|
||||
n->prefix, n->pxlen, ip4_and(n->prefix, ip4_mkmask(n->pxlen)), n->pxlen);
|
||||
};
|
||||
|
||||
net_ip6_: IP6 '/' NUM
|
||||
{
|
||||
if ($3 > IP6_MAX_PREFIX_LENGTH)
|
||||
cf_error("Invalid prefix length %u", $3);
|
||||
|
||||
net_fill_ip6(&($$), $1, $3);
|
||||
|
||||
net_addr_ip6 *n = (void *) &($$);
|
||||
if (!net_validate_ip6(n))
|
||||
cf_error("Invalid IPv6 prefix %I6/%d, maybe you wanted %I6/%d",
|
||||
n->prefix, n->pxlen, ip6_and(n->prefix, ip6_mkmask(n->pxlen)), n->pxlen);
|
||||
};
|
||||
|
||||
net_ip6_sadr_: IP6 '/' NUM FROM IP6 '/' NUM
|
||||
{
|
||||
if ($3 > IP6_MAX_PREFIX_LENGTH)
|
||||
cf_error("Invalid prefix length %u", $3);
|
||||
|
||||
if ($7 > IP6_MAX_PREFIX_LENGTH)
|
||||
cf_error("Invalid prefix length %u", $7);
|
||||
|
||||
$$ = cfg_alloc(sizeof(net_addr_ip6_sadr));
|
||||
net_fill_ip6_sadr($$, $1, $3, $5, $7);
|
||||
|
||||
net_addr_ip6_sadr *n = (void *) $$;
|
||||
if (!net_validate_ip6_sadr(n))
|
||||
cf_error("Invalid SADR IPv6 prefix %I6/%d from %I6/%d, maybe you wanted %I6/%d from %I6/%d",
|
||||
n->dst_prefix, n->dst_pxlen, n->src_prefix, n->src_pxlen,
|
||||
ip6_and(n->dst_prefix, ip6_mkmask(n->dst_pxlen)), n->dst_pxlen,
|
||||
ip6_and(n->src_prefix, ip6_mkmask(n->src_pxlen)), n->src_pxlen);
|
||||
};
|
||||
|
||||
net_vpn4_: VPN_RD net_ip4_
|
||||
{
|
||||
$$ = cfg_alloc(sizeof(net_addr_vpn4));
|
||||
net_fill_vpn4($$, net4_prefix(&$2), net4_pxlen(&$2), $1);
|
||||
}
|
||||
|
||||
net_vpn6_: VPN_RD net_ip6_
|
||||
{
|
||||
$$ = cfg_alloc(sizeof(net_addr_vpn6));
|
||||
net_fill_vpn6($$, net6_prefix(&$2), net6_pxlen(&$2), $1);
|
||||
}
|
||||
|
||||
net_roa4_: net_ip4_ MAX NUM AS NUM
|
||||
{
|
||||
$$ = cfg_alloc(sizeof(net_addr_roa4));
|
||||
net_fill_roa4($$, net4_prefix(&$1), net4_pxlen(&$1), $3, $5);
|
||||
if ($3 < net4_pxlen(&$1) || $3 > IP4_MAX_PREFIX_LENGTH)
|
||||
cf_error("Invalid max prefix length %u", $3);
|
||||
};
|
||||
|
||||
net_roa6_: net_ip6_ MAX NUM AS NUM
|
||||
{
|
||||
$$ = cfg_alloc(sizeof(net_addr_roa6));
|
||||
net_fill_roa6($$, net6_prefix(&$1), net6_pxlen(&$1), $3, $5);
|
||||
if ($3 < net6_pxlen(&$1) || $3 > IP6_MAX_PREFIX_LENGTH)
|
||||
cf_error("Invalid max prefix length %u", $3);
|
||||
};
|
||||
|
||||
net_mpls_: MPLS NUM
|
||||
{
|
||||
$$ = cfg_alloc(sizeof(net_addr_roa6));
|
||||
net_fill_mpls($$, $2);
|
||||
}
|
||||
|
||||
net_ip_: net_ip4_ | net_ip6_ ;
|
||||
net_vpn_: net_vpn4_ | net_vpn6_ ;
|
||||
net_roa_: net_roa4_ | net_roa6_ ;
|
||||
|
||||
net_:
|
||||
net_ip_ { $$ = cfg_alloc($1.length); net_copy($$, &($1)); }
|
||||
| net_vpn_
|
||||
| net_roa_
|
||||
| net_flow_
|
||||
| net_ip6_sadr_
|
||||
| net_mpls_
|
||||
;
|
||||
|
||||
|
||||
/* Networks - regular */
|
||||
|
||||
net_ip6:
|
||||
net_ip6_
|
||||
| CF_SYM_KNOWN {
|
||||
if (($1->class != (SYM_CONSTANT | T_NET)) || (SYM_VAL($1).net->type != NET_IP6))
|
||||
cf_error("IPv6 network constant expected");
|
||||
$$ = * SYM_VAL($1).net;
|
||||
}
|
||||
;
|
||||
|
||||
datetime:
|
||||
net_ip:
|
||||
net_ip_
|
||||
| CF_SYM_KNOWN {
|
||||
if (($1->class != (SYM_CONSTANT | T_NET)) || !net_is_ip(SYM_VAL($1).net))
|
||||
cf_error("IP network constant expected");
|
||||
$$ = * SYM_VAL($1).net;
|
||||
}
|
||||
;
|
||||
|
||||
net_any:
|
||||
net_
|
||||
| CF_SYM_KNOWN {
|
||||
if ($1->class != (SYM_CONSTANT | T_NET))
|
||||
cf_error("Network constant expected");
|
||||
$$ = (net_addr *) SYM_VAL($1).net; /* Avoid const warning */
|
||||
}
|
||||
;
|
||||
|
||||
net_or_ipa:
|
||||
net_ip4_
|
||||
| net_ip6_
|
||||
| IP4 { net_fill_ip4(&($$), $1, IP4_MAX_PREFIX_LENGTH); }
|
||||
| IP6 { net_fill_ip6(&($$), $1, IP6_MAX_PREFIX_LENGTH); }
|
||||
| CF_SYM_KNOWN {
|
||||
if ($1->class == (SYM_CONSTANT | T_IP))
|
||||
net_fill_ip_host(&($$), SYM_VAL($1).ip);
|
||||
else if (($1->class == (SYM_CONSTANT | T_NET)) && net_is_ip(SYM_VAL($1).net))
|
||||
$$ = * SYM_VAL($1).net;
|
||||
else
|
||||
cf_error("IP address or network constant expected");
|
||||
}
|
||||
;
|
||||
|
||||
label_stack_start: NUM
|
||||
{
|
||||
$$ = cfg_allocz(sizeof(mpls_label_stack));
|
||||
$$->len = 1;
|
||||
$$->stack[0] = $1;
|
||||
};
|
||||
|
||||
label_stack:
|
||||
label_stack_start
|
||||
| label_stack '/' NUM {
|
||||
if ($1->len >= MPLS_MAX_LABEL_STACK)
|
||||
cf_error("Too many labels in stack");
|
||||
$1->stack[$1->len++] = $3;
|
||||
$$ = $1;
|
||||
}
|
||||
;
|
||||
|
||||
time:
|
||||
TEXT {
|
||||
$$ = tm_parse_datetime($1);
|
||||
$$ = tm_parse_time($1);
|
||||
if (!$$)
|
||||
cf_error("Invalid date and time");
|
||||
cf_error("Invalid date/time");
|
||||
}
|
||||
;
|
||||
|
||||
text_or_none:
|
||||
TEXT { $$ = $1; }
|
||||
| { $$ = NULL; }
|
||||
text:
|
||||
TEXT
|
||||
| CF_SYM_KNOWN {
|
||||
if ($1->class != (SYM_CONSTANT | T_STRING)) cf_error("String constant expected");
|
||||
$$ = SYM_VAL($1).s;
|
||||
}
|
||||
;
|
||||
|
||||
opttext:
|
||||
TEXT
|
||||
| /* empty */ { $$ = NULL; }
|
||||
;
|
||||
|
||||
|
||||
CF_CODE
|
||||
|
||||
CF_END
|
||||
|
209
conf/flowspec.Y
Normal file
209
conf/flowspec.Y
Normal file
@ -0,0 +1,209 @@
|
||||
/*
|
||||
* BIRD -- Flow specification (RFC 5575) grammar
|
||||
*
|
||||
* (c) 2016 CZ.NIC z.s.p.o.
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
CF_HDR
|
||||
|
||||
#define PARSER 1
|
||||
|
||||
#include "nest/bird.h"
|
||||
#include "lib/flowspec.h"
|
||||
|
||||
|
||||
CF_DEFINES
|
||||
|
||||
struct flow_builder *this_flow;
|
||||
|
||||
|
||||
CF_DECLS
|
||||
|
||||
%type <i32> flow_num_op flow_srcdst flow_logic_op flow_num_type_ flow_frag_val flow_neg
|
||||
%type <net_ptr> net_flow4_ net_flow6_ net_flow_
|
||||
|
||||
CF_KEYWORDS(FLOW4, FLOW6, DST, SRC, PROTO, NEXT, HEADER, DPORT, SPORT, ICMP,
|
||||
TYPE, CODE, TCP, FLAGS, LENGTH, DSCP, DONT_FRAGMENT, IS_FRAGMENT,
|
||||
FIRST_FRAGMENT, LAST_FRAGMENT, FRAGMENT, LABEL, OFFSET)
|
||||
|
||||
|
||||
CF_GRAMMAR
|
||||
|
||||
/* Network Flow Specification */
|
||||
|
||||
flow_num_op:
|
||||
TRUE { $$ = FLOW_OP_TRUE; }
|
||||
| '=' { $$ = FLOW_OP_EQ; }
|
||||
| NEQ { $$ = FLOW_OP_NEQ; }
|
||||
| '<' { $$ = FLOW_OP_LT; }
|
||||
| LEQ { $$ = FLOW_OP_LEQ; }
|
||||
| '>' { $$ = FLOW_OP_GT; }
|
||||
| GEQ { $$ = FLOW_OP_GEQ; }
|
||||
| FALSE { $$ = FLOW_OP_FALSE; }
|
||||
;
|
||||
|
||||
flow_logic_op:
|
||||
OR { $$ = FLOW_OP_OR; }
|
||||
| AND { $$ = FLOW_OP_AND; }
|
||||
;
|
||||
|
||||
flow_num_type_:
|
||||
PROTO { $$ = FLOW_TYPE_IP_PROTOCOL; }
|
||||
| NEXT HEADER { $$ = FLOW_TYPE_NEXT_HEADER; }
|
||||
| PORT { $$ = FLOW_TYPE_PORT; }
|
||||
| DPORT { $$ = FLOW_TYPE_DST_PORT; }
|
||||
| SPORT { $$ = FLOW_TYPE_SRC_PORT; }
|
||||
| ICMP TYPE { $$ = FLOW_TYPE_ICMP_TYPE; }
|
||||
| ICMP CODE { $$ = FLOW_TYPE_ICMP_CODE; }
|
||||
| LENGTH { $$ = FLOW_TYPE_PACKET_LENGTH; }
|
||||
| DSCP { $$ = FLOW_TYPE_DSCP; }
|
||||
;
|
||||
|
||||
flow_num_type: flow_num_type_{ flow_builder_set_type(this_flow, $1); };
|
||||
flow_flag_type: TCP FLAGS { flow_builder_set_type(this_flow, FLOW_TYPE_TCP_FLAGS); };
|
||||
flow_frag_type: FRAGMENT { flow_builder_set_type(this_flow, FLOW_TYPE_FRAGMENT); };
|
||||
flow_label_type: LABEL { flow_builder_set_type(this_flow, FLOW_TYPE_LABEL); };
|
||||
|
||||
flow_srcdst:
|
||||
DST { $$ = FLOW_TYPE_DST_PREFIX; }
|
||||
| SRC { $$ = FLOW_TYPE_SRC_PREFIX; }
|
||||
;
|
||||
|
||||
flow_num_opts:
|
||||
flow_num_op expr {
|
||||
flow_check_cf_value_length(this_flow, $2);
|
||||
flow_builder_add_op_val(this_flow, $1, $2);
|
||||
}
|
||||
| flow_num_opts flow_logic_op flow_num_op expr {
|
||||
flow_check_cf_value_length(this_flow, $4);
|
||||
flow_builder_add_op_val(this_flow, $2 | $3, $4);
|
||||
}
|
||||
| flow_num_opt_ext
|
||||
| flow_num_opts OR flow_num_opt_ext
|
||||
;
|
||||
|
||||
flow_num_opt_ext_expr:
|
||||
expr {
|
||||
flow_check_cf_value_length(this_flow, $1);
|
||||
flow_builder_add_op_val(this_flow, FLOW_OP_EQ, $1);
|
||||
}
|
||||
| expr DDOT expr {
|
||||
flow_check_cf_value_length(this_flow, $1);
|
||||
flow_check_cf_value_length(this_flow, $3);
|
||||
flow_builder_add_op_val(this_flow, FLOW_OP_GEQ, $1);
|
||||
flow_builder_add_op_val(this_flow, FLOW_OP_AND | FLOW_OP_LEQ, $3);
|
||||
}
|
||||
;
|
||||
|
||||
flow_num_opt_ext:
|
||||
flow_num_opt_ext_expr
|
||||
| flow_num_opt_ext ',' flow_num_opt_ext_expr
|
||||
;
|
||||
|
||||
flow_bmk_opts:
|
||||
flow_neg expr '/' expr {
|
||||
flow_check_cf_bmk_values(this_flow, $1, $2, $4);
|
||||
flow_builder_add_val_mask(this_flow, $1, $2, $4);
|
||||
}
|
||||
| flow_bmk_opts flow_logic_op flow_neg expr '/' expr {
|
||||
flow_check_cf_bmk_values(this_flow, $3, $4, $6);
|
||||
flow_builder_add_val_mask(this_flow, $2 | $3, $4, $6);
|
||||
}
|
||||
| flow_bmk_opts ',' flow_neg expr '/' expr {
|
||||
flow_check_cf_bmk_values(this_flow, $3, $4, $6);
|
||||
flow_builder_add_val_mask(this_flow, 0x40 | $3, $4, $6); /* AND */
|
||||
}
|
||||
;
|
||||
|
||||
flow_neg:
|
||||
/* empty */ { $$ = 0x00; }
|
||||
| '!' { $$ = 0x02; }
|
||||
;
|
||||
|
||||
flow_frag_val:
|
||||
DONT_FRAGMENT { $$ = 1; }
|
||||
| IS_FRAGMENT { $$ = 2; }
|
||||
| FIRST_FRAGMENT { $$ = 4; }
|
||||
| LAST_FRAGMENT { $$ = 8; }
|
||||
;
|
||||
|
||||
flow_frag_opts:
|
||||
flow_neg flow_frag_val {
|
||||
flow_builder_add_val_mask(this_flow, 0, ($1 ? 0 : $2), $2);
|
||||
}
|
||||
| flow_frag_opts flow_logic_op flow_neg flow_frag_val {
|
||||
flow_builder_add_val_mask(this_flow, $2, ($3 ? 0 : $4), $4);
|
||||
}
|
||||
| flow_frag_opts ',' flow_neg flow_frag_val {
|
||||
flow_builder_add_val_mask(this_flow, 0x40, ($3 ? 0 : $4), $4); /* AND */
|
||||
}
|
||||
;
|
||||
|
||||
flow4_item:
|
||||
flow_srcdst net_ip {
|
||||
flow_builder_set_type(this_flow, $1);
|
||||
flow_builder4_add_pfx(this_flow, (net_addr_ip4 *) &($2));
|
||||
}
|
||||
| flow_num_type flow_num_opts
|
||||
| flow_flag_type flow_bmk_opts
|
||||
| flow_frag_type flow_frag_opts
|
||||
;
|
||||
|
||||
flow6_item:
|
||||
flow_srcdst net_ip6 {
|
||||
flow_builder_set_type(this_flow, $1);
|
||||
flow_builder6_add_pfx(this_flow, (net_addr_ip6 *) &($2), 0);
|
||||
}
|
||||
| flow_srcdst net_ip6 OFFSET NUM {
|
||||
if ($4 > $2.pxlen)
|
||||
cf_error("Prefix offset is higher than prefix length");
|
||||
flow_builder_set_type(this_flow, $1);
|
||||
flow_builder6_add_pfx(this_flow, (net_addr_ip6 *) &($2), $4);
|
||||
}
|
||||
| flow_num_type flow_num_opts
|
||||
| flow_flag_type flow_bmk_opts
|
||||
| flow_frag_type flow_frag_opts
|
||||
| flow_label_type flow_bmk_opts
|
||||
;
|
||||
|
||||
flow4_opts:
|
||||
/* empty */
|
||||
| flow4_opts flow4_item ';'
|
||||
;
|
||||
|
||||
flow6_opts:
|
||||
/* empty */
|
||||
| flow6_opts flow6_item ';'
|
||||
;
|
||||
|
||||
flow_builder_init:
|
||||
{
|
||||
if (this_flow == NULL)
|
||||
this_flow = flow_builder_init(&root_pool);
|
||||
else
|
||||
flow_builder_clear(this_flow);
|
||||
};
|
||||
|
||||
flow_builder_set_ipv4: { this_flow->ipv6 = 0; };
|
||||
flow_builder_set_ipv6: { this_flow->ipv6 = 1; };
|
||||
|
||||
net_flow4_: FLOW4 '{' flow_builder_init flow_builder_set_ipv4 flow4_opts '}'
|
||||
{
|
||||
$$ = (net_addr *) flow_builder4_finalize(this_flow, cfg_mem);
|
||||
flow4_validate_cf((net_addr_flow4 *) $$);
|
||||
};
|
||||
|
||||
net_flow6_: FLOW6 '{' flow_builder_init flow_builder_set_ipv6 flow6_opts '}'
|
||||
{
|
||||
$$ = (net_addr *) flow_builder6_finalize(this_flow, cfg_mem);
|
||||
flow6_validate_cf((net_addr_flow6 *) $$);
|
||||
};
|
||||
|
||||
net_flow_: net_flow4_ | net_flow6_ ;
|
||||
|
||||
|
||||
CF_CODE
|
||||
|
||||
CF_END
|
@ -10,6 +10,9 @@ m4_divert(-1)m4_dnl
|
||||
m4_define(CF_CLI, `m4_divert(0){ "m4_translit($1,A-Z,a-z)", "$3", "$4", 1 },
|
||||
m4_divert(-1)')
|
||||
|
||||
m4_define(CF_CLI_CMD, `m4_divert(0){ "m4_translit($1,A-Z,a-z)", "$2", "$3", 1 },
|
||||
m4_divert(-1)')
|
||||
|
||||
m4_define(CF_CLI_HELP, `m4_divert(0){ "m4_translit($1,A-Z,a-z)", "$2", "$3", 0 },
|
||||
m4_divert(-1)')
|
||||
|
||||
|
@ -34,9 +34,11 @@ m4_define(CF_CLI, `CF_KEYWORDS(m4_translit($1, [[ ]], [[,]]))
|
||||
')
|
||||
|
||||
# Enums are translated to C initializers: use CF_ENUM(typename, prefix, values)
|
||||
m4_define(CF_enum, `m4_divert(1){ "CF_enum_prefix[[]]$1", -((CF_enum_type<<16) | CF_enum_prefix[[]]$1), NULL },
|
||||
# For different prefix: CF_ENUM_PX(typename, external prefix, C prefix, values)
|
||||
m4_define(CF_enum, `m4_divert(1){ "CF_enum_prefix_ext[[]]$1", -((CF_enum_type<<16) | CF_enum_prefix_int[[]]$1), NULL },
|
||||
m4_divert(-1)')
|
||||
m4_define(CF_ENUM, `m4_define([[CF_enum_type]],$1)m4_define([[CF_enum_prefix]],$2)CF_iterate([[CF_enum]], [[m4_shift(m4_shift($@))]])DNL')
|
||||
m4_define(CF_ENUM, `m4_define([[CF_enum_type]],$1)m4_define([[CF_enum_prefix_ext]],$2)m4_define([[CF_enum_prefix_int]],$2)CF_iterate([[CF_enum]], [[m4_shift(m4_shift($@))]])DNL')
|
||||
m4_define(CF_ENUM_PX, `m4_define([[CF_enum_type]],$1)m4_define([[CF_enum_prefix_ext]],$2)m4_define([[CF_enum_prefix_int]],$3)CF_iterate([[CF_enum]], [[m4_shift(m4_shift(m4_shift($@)))]])DNL')
|
||||
|
||||
# After all configuration templates end, we generate the
|
||||
m4_m4wrap(`
|
||||
|
@ -34,20 +34,17 @@ m4_define(CF_keywd, `m4_ifdef([[CF_tok_$1]],,[[m4_define([[CF_tok_$1]],1)m4_defi
|
||||
m4_define(CF_KEYWORDS, `m4_define([[CF_toks]],[[]])CF_iterate([[CF_keywd]], [[$@]])m4_ifelse(CF_toks,,,%token[[]]CF_toks
|
||||
)DNL')
|
||||
|
||||
# Dynamic syntax rules
|
||||
m4_define(CF_dyn_rules,)
|
||||
m4_define(CF_ADDTO, `m4_define([[CF_rule_$1]],m4_ifdef([[CF_rule_$1]],CF_rule_$1 | ,[[m4_define([[CF_dyn_rules]],CF_dyn_rules[[CF_RULE($1)
|
||||
]])]])$2)DNL')
|
||||
|
||||
# CLI commands
|
||||
m4_define(CF_CLI, `m4_define([[CF_cmd]], cmd_[[]]m4_translit($1, [[ ]], _))DNL
|
||||
m4_divert(2)CF_KEYWORDS(m4_translit($1, [[ ]], [[,]]))
|
||||
m4_divert(3)CF_ADDTO(cli_cmd, CF_cmd)
|
||||
m4_divert(3)cli_cmd: CF_cmd
|
||||
CF_cmd: $1 $2 END')
|
||||
m4_define(CF_CLI_CMD, `')
|
||||
m4_define(CF_CLI_HELP, `')
|
||||
|
||||
# ENUM declarations are ignored
|
||||
m4_define(CF_ENUM, `')
|
||||
m4_define(CF_ENUM_PX, `')
|
||||
|
||||
# After all configuration templates end, we finally generate the grammar file.
|
||||
m4_m4wrap(`
|
||||
@ -61,10 +58,6 @@ m4_undivert(2)DNL
|
||||
%%
|
||||
m4_undivert(3)DNL
|
||||
|
||||
/* Dynamic rules */
|
||||
|
||||
m4_define(CF_RULE, [[$1: CF_rule_$1 ;]])
|
||||
CF_dyn_rules
|
||||
%%
|
||||
m4_undivert(4)DNL
|
||||
')
|
||||
|
472
configure.ac
Normal file
472
configure.ac
Normal file
@ -0,0 +1,472 @@
|
||||
dnl ** This is a configure script template for BIRD
|
||||
dnl ** Process it with autoconf to get ./configure
|
||||
dnl ** (c) 1999--2000 Martin Mares <mj@ucw.cz>
|
||||
|
||||
AC_INIT
|
||||
AC_CONFIG_SRCDIR([conf/confbase.Y])
|
||||
AC_CONFIG_AUX_DIR([tools])
|
||||
|
||||
AC_ARG_ENABLE([client],
|
||||
[AS_HELP_STRING([--enable-client], [enable building of BIRD client @<:@yes@:>@])],
|
||||
[],
|
||||
[enable_client=yes]
|
||||
)
|
||||
|
||||
AC_ARG_ENABLE([debug],
|
||||
[AS_HELP_STRING([--enable-debug], [enable internal debugging routines @<:@no@:>@])],
|
||||
[],
|
||||
[enable_debug=no]
|
||||
)
|
||||
|
||||
AC_ARG_ENABLE([debug-generated],
|
||||
[AS_HELP_STRING([--enable-debug-generated], [enable this to abstain from generating #line @<:@no@:>@])],
|
||||
[],
|
||||
[enable_debug_generated=no]
|
||||
)
|
||||
|
||||
AC_ARG_ENABLE([debug-expensive],
|
||||
[AS_HELP_STRING([--enable-debug-expensive], [enable expensive consistency checks (implies --enable-debug) @<:@no@:>@])],
|
||||
[],
|
||||
[enable_debug_expensive=no]
|
||||
)
|
||||
|
||||
AC_ARG_ENABLE([memcheck],
|
||||
[AS_HELP_STRING([--enable-memcheck], [check memory allocations when debugging @<:@yes@:>@])],
|
||||
[],
|
||||
[enable_memcheck=yes]
|
||||
)
|
||||
|
||||
AC_ARG_ENABLE([pthreads],
|
||||
[AS_HELP_STRING([--enable-pthreads], [enable POSIX threads support @<:@try@:>@])],
|
||||
[],
|
||||
[enable_pthreads=try]
|
||||
)
|
||||
|
||||
AC_ARG_ENABLE([libssh],
|
||||
[AS_HELP_STRING([--enable-libssh], [enable LibSSH support in RPKI @<:@try@:>@])],
|
||||
[],
|
||||
[enable_libssh=try]
|
||||
)
|
||||
|
||||
AC_ARG_ENABLE([mpls-kernel],
|
||||
[AS_HELP_STRING([--enable-mpls-kernel], [enable MPLS support in kernel protocol @<:@try@:>@])],
|
||||
[],
|
||||
[enable_mpls_kernel=try]
|
||||
)
|
||||
|
||||
AC_ARG_WITH([protocols],
|
||||
[AS_HELP_STRING([--with-protocols=LIST], [include specified routing protocols @<:@all@:>@])],
|
||||
[],
|
||||
[with_protocols="all"]
|
||||
)
|
||||
|
||||
AC_ARG_WITH([sysconfig],
|
||||
[AS_HELP_STRING([--with-sysconfig=FILE], [use specified BIRD system configuration file])]
|
||||
)
|
||||
|
||||
AC_ARG_WITH([runtimedir],
|
||||
[AS_HELP_STRING([--with-runtimedir=PATH], [run-state data, obsolete variant of --runstatedir])],
|
||||
[runstatedir="$with_runtimedir"]
|
||||
)
|
||||
|
||||
AC_ARG_WITH([iproutedir],
|
||||
[AS_HELP_STRING([--with-iproutedir=PATH], [path to iproute2 config files @<:@/etc/iproute2@:>@])],
|
||||
[given_iproutedir="yes"]
|
||||
)
|
||||
|
||||
AC_ARG_VAR([FLEX], [location of the Flex program])
|
||||
AC_ARG_VAR([BISON], [location of the Bison program])
|
||||
AC_ARG_VAR([M4], [location of the M4 program])
|
||||
|
||||
if test "$enable_debug_expensive" = yes; then
|
||||
enable_debug=yes
|
||||
fi
|
||||
|
||||
if test "$srcdir" = . ; then
|
||||
# Building in current directory => create obj directory holding all objects
|
||||
objdir=obj
|
||||
else
|
||||
# Building in separate directory
|
||||
objdir=.
|
||||
fi
|
||||
|
||||
exedir=.
|
||||
|
||||
AC_SUBST([objdir])
|
||||
AC_SUBST([exedir])
|
||||
AC_SUBST([srcdir])
|
||||
|
||||
# Workaround for older Autoconfs that do not define runstatedir
|
||||
AS_IF([test -z "${runstatedir}"], [runstatedir='${localstatedir}/run'])
|
||||
AC_SUBST([runstatedir])
|
||||
|
||||
CONFIG_FILE="\$(sysconfdir)/bird.conf"
|
||||
AC_SUBST([CONFIG_FILE])
|
||||
|
||||
CONTROL_SOCKET="\$(runstatedir)/bird.ctl"
|
||||
AC_SUBST([CONTROL_SOCKET])
|
||||
|
||||
AC_SEARCH_LIBS([clock_gettime], [rt posix4],
|
||||
[],
|
||||
[AC_MSG_ERROR([Function clock_gettime not available.])]
|
||||
)
|
||||
|
||||
AC_CANONICAL_HOST
|
||||
|
||||
# Store this value because ac_test_CFLAGS is overwritten by AC_PROG_CC
|
||||
if test "$ac_test_CFLAGS" != set ; then
|
||||
bird_cflags_default=yes
|
||||
fi
|
||||
|
||||
AC_PROG_CC
|
||||
AC_PROG_CC_C99
|
||||
if test -z "$GCC" ; then
|
||||
AC_MSG_ERROR([This program requires the GNU C Compiler.])
|
||||
fi
|
||||
|
||||
BIRD_CHECK_THREAD_LOCAL
|
||||
if test "$bird_cv_thread_local" = yes ; then
|
||||
AC_DEFINE([HAVE_THREAD_LOCAL], [1], [Define to 1 if _Thread_local is available])
|
||||
fi
|
||||
|
||||
if test "$enable_pthreads" != no ; then
|
||||
BIRD_CHECK_PTHREADS
|
||||
|
||||
if test "$bird_cv_lib_pthreads" = yes ; then
|
||||
AC_DEFINE([USE_PTHREADS], [1], [Define to 1 if pthreads are enabled])
|
||||
CFLAGS="$CFLAGS -pthread"
|
||||
LDFLAGS="$LDFLAGS -pthread"
|
||||
proto_bfd=bfd
|
||||
elif test "$enable_pthreads" = yes ; then
|
||||
AC_MSG_ERROR([POSIX threads not available.])
|
||||
fi
|
||||
|
||||
if test "$enable_pthreads" = try ; then
|
||||
enable_pthreads="$bird_cv_lib_pthreads"
|
||||
fi
|
||||
fi
|
||||
|
||||
# This is assumed to be necessary for proper BIRD build
|
||||
CFLAGS="$CFLAGS -fno-strict-aliasing -fno-strict-overflow"
|
||||
|
||||
if test "$bird_cflags_default" = yes ; then
|
||||
BIRD_CHECK_GCC_OPTION([bird_cv_c_option_wno_pointer_sign], [-Wno-pointer-sign], [-Wall])
|
||||
BIRD_CHECK_GCC_OPTION([bird_cv_c_option_wno_missing_init], [-Wno-missing-field-initializers], [-Wall -Wextra])
|
||||
|
||||
if test "$enable_debug" = no; then
|
||||
BIRD_CHECK_LTO
|
||||
fi
|
||||
|
||||
if test "$bird_cv_c_lto" = yes; then
|
||||
CFLAGS="$CFLAGS -flto"
|
||||
LDFLAGS="$LDFLAGS -flto=4 -g"
|
||||
else
|
||||
LDFLAGS="$LDFLAGS -g"
|
||||
fi
|
||||
|
||||
CFLAGS="$CFLAGS -Wall -Wextra -Wstrict-prototypes -Wno-parentheses"
|
||||
BIRD_ADD_GCC_OPTION([bird_cv_c_option_wno_pointer_sign], [-Wno-pointer-sign])
|
||||
BIRD_ADD_GCC_OPTION([bird_cv_c_option_wno_missing_init], [-Wno-missing-field-initializers])
|
||||
fi
|
||||
|
||||
|
||||
AC_MSG_CHECKING([CFLAGS])
|
||||
AC_MSG_RESULT([$CFLAGS])
|
||||
|
||||
AC_MSG_CHECKING([LDFLAGS])
|
||||
AC_MSG_RESULT([$LDFLAGS])
|
||||
|
||||
AC_PROG_CPP
|
||||
AC_PROG_INSTALL
|
||||
AC_PROG_RANLIB
|
||||
AC_CHECK_PROG([FLEX], [flex], [flex])
|
||||
AC_CHECK_PROG([BISON], [bison], [bison])
|
||||
AC_CHECK_PROGS([M4], [gm4 m4])
|
||||
|
||||
test -z "$FLEX" && AC_MSG_ERROR([Flex is missing.])
|
||||
test -z "$BISON" && AC_MSG_ERROR([Bison is missing.])
|
||||
test -z "$M4" && AC_MSG_ERROR([M4 is missing.])
|
||||
|
||||
AC_MSG_CHECKING([bison version])
|
||||
BIRD_CHECK_BISON_VERSION(BISON_VERSION)
|
||||
AC_MSG_RESULT([$BISON_VERSION])
|
||||
if test "$bird_bison_synclines" = yes && test "$enable_debug_generated" = no; then
|
||||
M4FLAGS="$M4FLAGS -s"
|
||||
fi
|
||||
|
||||
if test "$bird_bison_enhanced_error" = yes; then
|
||||
BISONFLAGS="$BISONFLAGS -Dparse.lac=full -Dparse.error=verbose"
|
||||
fi
|
||||
|
||||
AC_SUBST([M4FLAGS])
|
||||
AC_SUBST([BISONFLAGS])
|
||||
|
||||
BIRD_CHECK_PROG_FLAVOR_GNU([$M4],
|
||||
[],
|
||||
[AC_MSG_ERROR([Provided M4 is not GNU M4.])]
|
||||
)
|
||||
|
||||
if test -n "$with_sysconfig" -a "$with_sysconfig" != no ; then
|
||||
if test -f $with_sysconfig ; then
|
||||
sysdesc=$with_sysconfig
|
||||
else
|
||||
sysdesc=$srcdir/sysdep/cf/$with_sysconfig
|
||||
if ! test -f $sysdesc ; then
|
||||
sysdesc=$sysdesc.h
|
||||
fi
|
||||
fi
|
||||
elif test -f sysconfig.h ; then
|
||||
sysdesc=sysconfig
|
||||
else
|
||||
case "$host_os" in
|
||||
linux*)
|
||||
sysdesc=linux
|
||||
default_iproutedir="/etc/iproute2"
|
||||
;;
|
||||
freebsd*)
|
||||
sysdesc=bsd
|
||||
CPPFLAGS="$CPPFLAGS -I/usr/local/include"
|
||||
LDFLAGS="$LDFLAGS -L/usr/local/lib"
|
||||
;;
|
||||
kfreebsd*)
|
||||
sysdesc=bsd
|
||||
;;
|
||||
netbsd*)
|
||||
sysdesc=bsd
|
||||
CPPFLAGS="$CPPFLAGS -I/usr/pkg/include"
|
||||
LDFLAGS="$LDFLAGS -L/usr/pkg/lib -R/usr/pkg/lib"
|
||||
;;
|
||||
openbsd*)
|
||||
sysdesc=bsd
|
||||
;;
|
||||
dragonfly*)
|
||||
sysdesc=bsd
|
||||
;;
|
||||
*)
|
||||
AC_MSG_ERROR([Cannot determine correct system configuration. Please use --with-sysconfig to set it manually.])
|
||||
;;
|
||||
esac
|
||||
sysdesc=$srcdir/sysdep/cf/$sysdesc.h
|
||||
fi
|
||||
AC_MSG_CHECKING([which OS configuration should we use])
|
||||
AC_MSG_RESULT([$sysdesc])
|
||||
if ! test -f $sysdesc ; then
|
||||
AC_MSG_ERROR([The system configuration file is missing.])
|
||||
fi
|
||||
sysname=`echo $sysdesc | sed 's/\.h$//'`
|
||||
AC_DEFINE_UNQUOTED([SYSCONF_INCLUDE], ["$sysdesc"], [Which sysdep header to include])
|
||||
|
||||
AC_MSG_CHECKING([system-dependent directories])
|
||||
sysdep_dirs="`sed <$sysdesc '/^Link: /!d;s/^Link: \(.*\)$/\1/' | tr '\012' ' '`"
|
||||
AC_MSG_RESULT([$sysdep_dirs])
|
||||
AC_SUBST([sysdep_dirs])
|
||||
|
||||
if test "$with_iproutedir" = no ; then with_iproutedir= ; fi
|
||||
|
||||
if test -n "$given_iproutedir"
|
||||
then iproutedir=$with_iproutedir
|
||||
else iproutedir=$default_iproutedir
|
||||
fi
|
||||
|
||||
AC_SUBST([iproutedir])
|
||||
|
||||
DAEMON_LIBS=
|
||||
AC_SUBST(DAEMON_LIBS)
|
||||
|
||||
if test "$enable_libssh" != no ; then
|
||||
AC_CHECK_HEADER([libssh/libssh.h], [true], [fail=yes], [ ])
|
||||
AC_CHECK_LIB([ssh], [ssh_connect], [true], [fail=yes])
|
||||
|
||||
if test "$fail" != yes ; then
|
||||
AC_DEFINE([HAVE_LIBSSH], [1], [Define to 1 if you have the `ssh' library (-lssh).])
|
||||
DAEMON_LIBS="-lssh $DAEMON_LIBS"
|
||||
enable_libssh=yes
|
||||
else
|
||||
if test "$enable_libssh" = yes ; then
|
||||
AC_MSG_ERROR([LibSSH not available.])
|
||||
else
|
||||
enable_libssh=no
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "$enable_mpls_kernel" != no ; then
|
||||
BIRD_CHECK_MPLS_KERNEL
|
||||
|
||||
if test "$bird_cv_mpls_kernel" = yes ; then
|
||||
AC_DEFINE([HAVE_MPLS_KERNEL], [1], [Define to 1 if kernel is MPLS capable])
|
||||
elif test "$enable_mpls_kernel" = yes ; then
|
||||
AC_MSG_ERROR([Kernel MPLS support not found.])
|
||||
fi
|
||||
|
||||
if test "$enable_mpls_kernel" = try ; then
|
||||
enable_mpls_kernel="$bird_cv_mpls_kernel"
|
||||
fi
|
||||
fi
|
||||
|
||||
all_protocols="$proto_bfd babel bgp mrt ospf perf pipe radv rip rpki static"
|
||||
|
||||
all_protocols=`echo $all_protocols | sed 's/ /,/g'`
|
||||
|
||||
if test "$with_protocols" = all ; then
|
||||
with_protocols="$all_protocols"
|
||||
fi
|
||||
|
||||
AH_TEMPLATE([CONFIG_BABEL], [Babel protocol])
|
||||
AH_TEMPLATE([CONFIG_BFD], [BFD protocol])
|
||||
AH_TEMPLATE([CONFIG_BGP], [BGP protocol])
|
||||
AH_TEMPLATE([CONFIG_MRT], [MRT protocol])
|
||||
AH_TEMPLATE([CONFIG_OSPF], [OSPF protocol])
|
||||
AH_TEMPLATE([CONFIG_PIPE], [Pipe protocol])
|
||||
AH_TEMPLATE([CONFIG_RADV], [RAdv protocol])
|
||||
AH_TEMPLATE([CONFIG_RIP], [RIP protocol])
|
||||
AH_TEMPLATE([CONFIG_RPKI], [RPKI protocol])
|
||||
AH_TEMPLATE([CONFIG_STATIC], [Static protocol])
|
||||
|
||||
AC_MSG_CHECKING([protocols])
|
||||
protocols=`echo "$with_protocols" | sed 's/,/ /g'`
|
||||
if test "$protocols" = no ; then protocols= ; fi
|
||||
for a in $protocols ; do
|
||||
if ! test -f $srcdir/proto/$a/Makefile ; then
|
||||
AC_MSG_RESULT([failed])
|
||||
AC_MSG_ERROR([Requested protocol $a not found])
|
||||
fi
|
||||
AC_DEFINE_UNQUOTED([CONFIG_`echo $a | tr 'a-z' 'A-Z'`])
|
||||
done
|
||||
AC_MSG_RESULT([ok])
|
||||
AC_SUBST([protocols])
|
||||
|
||||
case $sysdesc in
|
||||
*/linux*)
|
||||
AC_CHECK_HEADER([linux/rtnetlink.h],
|
||||
[],
|
||||
[AC_MSG_ERROR([Appropriate version of Linux kernel headers not found.])],
|
||||
[
|
||||
dnl Some older versions of Linux kernel headers require these includes
|
||||
#include <asm/types.h>
|
||||
#include <sys/socket.h>
|
||||
]
|
||||
)
|
||||
;;
|
||||
esac
|
||||
|
||||
AC_CHECK_HEADERS_ONCE([alloca.h syslog.h])
|
||||
AC_CHECK_MEMBERS([struct sockaddr.sa_len], [], [], [#include <sys/socket.h>])
|
||||
|
||||
AC_C_BIGENDIAN(
|
||||
[AC_DEFINE([CPU_BIG_ENDIAN], [1], [Define to 1 if cpu is big endian])],
|
||||
[AC_DEFINE([CPU_LITTLE_ENDIAN], [1], [Define to 1 if cpu is little endian])],
|
||||
[AC_MSG_ERROR([Cannot determine CPU endianity.])]
|
||||
)
|
||||
|
||||
BIRD_CHECK_ANDROID_GLOB
|
||||
if test "$bird_cv_lib_glob" = no ; then
|
||||
AC_MSG_ERROR([glob.h not found.])
|
||||
elif test "$bird_cv_lib_glob" != yes ; then
|
||||
LIBS="$LIBS $bird_cv_lib_glob"
|
||||
fi
|
||||
|
||||
BIRD_CHECK_ANDROID_LOG
|
||||
if test "$bird_cv_lib_log" = no ; then
|
||||
AC_MSG_ERROR([don't know how to link syslog.])
|
||||
elif test "$bird_cv_lib_log" != yes ; then
|
||||
LIBS="$LIBS $bird_cv_lib_log"
|
||||
fi
|
||||
|
||||
if test "$enable_debug" = yes ; then
|
||||
AC_DEFINE([DEBUGGING], [1], [Define to 1 if debugging is enabled])
|
||||
LDFLAGS="$LDFLAGS -rdynamic"
|
||||
CFLAGS="$CFLAGS -O0 -ggdb -g3"
|
||||
|
||||
BIRD_CHECK_GCC_OPTION([bird_cv_c_option_dwarf4], [-gdwarf-4], [])
|
||||
BIRD_ADD_GCC_OPTION([bird_cv_c_option_dwarf4], [-gdwarf-4])
|
||||
|
||||
AC_CHECK_HEADER([execinfo.h],
|
||||
[
|
||||
AC_DEFINE([HAVE_EXECINFO_H], [1], [Define to 1 if you have the <execinfo.h> header file.])
|
||||
AC_SEARCH_LIBS([backtrace], [execinfo],
|
||||
[],
|
||||
[AC_MSG_ERROR([Function backtrace not available.])]
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
if test "$enable_memcheck" = yes ; then
|
||||
AC_CHECK_LIB([dmalloc], [dmalloc_debug])
|
||||
if test $ac_cv_lib_dmalloc_dmalloc_debug != yes ; then
|
||||
AC_CHECK_LIB([efence], [malloc])
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "enable_debug_expensive" = yes ; then
|
||||
AC_DEFINE([ENABLE_EXPENSIVE_CHECKS], [1], [Define to 1 if you want to run expensive consistency checks.])
|
||||
fi
|
||||
fi
|
||||
|
||||
CLIENT=birdcl
|
||||
CLIENT_LIBS=
|
||||
if test "$enable_client" = yes ; then
|
||||
CLIENT="$CLIENT birdc"
|
||||
BASE_LIBS="$LIBS"
|
||||
LIBS=""
|
||||
|
||||
AC_CHECK_HEADERS([curses.h],
|
||||
[],
|
||||
[AC_MSG_ERROR([The client requires ncurses library. Either install the library or use --disable-client to compile without the client.])],
|
||||
[AC_INCLUDES_DEFAULT]
|
||||
)
|
||||
|
||||
AC_SEARCH_LIBS([tgetent], [tinfo tinfow ncurses curses termcap],
|
||||
[TINFO_LIBS="$LIBS"; LIBS=""],
|
||||
[AC_MSG_ERROR([The client requires ncurses library. Either install the library or use --disable-client to compile without the client.])],
|
||||
)
|
||||
|
||||
AC_CHECK_HEADERS([readline/readline.h readline/history.h],
|
||||
[],
|
||||
[AC_MSG_ERROR([The client requires GNU Readline library. Either install the library or use --disable-client to compile without the client.])],
|
||||
[AC_INCLUDES_DEFAULT]
|
||||
)
|
||||
|
||||
AC_SEARCH_LIBS([rl_callback_read_char], [readline],
|
||||
[READLINE_LIBS="$LIBS"; LIBS=""],
|
||||
[AC_MSG_ERROR([The client requires GNU Readline library. Either install the library or use --disable-client to compile without the client.])],
|
||||
[$TINFO_LIBS]
|
||||
)
|
||||
|
||||
AC_CHECK_LIB([readline], [rl_crlf],
|
||||
[AC_DEFINE([HAVE_RL_CRLF], [1], [Define to 1 if you have rl_crlf()])],
|
||||
[],
|
||||
[$TINFO_LIBS]
|
||||
)
|
||||
|
||||
AC_CHECK_LIB([readline], [rl_ding],
|
||||
[AC_DEFINE([HAVE_RL_DING], [1], [Define to 1 if you have rl_ding()])],
|
||||
[],
|
||||
[$TINFO_LIBS]
|
||||
)
|
||||
|
||||
LIBS="$BASE_LIBS"
|
||||
CLIENT_LIBS="$READLINE_LIBS $TINFO_LIBS"
|
||||
fi
|
||||
AC_SUBST([CLIENT])
|
||||
AC_SUBST([CLIENT_LIBS])
|
||||
|
||||
mkdir -p $objdir/sysdep
|
||||
AC_CONFIG_HEADERS([$objdir/sysdep/autoconf.h:sysdep/autoconf.h.in])
|
||||
AC_CONFIG_FILES([Makefile:Makefile.in])
|
||||
AC_OUTPUT
|
||||
|
||||
AC_MSG_RESULT()
|
||||
AC_MSG_RESULT([BIRD was configured with the following options:])
|
||||
AC_MSG_RESULT([ Source directory: $srcdir])
|
||||
AC_MSG_RESULT([ Object directory: $objdir])
|
||||
AC_MSG_RESULT([ Iproute2 directory: $iproutedir])
|
||||
AC_MSG_RESULT([ System configuration: $sysdesc])
|
||||
AC_MSG_RESULT([ Debugging: $enable_debug])
|
||||
AC_MSG_RESULT([ POSIX threads: $enable_pthreads])
|
||||
AC_MSG_RESULT([ Routing protocols: $protocols])
|
||||
AC_MSG_RESULT([ LibSSH support in RPKI: $enable_libssh])
|
||||
AC_MSG_RESULT([ Kernel MPLS support: $enable_mpls_kernel])
|
||||
AC_MSG_RESULT([ Client: $enable_client])
|
||||
|
||||
rm -f $objdir/.*-stamp
|
262
configure.in
262
configure.in
@ -1,262 +0,0 @@
|
||||
dnl ** This is a configure script template for BIRD
|
||||
dnl ** Process it with autoconf to get ./configure
|
||||
dnl ** (c) 1999--2000 Martin Mares <mj@ucw.cz>
|
||||
|
||||
AC_REVISION($Id$)
|
||||
AC_INIT(conf/confbase.Y)
|
||||
AC_CONFIG_AUX_DIR(tools)
|
||||
|
||||
AC_ARG_ENABLE(debug,[ --enable-debug enable internal debugging routines (default: disabled)],,enable_debug=no)
|
||||
AC_ARG_ENABLE(memcheck,[ --enable-memcheck check memory allocations when debugging (default: enabled)],,enable_memcheck=yes)
|
||||
AC_ARG_ENABLE(client,[ --enable-client enable building of BIRD client (default: enabled)],,enable_client=yes)
|
||||
AC_ARG_ENABLE(ipv6,[ --enable-ipv6 enable building of IPv6 version (default: disabled)],,enable_ipv6=no)
|
||||
AC_ARG_WITH(sysconfig,[ --with-sysconfig=FILE use specified BIRD system configuration file])
|
||||
AC_ARG_WITH(protocols,[ --with-protocols=LIST include specified routing protocols (default: all)],,[with_protocols="all"])
|
||||
AC_ARG_WITH(sysinclude,[ --with-sysinclude=PATH search for system includes on specified place])
|
||||
AC_ARG_WITH(iproutedir,[ --with-iproutedir=PATH path to iproute2 config files (default: /etc/iproute2)],[given_iproutedir="yes"])
|
||||
AC_ARG_VAR([FLEX], [location of the Flex program])
|
||||
AC_ARG_VAR([BISON], [location of the Bison program])
|
||||
AC_ARG_VAR([M4], [location of the M4 program])
|
||||
|
||||
if test "$srcdir" = . ; then
|
||||
# Building in current directory => create obj directory holding all objects
|
||||
objdir=obj
|
||||
mkdir -p obj
|
||||
srcdir_rel=..
|
||||
makefiles="Makefile:tools/Makefile-top.in obj/Makefile:tools/Makefile.in obj/Rules:tools/Rules.in"
|
||||
exedir=..
|
||||
else
|
||||
# Building in separate directory
|
||||
objdir=.
|
||||
srcdir_rel=$srcdir
|
||||
makefiles="Makefile:tools/Makefile.in Rules:tools/Rules.in"
|
||||
exedir=.
|
||||
fi
|
||||
case $srcdir_rel in
|
||||
/*) srcdir_rel_mf=$srcdir_rel ;;
|
||||
*) srcdir_rel_mf="\$(root-rel)$srcdir_rel" ;;
|
||||
esac
|
||||
AC_SUBST(objdir)
|
||||
AC_SUBST(exedir)
|
||||
AC_SUBST(srcdir_rel_mf)
|
||||
|
||||
if test "$enable_ipv6" = yes ; then
|
||||
ip=ipv6
|
||||
SUFFIX6=6
|
||||
all_protocols=bgp,ospf,pipe,radv,rip,static
|
||||
else
|
||||
ip=ipv4
|
||||
SUFFIX6=""
|
||||
all_protocols=bgp,ospf,pipe,rip,static
|
||||
fi
|
||||
|
||||
if test "$with_protocols" = all ; then
|
||||
with_protocols="$all_protocols"
|
||||
fi
|
||||
|
||||
AC_SEARCH_LIBS(clock_gettime,[c rt posix4])
|
||||
|
||||
AC_CANONICAL_HOST
|
||||
|
||||
# Store this value because ac_test_CFLAGS is overwritten by AC_PROG_CC
|
||||
if test "$ac_test_CFLAGS" != set ; then
|
||||
bird_cflags_default=yes
|
||||
fi
|
||||
|
||||
AC_PROG_CC
|
||||
if test -z "$GCC" ; then
|
||||
AC_MSG_ERROR([This program requires the GNU C Compiler.])
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING([what CFLAGS should we use])
|
||||
if test "$bird_cflags_default" = yes ; then
|
||||
BIRD_CHECK_GCC_OPTIONS
|
||||
|
||||
CFLAGS="$CFLAGS -Wall -Wstrict-prototypes -Wno-parentheses"
|
||||
if test "$bird_cv_c_option_no_pointer_sign" = yes ; then
|
||||
CFLAGS="$CFLAGS -Wno-pointer-sign"
|
||||
fi
|
||||
fi
|
||||
AC_MSG_RESULT($CFLAGS)
|
||||
|
||||
|
||||
AC_PROG_CPP
|
||||
AC_PROG_INSTALL
|
||||
AC_PROG_RANLIB
|
||||
AC_CHECK_PROG(FLEX, flex, flex)
|
||||
AC_CHECK_PROG(BISON, bison, bison)
|
||||
AC_CHECK_PROGS(M4, gm4 m4)
|
||||
|
||||
test -z "$FLEX" && AC_MSG_ERROR([Flex is missing.])
|
||||
test -z "$BISON" && AC_MSG_ERROR([Bison is missing.])
|
||||
test -z "$M4" && AC_MSG_ERROR([M4 is missing.])
|
||||
BIRD_CHECK_PROG_FLAVOR_GNU([$M4], , [AC_MSG_ERROR([Provided M4 is not GNU M4.])])
|
||||
|
||||
if test -n "$with_sysconfig" -a "$with_sysconfig" != no ; then
|
||||
if test -f $with_sysconfig ; then
|
||||
sysdesc=$with_sysconfig
|
||||
else
|
||||
sysdesc=$srcdir/sysdep/cf/$with_sysconfig
|
||||
if ! test -f $sysdesc ; then
|
||||
sysdesc=$sysdesc.h
|
||||
fi
|
||||
fi
|
||||
elif test -f sysconfig.h ; then
|
||||
sysdesc=sysconfig
|
||||
else
|
||||
case "$ip:$host_os" in
|
||||
ipv4:linux*) BIRD_CHECK_LINUX_VERSION
|
||||
default_iproutedir="/etc/iproute2"
|
||||
case $bird_cv_sys_linux_version in
|
||||
1.*|2.0.*) sysdesc=linux-20 ;;
|
||||
*) sysdesc=linux-22 ;;
|
||||
esac
|
||||
;;
|
||||
ipv6:linux*) BIRD_CHECK_LINUX_VERSION
|
||||
default_iproutedir="/etc/iproute2"
|
||||
case $bird_cv_sys_linux_version in
|
||||
1.*|2.0.*) AC_MSG_ERROR([This version of Linux doesn't support IPv6.]) ;;
|
||||
*) sysdesc=linux-v6 ;;
|
||||
esac
|
||||
;;
|
||||
ipv6:netbsd*) sysdesc=bsd-v6
|
||||
CPPFLAGS="$CPPFLAGS -I/usr/pkg/include"
|
||||
LDFLAGS="$LDFLAGS -L/usr/pkg/lib -R/usr/pkg/lib"
|
||||
;;
|
||||
ipv4:netbsd*) sysdesc=bsd
|
||||
CPPFLAGS="$CPPFLAGS -I/usr/pkg/include"
|
||||
LDFLAGS="$LDFLAGS -L/usr/pkg/lib -R/usr/pkg/lib"
|
||||
;;
|
||||
ipv6:freebsd*) sysdesc=bsd-v6
|
||||
;;
|
||||
ipv4:freebsd*) sysdesc=bsd
|
||||
;;
|
||||
ipv6:kfreebsd*) sysdesc=bsd-v6
|
||||
;;
|
||||
ipv4:kfreebsd*) sysdesc=bsd
|
||||
;;
|
||||
ipv6:openbsd*) sysdesc=bsd-v6
|
||||
;;
|
||||
ipv4:openbsd*) sysdesc=bsd
|
||||
;;
|
||||
*) AC_MSG_ERROR([Cannot determine correct system configuration. Please use --with-sysconfig to set it manually.])
|
||||
;;
|
||||
esac
|
||||
sysdesc=$srcdir/sysdep/cf/$sysdesc.h
|
||||
fi
|
||||
AC_MSG_CHECKING([which OS configuration should we use])
|
||||
AC_MSG_RESULT($sysdesc)
|
||||
if ! test -f $sysdesc ; then
|
||||
AC_MSG_ERROR([The system configuration file is missing.])
|
||||
fi
|
||||
sysname=`echo $sysdesc | sed 's/\.h$//'`
|
||||
AC_DEFINE_UNQUOTED(SYSCONF_INCLUDE, "$sysdesc")
|
||||
|
||||
AC_MSG_CHECKING([system-dependent directories])
|
||||
sysdep_dirs="`sed <$sysdesc '/^Link: /!d;s/^Link: \(.*\)$/\1/' | tr '\012' ' '` lib"
|
||||
AC_MSG_RESULT($sysdep_dirs)
|
||||
AC_SUBST(sysdep_dirs)
|
||||
|
||||
if test "$with_iproutedir" = no ; then with_iproutedir= ; fi
|
||||
|
||||
if test -n "$given_iproutedir"
|
||||
then iproutedir=$with_iproutedir
|
||||
else iproutedir=$default_iproutedir
|
||||
fi
|
||||
|
||||
AC_SUBST(iproutedir)
|
||||
|
||||
AC_MSG_CHECKING([protocols])
|
||||
protocols=`echo "$with_protocols" | sed 's/,/ /g'`
|
||||
if test "$protocols" = no ; then protocols= ; fi
|
||||
for a in $protocols ; do
|
||||
if ! test -f $srcdir/proto/$a/Makefile ; then
|
||||
AC_MSG_RESULT(failed)
|
||||
AC_MSG_ERROR([Requested protocol $a not found.])
|
||||
fi
|
||||
AC_DEFINE_UNQUOTED(CONFIG_`echo $a | tr 'a-z' 'A-Z'`)
|
||||
done
|
||||
AC_MSG_RESULT(ok)
|
||||
AC_SUBST(protocols)
|
||||
|
||||
case $sysdesc in
|
||||
*/linux-22*|*/linux-v6*)
|
||||
AC_CHECK_HEADER(linux/rtnetlink.h,,[AC_MSG_ERROR([Appropriate version of Linux kernel headers not found.])],[
|
||||
#include <asm/types.h>
|
||||
#include <sys/socket.h>
|
||||
])
|
||||
;;
|
||||
esac
|
||||
|
||||
AC_CHECK_HEADER(syslog.h, [AC_DEFINE(HAVE_SYSLOG)])
|
||||
AC_CHECK_HEADER(alloca.h, [AC_DEFINE(HAVE_ALLOCA_H)])
|
||||
AC_MSG_CHECKING(whether 'struct sockaddr' has sa_len)
|
||||
AC_TRY_COMPILE([#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
], [static struct sockaddr sa; int i = sizeof(sa.sa_len);],
|
||||
[AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(HAVE_SIN_LEN,,sin_len)],
|
||||
AC_MSG_RESULT(no))
|
||||
|
||||
AC_C_BIGENDIAN([AC_DEFINE(CPU_BIG_ENDIAN)], [AC_DEFINE(CPU_LITTLE_ENDIAN)],
|
||||
[AC_MSG_ERROR([Cannot determine CPU endianity.])])
|
||||
|
||||
BIRD_CHECK_INTEGERS
|
||||
BIRD_CHECK_STRUCT_ALIGN
|
||||
BIRD_CHECK_TIME_T
|
||||
BIRD_CHECK_STRUCT_IP_MREQN
|
||||
|
||||
if test "$enable_debug" = yes ; then
|
||||
AC_DEFINE(DEBUGGING)
|
||||
if test "$enable_memcheck" = yes ; then
|
||||
AC_CHECK_LIB(dmalloc, dmalloc_debug)
|
||||
if test $ac_cv_lib_dmalloc_dmalloc_debug != yes ; then
|
||||
AC_CHECK_LIB(efence, malloc)
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
CLIENT=
|
||||
CLIENT_LIBS=
|
||||
if test "$enable_client" = yes ; then
|
||||
CLIENT=client
|
||||
AC_CHECK_LIB(history, add_history, CLIENT_LIBS="-lhistory")
|
||||
AC_CHECK_LIB(ncurses, tgetent, USE_TERMCAP_LIB=-lncurses,
|
||||
AC_CHECK_LIB(curses, tgetent, USE_TERMCAP_LIB=-lcurses,
|
||||
AC_CHECK_LIB(tinfow, tgetent, USE_TERMCAP_LIB=-ltinfow,
|
||||
AC_CHECK_LIB(tinfo, tgetent, USE_TERMCAP_LIB=-ltinfo
|
||||
AC_CHECK_LIB(termcap, tgetent, USE_TERMCAP_LIB=-ltermcap)))))
|
||||
AC_CHECK_LIB(readline, rl_callback_read_char, CLIENT_LIBS="-lreadline $CLIENT_LIBS $USE_TERMCAP_LIB",
|
||||
AC_MSG_ERROR([[The client requires GNU readline library 2.1 or newer. Either install the library or use --disable-client to compile without the client.]]), $USE_TERMCAP_LIB)
|
||||
AC_CHECK_LIB(readline, rl_crlf, AC_DEFINE(HAVE_RL_CRLF),,$USE_TERMCAP_LIB)
|
||||
AC_CHECK_LIB(readline, rl_ding, AC_DEFINE(HAVE_RL_DING),,$USE_TERMCAP_LIB)
|
||||
fi
|
||||
AC_SUBST(CLIENT)
|
||||
AC_SUBST(CLIENT_LIBS)
|
||||
AC_SUBST(SUFFIX6)
|
||||
|
||||
mkdir -p $objdir/sysdep
|
||||
AC_CONFIG_HEADERS([$objdir/sysdep/autoconf.h:sysdep/autoconf.h.in])
|
||||
AC_CONFIG_COMMANDS([merge],[[export CPP="$CPP"
|
||||
$srcdir/tools/mergedirs $srcdir $srcdir_rel $objdir $sysdep_dirs]],
|
||||
[[srcdir=$srcdir]
|
||||
[srcdir_rel=$srcdir_rel]
|
||||
[objdir=$objdir]
|
||||
[sysdep_dirs="$sysdep_dirs"]])
|
||||
AC_CONFIG_FILES($makefiles)
|
||||
AC_OUTPUT
|
||||
|
||||
rm -f $objdir/sysdep/paths.h
|
||||
|
||||
cat >&AC_FD_MSG <<EOF
|
||||
|
||||
BIRD was configured with the following options:
|
||||
Source directory: $srcdir
|
||||
Object directory: $objdir
|
||||
Iproute2 directory: $iproutedir
|
||||
System configuration: $sysdesc
|
||||
Debugging: $enable_debug
|
||||
Routing protocols: $protocols
|
||||
Client: $enable_client
|
||||
EOF
|
||||
rm -f $objdir/.*-stamp
|
@ -242,6 +242,7 @@ sub process_options
|
||||
# removes iso-entites sub directory after doing make install.)
|
||||
#
|
||||
$ENV{SGML_CATALOG_FILES} .= (defined $ENV{SGML_CATALOG_FILES} ? ":" : "") .
|
||||
"$main::prefix/share/sgml/sgml-iso-entities-8879.1986/catalog:" .
|
||||
"$main::prefix/share/sgml/entities/sgml-iso-entities-8879.1986/catalog";
|
||||
$ENV{SGML_CATALOG_FILES} .= ":$main::DataDir/linuxdoc-tools.catalog";
|
||||
$ENV{SGML_CATALOG_FILES} .= ":$main::/etc/sgml.catalog";
|
||||
@ -372,6 +373,8 @@ sub process_file
|
||||
}
|
||||
}
|
||||
#
|
||||
|
||||
local $ENV{PATH} = "$ENV{PATH}:/usr/lib/linuxdoc-tools";
|
||||
my($precmd) = "|sgmlpre output=$global->{format} $global->{define}";
|
||||
|
||||
#
|
||||
|
71
doc/Makefile
71
doc/Makefile
@ -1,46 +1,49 @@
|
||||
root-rel=../
|
||||
dir-name=doc
|
||||
|
||||
ifneq ($(wildcard ../Rules),)
|
||||
include ../Rules
|
||||
else
|
||||
srcdir=$(shell cd $(root-rel) ; pwd)
|
||||
srcdir_abs=$(srcdir)
|
||||
endif
|
||||
|
||||
# Force rebuilds
|
||||
.PHONY: prog.sgml bird.sgml
|
||||
.PHONY: progspell docs progdocs userdocs
|
||||
|
||||
doc-srcdir := $(shell cd $(s) && pwd)
|
||||
sgml2 := $(doc-srcdir)/sgml2
|
||||
|
||||
docs: progdocs userdocs
|
||||
progdocs: prog.html prog.ps
|
||||
userdocs: bird.html bird.ps
|
||||
|
||||
prog.sgml:
|
||||
$(srcdir)/tools/progdoc $(srcdir_abs)
|
||||
doc-fmt = $(1): $(o)prog.$(1) $(o)bird.$(1)
|
||||
$(call doc-fmt,html)
|
||||
$(call doc-fmt,dvi)
|
||||
$(call doc-fmt,ps)
|
||||
$(call doc-fmt,pdf)
|
||||
|
||||
%.html: %.sgml
|
||||
./sgml2html $<
|
||||
progdocs: $(o)prog.html $(o)prog.pdf
|
||||
userdocs: $(o)bird.html $(o)bird.pdf
|
||||
progspell: $(o)prog.spell
|
||||
|
||||
%.dvi: %.tex
|
||||
latex $<
|
||||
latex $<
|
||||
$(o)prog.sgml: $(srcdir)/tools/progdoc $(objdir)/.dir-stamp
|
||||
$(srcdir)/tools/progdoc $(srcdir) $@
|
||||
|
||||
%.ps: %.dvi
|
||||
$(o)%.sgml: $(s)%.sgml $(objdir)/.dir-stamp
|
||||
cp $< $@
|
||||
|
||||
$(o)%.html: $(o)%.sgml
|
||||
cd $(dir $@) && $(sgml2)html $(notdir $<)
|
||||
|
||||
$(o)%.tex: $(o)%.sgml
|
||||
cd $(dir $@) && $(sgml2)latex --output=tex $(notdir $<)
|
||||
|
||||
$(o)%.dvi: $(o)%.tex
|
||||
cd $(dir $@) && TEXINPUTS=$(TEXINPUTS):$(doc-srcdir)/tex latex $(notdir $<)
|
||||
cd $(dir $@) && TEXINPUTS=$(TEXINPUTS):$(doc-srcdir)/tex latex $(notdir $<)
|
||||
|
||||
$(o)%.ps: $(o)%.dvi
|
||||
dvips -D600 -ta4 -o $@ $<
|
||||
|
||||
%.tex: %.sgml
|
||||
./sgml2latex --output=tex $<
|
||||
$(o)%.pdf: $(o)%.tex
|
||||
TEXINPUTS=$(TEXINPUTS):$(doc-srcdir)/tex pdflatex -output-directory=$(dir $@) $<
|
||||
TEXINPUTS=$(TEXINPUTS):$(doc-srcdir)/tex pdflatex -output-directory=$(dir $@) $<
|
||||
|
||||
%.txt: %.sgml
|
||||
./sgml2txt $<
|
||||
$(o)%.txt: $(o)%.sgml
|
||||
cd $(dir $@) && $(sgml2)txt $(notdir $<)
|
||||
|
||||
progspell: prog.sgml
|
||||
sed -f prog-spell.sed <prog.sgml >prog.spell
|
||||
ispell prog.spell
|
||||
$(o)prog.spell: $(o)prog.sgml $(s)prog-spell.sed
|
||||
sed -f $(lastword $^) <$< >$@
|
||||
ispell $@
|
||||
|
||||
clean:
|
||||
rm -f *.tex *.dvi *.log *.txt *.aux *.toc *.spell
|
||||
rm -f prog.sgml
|
||||
|
||||
distclean: clean
|
||||
rm -f *.html *.ps
|
||||
$(call clean,prog.spell $(addprefix *.,html dvi ps pdf sgml tex txt aux log toc))
|
||||
|
@ -1,204 +1,204 @@
|
||||
/*
|
||||
* This is an example configuration file.
|
||||
*/
|
||||
|
||||
# Yes, even shell-like comments work...
|
||||
# This is a basic configuration file, which contains boilerplate options and
|
||||
# some basic examples. It allows the BIRD daemon to start but will not cause
|
||||
# anything else to happen.
|
||||
#
|
||||
# Please refer to the BIRD User's Guide documentation, which is also available
|
||||
# online at http://bird.network.cz/ in HTML format, for more information on
|
||||
# configuring BIRD and adding routing protocols.
|
||||
|
||||
# Configure logging
|
||||
#log syslog { debug, trace, info, remote, warning, error, auth, fatal, bug };
|
||||
#log stderr all;
|
||||
#log "tmp" all;
|
||||
log syslog all;
|
||||
# log "/var/log/bird.log" { debug, trace, info, remote, warning, error, auth, fatal, bug };
|
||||
|
||||
# Override router ID
|
||||
#router id 198.51.100.1;
|
||||
# Set router ID. It is a unique identification of your router, usually one of
|
||||
# IPv4 addresses of the router. It is recommended to configure it explicitly.
|
||||
# router id 198.51.100.1;
|
||||
|
||||
# You can define your own symbols...
|
||||
#define xyzzy = (120+10);
|
||||
#define '1a-a1' = (30+40);
|
||||
# Turn on global debugging of all protocols (all messages or just selected classes)
|
||||
# debug protocols all;
|
||||
# debug protocols { events, states };
|
||||
|
||||
# Define a route filter...
|
||||
#filter test_filter {
|
||||
# if net ~ 10.0.0.0/16 then accept;
|
||||
# else reject;
|
||||
#}
|
||||
# Turn on internal watchdog
|
||||
# watchdog warning 5 s;
|
||||
# watchdog timeout 30 s;
|
||||
|
||||
#filter sink { reject; }
|
||||
#filter okay { accept; }
|
||||
# You can define your own constants
|
||||
# define my_asn = 65000;
|
||||
# define my_addr = 198.51.100.1;
|
||||
|
||||
#include "filters.conf";
|
||||
# Tables master4 and master6 are defined by default
|
||||
# ipv4 table master4;
|
||||
# ipv6 table master6;
|
||||
|
||||
# Define another routing table
|
||||
#table testable;
|
||||
# Define more tables, e.g. for policy routing or as MRIB
|
||||
# ipv4 table mrib4;
|
||||
# ipv6 table mrib6;
|
||||
|
||||
# Turn on global debugging of all protocols
|
||||
#debug protocols all;
|
||||
|
||||
# The direct protocol automatically generates device routes to
|
||||
# all network interfaces. Can exist in as many instances as you wish
|
||||
# if you want to populate multiple routing tables with device routes.
|
||||
#protocol direct {
|
||||
# interface "-eth*", "*"; # Restrict network interfaces it works with
|
||||
#}
|
||||
|
||||
# This pseudo-protocol performs synchronization between BIRD's routing
|
||||
# tables and the kernel. If your kernel supports multiple routing tables
|
||||
# (as Linux 2.2.x does), you can run multiple instances of the kernel
|
||||
# protocol and synchronize different kernel tables with different BIRD tables.
|
||||
protocol kernel {
|
||||
# learn; # Learn all alien routes from the kernel
|
||||
persist; # Don't remove routes on bird shutdown
|
||||
scan time 20; # Scan kernel routing table every 20 seconds
|
||||
# import none; # Default is import all
|
||||
export all; # Default is export none
|
||||
# kernel table 5; # Kernel table to synchronize with (default: main)
|
||||
}
|
||||
|
||||
# This pseudo-protocol watches all interface up/down events.
|
||||
# The Device protocol is not a real routing protocol. It does not generate any
|
||||
# routes and it only serves as a module for getting information about network
|
||||
# interfaces from the kernel. It is necessary in almost any configuration.
|
||||
protocol device {
|
||||
scan time 10; # Scan interfaces every 10 seconds
|
||||
}
|
||||
|
||||
# Static routes (again, there can be multiple instances, so that you
|
||||
# can disable/enable various groups of static routes on the fly).
|
||||
# The direct protocol is not a real routing protocol. It automatically generates
|
||||
# direct routes to all network interfaces. Can exist in as many instances as you
|
||||
# wish if you want to populate multiple routing tables with direct routes.
|
||||
protocol direct {
|
||||
disabled; # Disable by default
|
||||
ipv4; # Connect to default IPv4 table
|
||||
ipv6; # ... and to default IPv6 table
|
||||
}
|
||||
|
||||
# The Kernel protocol is not a real routing protocol. Instead of communicating
|
||||
# with other routers in the network, it performs synchronization of BIRD
|
||||
# routing tables with the OS kernel. One instance per table.
|
||||
protocol kernel {
|
||||
ipv4 { # Connect protocol to IPv4 table by channel
|
||||
# table master4; # Default IPv4 table is master4
|
||||
# import all; # Import to table, default is import all
|
||||
export all; # Export to protocol. default is export none
|
||||
};
|
||||
# learn; # Learn alien routes from the kernel
|
||||
# kernel table 10; # Kernel table to synchronize with (default: main)
|
||||
}
|
||||
|
||||
# Another instance for IPv6, skipping default options
|
||||
protocol kernel {
|
||||
ipv6 { export all; };
|
||||
}
|
||||
|
||||
# Static routes (Again, there can be multiple instances, for different address
|
||||
# families and to disable/enable various groups of static routes on the fly).
|
||||
protocol static {
|
||||
# disabled; # Disable by default
|
||||
# table testable; # Connect to a non-default table
|
||||
# preference 1000; # Default preference of routes
|
||||
# debug { states, routes, filters, interfaces, events, packets };
|
||||
# debug all;
|
||||
# route 0.0.0.0/0 via 198.51.100.13;
|
||||
# route 198.51.100.0/25 reject;
|
||||
# route 10.0.0.0/8 reject;
|
||||
# route 10.1.1.0:255.255.255.0 via 198.51.100.3;
|
||||
# route 10.1.2.0:255.255.255.0 via 198.51.100.3;
|
||||
# route 10.1.3.0:255.255.255.0 via 198.51.100.4;
|
||||
# route 10.2.0.0/24 via "arc0";
|
||||
ipv4; # Again, IPv4 channel with default options
|
||||
|
||||
# route 0.0.0.0/0 via 198.51.100.10;
|
||||
# route 192.0.2.0/24 blackhole;
|
||||
# route 10.0.0.0/8 unreachable;
|
||||
# route 10.2.0.0/24 via "eth0";
|
||||
# # Static routes can be defined with optional attributes
|
||||
# route 10.1.1.0/24 via 198.51.100.3 { rip_metric = 3; };
|
||||
# route 10.1.2.0/24 via 198.51.100.3 { ospf_metric1 = 100; };
|
||||
# route 10.1.3.0/24 via 198.51.100.4 { ospf_metric2 = 100; };
|
||||
}
|
||||
|
||||
# Pipe protocol connects two routing tables... Beware of loops.
|
||||
#protocol pipe {
|
||||
# peer table testable;
|
||||
# Define what routes do we export to this protocol / import from it.
|
||||
# import all; # default is all
|
||||
# export all; # default is none
|
||||
# import none; # If you wish to disable imports
|
||||
# import filter test_filter; # Use named filter
|
||||
# import where source = RTS_DEVICE; # Use explicit filter
|
||||
#}
|
||||
# Pipe protocol connects two routing tables. Beware of loops.
|
||||
# protocol pipe {
|
||||
# table master4; # No ipv4/ipv6 channel definition like in other protocols
|
||||
# peer table mrib4;
|
||||
# import all; # Direction peer table -> table
|
||||
# export all; # Direction table -> peer table
|
||||
# }
|
||||
|
||||
# RIP aka Rest In Pieces...
|
||||
#protocol rip MyRIP { # You can also use an explicit name
|
||||
# preference xyzzy;
|
||||
# debug all;
|
||||
# port 1520;
|
||||
# period 7;
|
||||
# infinity 16;
|
||||
# garbage time 60;
|
||||
# interface "*" { mode broadcast; };
|
||||
# honor neighbor; # To whom do we agree to send the routing table
|
||||
# honor always;
|
||||
# honor never;
|
||||
# passwords {
|
||||
# password "nazdar";
|
||||
# RIP example, both RIP and RIPng are supported
|
||||
# protocol rip {
|
||||
# ipv4 {
|
||||
# # Export direct, static routes and ones from RIP itself
|
||||
# import all;
|
||||
# export where source ~ [ RTS_DEVICE, RTS_STATIC, RTS_RIP ];
|
||||
# };
|
||||
# authentication none;
|
||||
# import filter { print "importing"; accept; };
|
||||
# export filter { print "exporting"; accept; };
|
||||
#}
|
||||
# interface "eth*" {
|
||||
# update time 10; # Default period is 30
|
||||
# timeout time 60; # Default timeout is 180
|
||||
# authentication cryptographic; # No authentication by default
|
||||
# password "hello" { algorithm hmac sha256; }; # Default is MD5
|
||||
# };
|
||||
# }
|
||||
|
||||
#protocol ospf MyOSPF {
|
||||
# tick 2;
|
||||
# rfc1583compat yes;
|
||||
# area 0.0.0.0 {
|
||||
# stub no;
|
||||
# OSPF example, both OSPFv2 and OSPFv3 are supported
|
||||
# protocol ospf v3 {
|
||||
# ipv6 {
|
||||
# import all;
|
||||
# export where source = RTS_STATIC;
|
||||
# };
|
||||
# area 0 {
|
||||
# interface "eth*" {
|
||||
# hello 9;
|
||||
# retransmit 6;
|
||||
# cost 10;
|
||||
# transmit delay 5;
|
||||
# dead count 5;
|
||||
# wait 50;
|
||||
# type broadcast;
|
||||
# authentication simple;
|
||||
# password "pass";
|
||||
# type broadcast; # Detected by default
|
||||
# cost 10; # Interface metric
|
||||
# hello 5; # Default hello perid 10 is too long
|
||||
# };
|
||||
# interface "arc0" {
|
||||
# rx buffer large;
|
||||
# type nonbroadcast;
|
||||
# poll 14;
|
||||
# dead 75;
|
||||
# neighbors {
|
||||
# 10.1.1.2 eligible;
|
||||
# 10.1.1.4;
|
||||
# };
|
||||
# strict nonbroadcast yes;
|
||||
# interface "tun*" {
|
||||
# type ptp; # PtP mode, avoids DR selection
|
||||
# cost 100; # Interface metric
|
||||
# hello 5; # Default hello perid 10 is too long
|
||||
# };
|
||||
# interface "xxx0" {
|
||||
# passwords {
|
||||
# password "abc" {
|
||||
# id 1;
|
||||
# generate to "22-04-2003 11:00:06";
|
||||
# accept to "17-01-2004 12:01:05";
|
||||
# };
|
||||
# password "def" {
|
||||
# id 2;
|
||||
# generate from "22-04-2003 11:00:07";
|
||||
# accept from "17-01-2003 12:01:05";
|
||||
# };
|
||||
# };
|
||||
# authentication cryptographic;
|
||||
# interface "dummy0" {
|
||||
# stub; # Stub interface, just propagate it
|
||||
# };
|
||||
# };
|
||||
# area 20 {
|
||||
# stub 1;
|
||||
# interface "ppp1" {
|
||||
# hello 8;
|
||||
# authentication none;
|
||||
# };
|
||||
# interface "fr*";
|
||||
# virtual link 192.168.0.1 {
|
||||
# password "sdsdffsdfg";
|
||||
# authentication cryptographic;
|
||||
# };
|
||||
# };
|
||||
#}
|
||||
|
||||
|
||||
#protocol bgp {
|
||||
# disabled;
|
||||
# Define simple filter as an example for BGP import filter
|
||||
# See https://gitlab.labs.nic.cz/labs/bird/wikis/BGP_filtering for more examples
|
||||
# filter rt_import
|
||||
# {
|
||||
# if bgp_path.first != 64496 then accept;
|
||||
# if bgp_path.len > 64 then accept;
|
||||
# if bgp_next_hop != from then accept;
|
||||
# reject;
|
||||
# }
|
||||
|
||||
# BGP example, explicit name 'uplink1' is used instead of default 'bgp1'
|
||||
# protocol bgp uplink1 {
|
||||
# description "My BGP uplink";
|
||||
# local as 65000;
|
||||
# neighbor 198.51.100.130 as 64496;
|
||||
# multihop;
|
||||
# hold time 240;
|
||||
# startup hold time 240;
|
||||
# connect retry time 120;
|
||||
# keepalive time 80; # defaults to hold time / 3
|
||||
# start delay time 5; # How long do we wait before initial connect
|
||||
# error wait time 60, 300;# Minimum and maximum time we wait after an error (when consecutive
|
||||
# # errors occur, we increase the delay exponentially ...
|
||||
# error forget time 300; # ... until this timeout expires)
|
||||
# disable after error; # Disable the protocol automatically when an error occurs
|
||||
# next hop self; # Disable next hop processing and always advertise our local address as nexthop
|
||||
# path metric 1; # Prefer routes with shorter paths (like Cisco does)
|
||||
# default bgp_med 0; # MED value we use for comparison when none is defined
|
||||
# default bgp_local_pref 0; # The same for local preference
|
||||
# source address 198.51.100.14; # What local address we use for the TCP connection
|
||||
# local 198.51.100.1 as 65000;
|
||||
# neighbor 198.51.100.10 as 64496;
|
||||
# hold time 90; # Default is 240
|
||||
# password "secret"; # Password used for MD5 authentication
|
||||
# rr client; # I am a route reflector and the neighor is my client
|
||||
# rr cluster id 1.0.0.1; # Use this value for cluster id instead of my router id
|
||||
# export where source=RTS_STATIC;
|
||||
# export filter {
|
||||
# if source = RTS_STATIC then {
|
||||
# bgp_community = -empty-; bgp_community = add(bgp_community,(65000,5678));
|
||||
# bgp_origin = 0;
|
||||
# bgp_community = -empty-; bgp_community.add((65000,5678));
|
||||
# if (65000,64501) ~ bgp_community then
|
||||
# bgp_community.add((0, 1));
|
||||
# if bgp_path ~ [= 65000 =] then
|
||||
# bgp_path.prepend(65000);
|
||||
# accept;
|
||||
# }
|
||||
# reject;
|
||||
#
|
||||
# ipv4 { # regular IPv4 unicast (1/1)
|
||||
# import filter rt_import;
|
||||
# export where source ~ [ RTS_STATIC, RTS_BGP ];
|
||||
# };
|
||||
#
|
||||
# ipv6 { # regular IPv6 unicast (2/1)
|
||||
# import filter rt_import;
|
||||
# export filter { # The same as 'where' expression above
|
||||
# if source ~ [ RTS_STATIC, RTS_BGP ]
|
||||
# then accept;
|
||||
# else reject;
|
||||
# };
|
||||
# };
|
||||
#
|
||||
# ipv4 multicast { # IPv4 multicast topology (1/2)
|
||||
# table mrib4; # explicit IPv4 table
|
||||
# import filter rt_import;
|
||||
# export all;
|
||||
# };
|
||||
#
|
||||
# ipv6 multicast { # IPv6 multicast topology (2/2)
|
||||
# table mrib6; # explicit IPv6 table
|
||||
# import filter rt_import;
|
||||
# export all;
|
||||
# };
|
||||
#}
|
||||
|
||||
# Template example. Using templates to define IBGP route reflector clients.
|
||||
# template bgp rr_clients {
|
||||
# local 10.0.0.1 as 65000;
|
||||
# neighbor as 65000;
|
||||
# rr client;
|
||||
# rr cluster id 1.0.0.1;
|
||||
#
|
||||
# ipv4 {
|
||||
# import all;
|
||||
# export where source = RTS_BGP;
|
||||
# };
|
||||
#
|
||||
# ipv6 {
|
||||
# import all;
|
||||
# export where source = RTS_BGP;
|
||||
# };
|
||||
# }
|
||||
#
|
||||
# protocol bgp client1 from rr_clients {
|
||||
# neighbor 10.0.1.1;
|
||||
# }
|
||||
#
|
||||
# protocol bgp client2 from rr_clients {
|
||||
# neighbor 10.0.2.1;
|
||||
# }
|
||||
#
|
||||
# protocol bgp client3 from rr_clients {
|
||||
# neighbor 10.0.3.1;
|
||||
# }
|
||||
|
332
doc/bird.conf.example2
Normal file
332
doc/bird.conf.example2
Normal file
@ -0,0 +1,332 @@
|
||||
/*
|
||||
* This is an example configuration file for MP-BGP setting
|
||||
*/
|
||||
|
||||
|
||||
log "bird.log" all;
|
||||
# debug protocols all;
|
||||
|
||||
router id 192.168.1.1;
|
||||
|
||||
ipv4 table master4;
|
||||
ipv6 table master6;
|
||||
|
||||
ipv4 table mcast4;
|
||||
ipv6 table mcast6;
|
||||
|
||||
ipv4 table mtab4;
|
||||
ipv6 table mtab6;
|
||||
|
||||
vpn4 table vpntab4;
|
||||
vpn6 table vpntab6;
|
||||
|
||||
vpn4 table vpn4mc;
|
||||
vpn6 table vpn6mc;
|
||||
|
||||
flow4 table flowtab4;
|
||||
flow6 table flowtab6;
|
||||
|
||||
|
||||
protocol device {
|
||||
}
|
||||
|
||||
protocol kernel kernel4 {
|
||||
ipv4 {
|
||||
export all;
|
||||
};
|
||||
}
|
||||
|
||||
protocol kernel kernel6 {
|
||||
ipv6 {
|
||||
export all;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
protocol static static4 {
|
||||
ipv4;
|
||||
|
||||
route 10.10.0.0/24 via 192.168.1.2;
|
||||
route 10.10.1.0/24 via 192.168.1.2 { bgp_large_community.add((10,20,30)); bgp_large_community.add((10,(20*3),10)); };
|
||||
}
|
||||
|
||||
protocol static static6 {
|
||||
ipv6;
|
||||
|
||||
route 2001:db8:10:10::/64 via 2001:db8:1:1::10;
|
||||
route 2001:db8:10:11::/64 via 2001:db8:1:1::10;
|
||||
|
||||
route 2001:db8:1:1::/64 via fe80::ec9b:67ff:fe60:fd5d % ve1;
|
||||
}
|
||||
|
||||
# VPNv4 routes with MPLS labels
|
||||
protocol static statvpn4 {
|
||||
vpn4;
|
||||
|
||||
route 10:10 10.20.0.0/24 via 192.168.1.2 mpls 210;
|
||||
route 10:10 10.20.1.0/24 via 192.168.1.2 mpls 210;
|
||||
route 10:20 10.20.0.0/24 via 192.168.1.2 mpls 220;
|
||||
route 10:20 10.20.1.0/24 via 192.168.1.2 mpls 220;
|
||||
}
|
||||
|
||||
protocol static statvpn6 {
|
||||
vpn6;
|
||||
|
||||
route 10:10 2001:db8:20:10::/64 via 2001:db8:1:1::10 mpls 200/210;
|
||||
route 10:10 2001:db8:20:11::/64 via 2001:db8:1:1::10 mpls 200/210;
|
||||
route 10:20 2001:db8:20:10::/64 via 2001:db8:1:1::10 mpls 200/220;
|
||||
route 10:20 2001:db8:20:11::/64 via 2001:db8:1:1::10 mpls 200/220;
|
||||
}
|
||||
|
||||
# RFC 5575 flow specification
|
||||
protocol static flowstat4 {
|
||||
flow4;
|
||||
|
||||
route flow4 {
|
||||
dst 10.0.0.0/8;
|
||||
proto = 23;
|
||||
dport > 24 && < 30 || 40..50,60..70,80;
|
||||
sport > 24 && < 30 || = 40 || 50,60..70,80;
|
||||
icmp type 80;
|
||||
icmp code 90;
|
||||
tcp flags 0x03/0x0f;
|
||||
length 2048..65535;
|
||||
dscp = 63;
|
||||
fragment dont_fragment, is_fragment || !first_fragment;
|
||||
};
|
||||
|
||||
route flow4 {
|
||||
dst 11.0.0.0/8;
|
||||
proto = 0x12;
|
||||
sport > 0x5678 && < 0x9abc || 0xdef0 || 0x1234,0x5678,0x9abc..0xdef0;
|
||||
dport = 50;
|
||||
tcp flags 0x000/0xf00;
|
||||
};
|
||||
|
||||
route flow4 {
|
||||
dst 12.0.0.0/32;
|
||||
tcp flags ! 0/0x999;
|
||||
};
|
||||
|
||||
route flow4 {
|
||||
dst 220.0.254.0/24;
|
||||
tcp flags 0x99/0x999;
|
||||
};
|
||||
|
||||
route flow4 {
|
||||
dst 220.0.254.192/28;
|
||||
tcp flags ! 0xfff/0xfff;
|
||||
};
|
||||
|
||||
route flow4 {
|
||||
dst 15.0.0.0/8;
|
||||
tcp flags ! 0x999/0x999;
|
||||
};
|
||||
}
|
||||
|
||||
protocol static flowstat6 {
|
||||
flow6;
|
||||
|
||||
route flow6 {
|
||||
dst fec0:1122:3344:5566::1/128;
|
||||
src 0000:0000:0000:0001:1234:5678:9800:0000/101 offset 63;
|
||||
next header = 23;
|
||||
sport 24..30, 42 || 50,60,70..80;
|
||||
dport = 50;
|
||||
tcp flags 0x03/0x0f, !0/0xff || 0x33/0x33;
|
||||
fragment !is_fragment || !first_fragment;
|
||||
label 0xaaaa/0xaaaa && 0x33/0x33;
|
||||
};
|
||||
|
||||
route flow6 {
|
||||
dst fec0:1122:3344:5566::1/128;
|
||||
src ::1:1234:5678:9800:0/101 offset 63;
|
||||
next header = 23;
|
||||
dport = 50;
|
||||
sport > 24 && < 30 || = 40 || = 50 || = 60 || >= 70 && <= 80;
|
||||
tcp flags 0x3/0x3 && 0x0/0xc;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
protocol pipe {
|
||||
table master4;
|
||||
peer table mcast4;
|
||||
import none;
|
||||
export where source = RTS_OSPF;
|
||||
}
|
||||
|
||||
protocol pipe {
|
||||
table master6;
|
||||
peer table mcast6;
|
||||
import none;
|
||||
export where source = RTS_OSPF;
|
||||
}
|
||||
|
||||
protocol ospf v2 ospf4 {
|
||||
ipv4 {
|
||||
import all;
|
||||
# export where source = RTS_STATIC;
|
||||
};
|
||||
|
||||
area 0 {
|
||||
interface "ve0" { stub; };
|
||||
interface "ve1" { hello 5; type ptp; };
|
||||
interface "ve2" { hello 5; type bcast; ttl security; };
|
||||
interface "ve3" { hello 5; type bcast; ttl security; };
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
protocol ospf v3 ospf6 {
|
||||
ipv6 {
|
||||
import all;
|
||||
# export where source = RTS_STATIC;
|
||||
};
|
||||
|
||||
area 0 {
|
||||
interface "ve0" { stub; };
|
||||
interface "ve1" { hello 5; type ptp; };
|
||||
interface "ve2" { hello 5; type bcast; };
|
||||
};
|
||||
}
|
||||
|
||||
protocol bgp {
|
||||
local 192.168.11.1 as 1000;
|
||||
neighbor 192.168.11.2 as 2000;
|
||||
# local 192.168.1.1 as 1000;
|
||||
# neighbor 192.168.2.1 as 2000;
|
||||
# multihop;
|
||||
# rr client;
|
||||
# strict bind;
|
||||
# debug all;
|
||||
|
||||
# regular IPv4 unicast (1/1)
|
||||
ipv4 {
|
||||
# connects to master4 table by default
|
||||
import all;
|
||||
export where source ~ [ RTS_STATIC, RTS_BGP ];
|
||||
};
|
||||
|
||||
# regular IPv6 unicast (2/1)
|
||||
ipv6 {
|
||||
# connects to master6 table by default
|
||||
import all;
|
||||
export where source ~ [ RTS_STATIC, RTS_BGP ];
|
||||
# next hop address 2001:db8:1:1::1;
|
||||
};
|
||||
|
||||
# IPv4 multicast topology (1/2)
|
||||
ipv4 multicast {
|
||||
# explicit IPv4 table
|
||||
table mcast4;
|
||||
import all;
|
||||
export all;
|
||||
};
|
||||
|
||||
# IPv6 multicast topology (2/2)
|
||||
ipv6 multicast {
|
||||
# explicit IPv6 table
|
||||
table mcast6;
|
||||
import all;
|
||||
export all;
|
||||
# next hop address 2001:db8:1:1::1;
|
||||
};
|
||||
|
||||
# IPv4 with MPLS labels (1/4)
|
||||
ipv4 mpls {
|
||||
# explicit IPv4 table
|
||||
table mtab4;
|
||||
import all;
|
||||
export all;
|
||||
};
|
||||
|
||||
# IPv6 with MPLS labels (2/4)
|
||||
ipv6 mpls {
|
||||
# explicit IPv6 table
|
||||
table mtab6;
|
||||
import all;
|
||||
export all;
|
||||
# allows IPv4 next hops (6PE)
|
||||
# extended next hop;
|
||||
};
|
||||
|
||||
# VPNv4 with MPLS labels (1/128)
|
||||
vpn4 mpls {
|
||||
# connects to vpntab4 table by default
|
||||
import all;
|
||||
export all;
|
||||
};
|
||||
|
||||
# VPNv6 with MPLS labels (2/128)
|
||||
vpn6 mpls {
|
||||
# connects to vpntab6 table by default
|
||||
import all;
|
||||
export all;
|
||||
};
|
||||
|
||||
# VPNv4 multicast topology (1/129)
|
||||
vpn4 multicast {
|
||||
table vpn4mc;
|
||||
import all;
|
||||
export all;
|
||||
};
|
||||
|
||||
# VPNv6 multicast topology (2/129)
|
||||
vpn6 multicast {
|
||||
table vpn6mc;
|
||||
import all;
|
||||
export all;
|
||||
};
|
||||
|
||||
# IPv4 Flowspec (1/133)
|
||||
flow4 {
|
||||
# connects to flowtab4 table by default
|
||||
import all;
|
||||
export all;
|
||||
};
|
||||
|
||||
# IPv6 Flowspec (2/133)
|
||||
flow6 {
|
||||
# connects to flowtab6 table by default
|
||||
import all;
|
||||
export all;
|
||||
};
|
||||
}
|
||||
|
||||
protocol bgp {
|
||||
local 192.168.1.1 as 1000;
|
||||
neighbor 192.168.3.1 as 1000;
|
||||
multihop;
|
||||
rr client;
|
||||
|
||||
ipv4 {
|
||||
import all;
|
||||
export where source ~ [ RTS_STATIC, RTS_BGP ];
|
||||
};
|
||||
|
||||
ipv6 {
|
||||
import all;
|
||||
export where source ~ [ RTS_STATIC, RTS_BGP ];
|
||||
next hop address 2001:db8:1:1::1;
|
||||
};
|
||||
}
|
||||
|
||||
protocol bgp {
|
||||
local 2001:db8:1:1::1 as 1000;
|
||||
neighbor 2001:db8:4:1::1 as 1000;
|
||||
multihop;
|
||||
rr client;
|
||||
|
||||
ipv4 {
|
||||
import all;
|
||||
export where source ~ [ RTS_STATIC, RTS_BGP ];
|
||||
next hop address 192.168.4.1;
|
||||
};
|
||||
|
||||
ipv6 {
|
||||
import all;
|
||||
export where source ~ [ RTS_STATIC, RTS_BGP ];
|
||||
};
|
||||
}
|
||||
|
5940
doc/bird.sgml
5940
doc/bird.sgml
File diff suppressed because it is too large
Load Diff
9
doc/prog-root
Normal file
9
doc/prog-root
Normal file
@ -0,0 +1,9 @@
|
||||
D doc/prog-head.sgml
|
||||
D doc/prog-intro.sgml
|
||||
C nest
|
||||
C conf
|
||||
C filter
|
||||
C proto
|
||||
C sysdep
|
||||
C lib
|
||||
D doc/prog-foot.sgml
|
@ -25,6 +25,15 @@ Reply codes of BIRD command-line interface
|
||||
0014 Route count
|
||||
0015 Reloading
|
||||
0016 Access restricted
|
||||
0017 Reconfiguration already in progress, removing queued config
|
||||
0018 Reconfiguration confirmed
|
||||
0019 Nothing to do (configure undo/confirm)
|
||||
0020 Configuration OK
|
||||
0021 Undo requested
|
||||
0022 Undo scheduled
|
||||
0023 Evaluation of expression
|
||||
0024 Graceful restart status report
|
||||
0025 Graceful restart ordered
|
||||
|
||||
1000 BIRD version
|
||||
1001 Interface list
|
||||
@ -45,6 +54,13 @@ Reply codes of BIRD command-line interface
|
||||
1016 Show ospf state/topology
|
||||
1017 Show ospf lsadb
|
||||
1018 Show memory
|
||||
1019 Show ROA list
|
||||
1020 Show BFD sessions
|
||||
1021 Show RIP interface
|
||||
1022 Show RIP neighbors
|
||||
1023 Show Babel interfaces
|
||||
1024 Show Babel neighbors
|
||||
1025 Show Babel entries
|
||||
|
||||
8000 Reply too long
|
||||
8001 Route not found
|
||||
@ -54,6 +70,7 @@ Reply codes of BIRD command-line interface
|
||||
8005 Protocol is down => cannot dump
|
||||
8006 Reload failed
|
||||
8007 Access denied
|
||||
8008 Evaluation runtime error
|
||||
|
||||
9000 Command too long
|
||||
9001 Parse error
|
||||
|
144
doc/sbase/dist/birddoc/groff/mapping
vendored
144
doc/sbase/dist/birddoc/groff/mapping
vendored
@ -6,7 +6,7 @@
|
||||
% Based on qwertz replacement file by Tom Gordon
|
||||
% linuxdoc mods by mdw
|
||||
|
||||
% Groff dependencies are few. To port to another roff:
|
||||
% Groff dependencies are few. To port to another roff:
|
||||
% 1. Check and modify, if necessary, font changes. (e.g. In psroff the
|
||||
% same fonts have other names.)
|
||||
% 2. Check the code for including Encapsulated PostScript, generated
|
||||
@ -19,13 +19,13 @@
|
||||
|
||||
% Hacked by mdw
|
||||
".nr PI 3n\n"
|
||||
".ds CF \\\\n\%\n"
|
||||
".ds CF \\\\n\%\n"
|
||||
".ds CH \\&\n"
|
||||
".ds dR $\n" % dollar, to avoid EQN conflicts
|
||||
|
||||
% Start with no TOC
|
||||
".ds printtoc\n"
|
||||
|
||||
|
||||
% Footnote style
|
||||
".nr FF 1\n"
|
||||
|
||||
@ -51,16 +51,16 @@
|
||||
".nr HM 0i\n"
|
||||
".nr FM 0i\n"
|
||||
|
||||
% Turn off right-margin filling
|
||||
% Turn off right-margin filling
|
||||
".na\n"
|
||||
|
||||
|
||||
% h is 1 if first paragraph after heading
|
||||
|
||||
".nr h 0\n"
|
||||
".nr h 0\n"
|
||||
|
||||
% initialize heading level
|
||||
|
||||
".nr il 1\n"
|
||||
|
||||
".nr il 1\n"
|
||||
|
||||
% Number registers for list
|
||||
|
||||
@ -68,20 +68,20 @@
|
||||
".nr ll 0\n" % list level, stores current level
|
||||
".nr el 0\n" % current enumeration level
|
||||
|
||||
% Not all list levels are enumerations, as
|
||||
% Not all list levels are enumerations, as
|
||||
% itemizations can be embedded within enumerations
|
||||
% and vice versa
|
||||
|
||||
|
||||
% type of list level is in \n(t\n(ll, where
|
||||
% 0 : itemize, 1 : enumerate, 2: description
|
||||
|
||||
% enumerator for an enumeration level is in
|
||||
% \n(e\n(el -- i.e. \n(e1=2 means current item of
|
||||
% enumeration level 1 is 2
|
||||
|
||||
|
||||
% context-sensitive paragraph macro
|
||||
|
||||
% Bug: There's some problem using this to re-start paragraphs after the
|
||||
% Bug: There's some problem using this to re-start paragraphs after the
|
||||
% </verb> and </code>, so after verb and code I insert .LP. That's fine
|
||||
% except that is loses indentation when using verb or code inside of a list.
|
||||
|
||||
@ -95,21 +95,21 @@
|
||||
% for this enumeration level
|
||||
".if \\\\n(t\\\\n(ll=1 \\{.IP \\\\n+(e\\\\n(el.\\}\n"
|
||||
% if first par element of descrip, do nothing
|
||||
".\\}\n"
|
||||
".\\}\n"
|
||||
".el .sp \n" % subsequent par element of item
|
||||
".\\}\n"
|
||||
".el \\{\\\n" % not within list
|
||||
".ie \\\\nh=1 \\{\\\n" % first par after heading
|
||||
".LP\n"
|
||||
".ie \\\\nh=1 \\{\\\n" % first par after heading
|
||||
".LP\n"
|
||||
".nr h 0\n" % reset h flag
|
||||
".\\}\n"
|
||||
".\\}\n"
|
||||
".el .LP \n" % Changed from .PP, mdw
|
||||
".\\}\n"
|
||||
".nh\n"
|
||||
"..\n"
|
||||
"..\n"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
% for each level, a number register is created
|
||||
% to store its type and current item number, where
|
||||
% -1=bullet of an itemized list.
|
||||
@ -141,7 +141,7 @@
|
||||
% set initial level of headings, in register il
|
||||
|
||||
<article> + ".nr il 0" +
|
||||
</article> + ".if '\\*[printtoc]'true' .PX\n"
|
||||
</article> + ".if '\\*[printtoc]'true' .PX\n"
|
||||
|
||||
<report> + ".nr il 1" +
|
||||
</report> + ".bp\n"
|
||||
@ -153,23 +153,23 @@
|
||||
".bp\n"
|
||||
".TC" +
|
||||
|
||||
<notes>
|
||||
<notes>
|
||||
</notes>
|
||||
|
||||
<manpage> + ".nr il -1" +
|
||||
</manpage>
|
||||
</manpage>
|
||||
|
||||
<progdoc>
|
||||
</progdoc>
|
||||
|
||||
% Hacked up titlepag stuff to look more reasonable. Titles and author
|
||||
% names are now stored in strings, printed by the end of </titlepag>.
|
||||
% Wake up! This uses groff-like long string names. You must use groff
|
||||
% Wake up! This uses groff-like long string names. You must use groff
|
||||
% to format this.
|
||||
|
||||
<titlepag> + ".ds mdwtitle\n"
|
||||
".ds mdwsubtitle\n"
|
||||
".ds mdwdate\n"
|
||||
".ds mdwdate\n"
|
||||
".de printabstract\n"
|
||||
"..\n" +
|
||||
</titlepag> + "\\*[mdwtitle]\n"
|
||||
@ -181,10 +181,10 @@
|
||||
"\\*[mdwdate]\n"
|
||||
".br\n"
|
||||
".printabstract\n"
|
||||
".br\n"
|
||||
".br\n"
|
||||
|
||||
%<title> + ".TL" +
|
||||
%</title>
|
||||
%</title>
|
||||
|
||||
<title> + ".ds mdwtitle "
|
||||
</title> +
|
||||
@ -194,13 +194,13 @@
|
||||
% ".SM" +
|
||||
%</subtitle> + ".LG" +
|
||||
|
||||
<subtitle> + ".ds mdwsubtitle "
|
||||
<subtitle> + ".ds mdwsubtitle "
|
||||
</subtitle> +
|
||||
|
||||
<date> + ".ds mdwdate "
|
||||
<date> + ".ds mdwdate "
|
||||
</date> +
|
||||
|
||||
<abstract> + ".de printabstract\n"
|
||||
<abstract> + ".de printabstract\n"
|
||||
".LP\n"
|
||||
</abstract> + ".." +
|
||||
|
||||
@ -215,10 +215,10 @@
|
||||
<name> + ".br" +
|
||||
</name>
|
||||
|
||||
<and>
|
||||
<and>
|
||||
</and>
|
||||
|
||||
<thanks> "\\**\n"
|
||||
<thanks> "\\**\n"
|
||||
".FS" +
|
||||
</thanks> + ".FE" +
|
||||
|
||||
@ -229,11 +229,11 @@
|
||||
<newline> + ".br"
|
||||
</newline>
|
||||
|
||||
<label>
|
||||
</label>
|
||||
<label>
|
||||
</label>
|
||||
|
||||
<header>
|
||||
</header>
|
||||
<header>
|
||||
</header>
|
||||
|
||||
<lhead> + ".EH '"
|
||||
</lhead> "'''" +
|
||||
@ -263,13 +263,13 @@
|
||||
<toc>
|
||||
</toc>
|
||||
|
||||
<lof>
|
||||
<lof>
|
||||
</lof>
|
||||
|
||||
<lot>
|
||||
<lot>
|
||||
</lot>
|
||||
|
||||
<chapt> + ".bp\n"
|
||||
<chapt> + ".bp\n"
|
||||
".NH \\n(il " +
|
||||
</chapt>
|
||||
|
||||
@ -283,7 +283,7 @@
|
||||
</sect2>
|
||||
|
||||
<sect3> + ".NH 4+\\n(il" +
|
||||
</sect3>
|
||||
</sect3>
|
||||
|
||||
<sect4> + ".NH 5+\\n(il" +
|
||||
</sect4>
|
||||
@ -292,10 +292,10 @@
|
||||
</heading> + "\\*h\n"
|
||||
".XS \\n%\n"
|
||||
"\\*(SN \\*h\n"
|
||||
".XE\n"
|
||||
".XE\n"
|
||||
".nr h 1\n" % set heading flag to true
|
||||
|
||||
<p> + ".Pp" +
|
||||
<p> + ".Pp" +
|
||||
</p>
|
||||
|
||||
<itemize> + ".nr ll +1\n" % increment list level
|
||||
@ -309,9 +309,9 @@
|
||||
".af e\\n(el \\*(f\\n(el\n" % style of enumerator
|
||||
".if \\n(ll>1 .RS" +
|
||||
</enum> + ".if \\n(ll>1 .RE\n"
|
||||
".br\n"
|
||||
".br\n"
|
||||
".nr el -1\n" % decrement enumeration level
|
||||
".nr ll -1\n" % decrement list level
|
||||
".nr ll -1\n" % decrement list level
|
||||
|
||||
<descrip> + ".RS\n"
|
||||
".nr ll +1\n" % increment list level
|
||||
@ -324,7 +324,7 @@
|
||||
% If bi=1 then the paragraph is the first one of the item.
|
||||
|
||||
<item> + ".nr bi 1\n.Pp" +
|
||||
</item>
|
||||
</item>
|
||||
|
||||
<tag> + ".IP \"\\fB"
|
||||
</tag> "\\fR\"\n"
|
||||
@ -337,12 +337,12 @@
|
||||
</cf> ""
|
||||
|
||||
<cite> + ".\[\n[ID]\n.\]" +
|
||||
</cite>
|
||||
</cite>
|
||||
|
||||
<ncite> + ".\[\n[ID]\n.\]\n([NOTE])"
|
||||
</ncite>
|
||||
|
||||
<footnote> " (-- "
|
||||
<footnote> " (-- "
|
||||
</footnote> "--)" +
|
||||
|
||||
<sq> "\\*Q"
|
||||
@ -353,20 +353,20 @@
|
||||
</lq> + ".nr LL \\n(LL+\\n(PI\n"
|
||||
".RE" +
|
||||
|
||||
<em> "\\fI"
|
||||
</em> "\\fP"
|
||||
<em> "\\fI"
|
||||
</em> "\\fP"
|
||||
|
||||
<bf> "\\fB"
|
||||
</bf> "\\fR"
|
||||
<bf> "\\fB"
|
||||
</bf> "\\fR"
|
||||
|
||||
<it> "\\fI"
|
||||
</it> "\\fR"
|
||||
<it> "\\fI"
|
||||
</it> "\\fR"
|
||||
|
||||
<sf> "\\fR"
|
||||
</sf> "\\fR"
|
||||
<sf> "\\fR"
|
||||
</sf> "\\fR"
|
||||
|
||||
<sl> "\\fI"
|
||||
</sl> "\\fR"
|
||||
<sl> "\\fI"
|
||||
</sl> "\\fR"
|
||||
|
||||
% Changed by mdw
|
||||
<tt> "\\fC"
|
||||
@ -394,10 +394,10 @@
|
||||
<pageref> "??"
|
||||
</pageref>
|
||||
|
||||
<x>
|
||||
<x>
|
||||
</x>
|
||||
|
||||
<mc>
|
||||
<mc>
|
||||
</mc>
|
||||
|
||||
<biblio> + ".\[\n"
|
||||
@ -423,7 +423,7 @@
|
||||
% ".Pp" + % continue previous paragraph (changed mdw)
|
||||
".LP"
|
||||
|
||||
% tscreen added by mdw
|
||||
% tscreen added by mdw
|
||||
<tscreen> + ".br\n"
|
||||
".po 0.75i\n"
|
||||
".ll 6.0i\n"
|
||||
@ -487,8 +487,8 @@
|
||||
|
||||
% mathematics -- this nroff version needs work.
|
||||
|
||||
<f>
|
||||
</f>
|
||||
<f>
|
||||
</f>
|
||||
|
||||
<dm> + ".DS L" +
|
||||
</dm> + ".DE" +
|
||||
@ -496,8 +496,8 @@
|
||||
<eq> + ".DS L" +
|
||||
</eq> + ".DE" +
|
||||
|
||||
<fr>
|
||||
</fr>
|
||||
<fr>
|
||||
</fr>
|
||||
|
||||
<nu> "{"
|
||||
</nu> "} over "
|
||||
@ -505,7 +505,7 @@
|
||||
<de> "{"
|
||||
</de> "}"
|
||||
|
||||
<lim>
|
||||
<lim>
|
||||
</lim>
|
||||
|
||||
<op>
|
||||
@ -527,7 +527,7 @@
|
||||
</in>
|
||||
|
||||
<sum> " sum "
|
||||
</sum>
|
||||
</sum>
|
||||
|
||||
% limitation: eqn only does square roots!
|
||||
|
||||
@ -539,7 +539,7 @@
|
||||
"[ca]." +
|
||||
</ar> + ".TE" +
|
||||
|
||||
<arr> "\n"
|
||||
<arr> "\n"
|
||||
</arr>
|
||||
|
||||
<arc> "|"
|
||||
@ -567,8 +567,8 @@
|
||||
|
||||
% limitation: no calligraphic characters, using helvetica italics instead. Is there a better font?
|
||||
|
||||
<fi> "\\fI"
|
||||
</fi> "\\fP"
|
||||
<fi> "\\fI"
|
||||
</fi> "\\fP"
|
||||
|
||||
<phr> " roman }"
|
||||
</phr> "}"
|
||||
@ -584,12 +584,12 @@
|
||||
|
||||
<eps> + ".if t .PSPIC [file].ps\n"
|
||||
".if n .sp 4" +
|
||||
</eps>
|
||||
|
||||
</eps>
|
||||
|
||||
% Are TeX units properly handled by this translation of ph?
|
||||
|
||||
<ph> + ".sp [VSPACE]" +
|
||||
</ph>
|
||||
</ph>
|
||||
|
||||
<caption> + ".sp\n.ce" +
|
||||
</caption>
|
||||
@ -619,7 +619,7 @@
|
||||
<slides> + ".nr PS 18" +
|
||||
</slides>
|
||||
|
||||
<slide>
|
||||
<slide>
|
||||
</slide> + ".bp\n\\&" +
|
||||
|
||||
% letters -- replacement for email, using mh format.
|
||||
|
72
doc/sbase/dist/birddoc/html/mapping
vendored
72
doc/sbase/dist/birddoc/html/mapping
vendored
@ -21,7 +21,7 @@
|
||||
</notes> + "<@@enddoc>" +
|
||||
|
||||
% Manual Pages are expected to be formatted using nroff (or groff), unless
|
||||
% they are included as sections of other qwertz documents.
|
||||
% they are included as sections of other qwertz documents.
|
||||
|
||||
<manpage>
|
||||
</manpage>
|
||||
@ -35,7 +35,7 @@
|
||||
<title> + "<@@title>"
|
||||
</title>
|
||||
|
||||
<subtitle> + "<H2>"
|
||||
<subtitle> + "<H2>"
|
||||
</subtitle> "</H2>" +
|
||||
|
||||
<author>
|
||||
@ -48,26 +48,27 @@
|
||||
</and>
|
||||
|
||||
<thanks> + "Thanks "
|
||||
</thanks>
|
||||
</thanks>
|
||||
|
||||
<inst> + "<H3>"
|
||||
</inst> "</H3>" +
|
||||
|
||||
<newline> "<BR>"
|
||||
|
||||
|
||||
<label> + "<@@label>[ID]" +
|
||||
|
||||
<header>
|
||||
</header>
|
||||
</label>
|
||||
|
||||
<header>
|
||||
</header>
|
||||
|
||||
<lhead> + "<!-- "
|
||||
</lhead> " -->" +
|
||||
</lhead> " -->" +
|
||||
|
||||
<rhead> + "<!-- "
|
||||
</rhead> " -->" +
|
||||
|
||||
<comment> + "<H4>Comment</H4>" +
|
||||
</comment>
|
||||
</comment>
|
||||
|
||||
<abstract> + "<P><HR>\n<EM>"
|
||||
</abstract> "</EM>\n<HR>" +
|
||||
@ -99,7 +100,7 @@
|
||||
<sect3> + "<@@head>"
|
||||
</sect3>
|
||||
|
||||
<sect4> + "<@@head>"
|
||||
<sect4> + "<@@head>"
|
||||
</sect4>
|
||||
|
||||
<heading>
|
||||
@ -134,6 +135,9 @@
|
||||
<ncite> "[<I>[NOTE] ([ID])</I>]"
|
||||
</ncite>
|
||||
|
||||
<file> "<CODE>"
|
||||
</file> "</CODE>"
|
||||
|
||||
<footnote> + "<BLOCKQUOTE>"
|
||||
</footnote> "</BLOCKQUOTE>" +
|
||||
|
||||
@ -198,12 +202,14 @@
|
||||
"<@@endurl>" +
|
||||
</url>
|
||||
|
||||
<htmlurl> + "<@@url>[URL]\n"
|
||||
"[NAME]</A>\n"
|
||||
"<@@endurl>" +
|
||||
<htmlurl> "<A HREF=\"[URL]\">[NAME]</A>"
|
||||
</htmlurl>
|
||||
|
||||
% ref modified to have an optional name field
|
||||
<rfc> "<A HREF=\"http://www.rfc-editor.org/info/rfc[ID]\">RFC [ID]</A>"
|
||||
</rfc>
|
||||
|
||||
|
||||
% ref modified to have an optional name field
|
||||
<ref> + "<@@ref>[ID]\n"
|
||||
"[NAME]</A>\n"
|
||||
"<@@endref>" +
|
||||
@ -228,7 +234,7 @@
|
||||
</mc> "</MC>"
|
||||
|
||||
<biblio> + "<BIBLIO STYLE=\"[STYLE]\" FILES=\"[FILES]\">" +
|
||||
</biblio>
|
||||
</biblio>
|
||||
|
||||
<code> + "<HR>\n<PRE>" +
|
||||
</code> + "</PRE>\n<HR>" +
|
||||
@ -244,28 +250,28 @@
|
||||
|
||||
% theorems and such
|
||||
|
||||
<def> + "<DEF>"
|
||||
<def> + "<DEF>"
|
||||
</def> + "</DEF>" +
|
||||
|
||||
<prop> + "<PROP>"
|
||||
<prop> + "<PROP>"
|
||||
</prop> + "</PROP>" +
|
||||
|
||||
<lemma> + "<LEMMA>"
|
||||
<lemma> + "<LEMMA>"
|
||||
</lemma> + "</LEMMA>" +
|
||||
|
||||
<coroll> + "<COROLL>"
|
||||
<coroll> + "<COROLL>"
|
||||
</coroll> + "</COROLL>" +
|
||||
|
||||
<proof> + "<PROOF>"
|
||||
<proof> + "<PROOF>"
|
||||
</proof> + "</PROOF>" +
|
||||
|
||||
<theorem> + "<THEOREM>"
|
||||
<theorem> + "<THEOREM>"
|
||||
</theorem> + "</THEOREM>" +
|
||||
|
||||
<thtag> "<THTAG>"
|
||||
</thtag> "</THTAG>"
|
||||
|
||||
% mathematics
|
||||
% mathematics
|
||||
|
||||
<f>
|
||||
</f>
|
||||
@ -315,11 +321,11 @@
|
||||
<ar> "<AR>"
|
||||
</ar> "</AR>"
|
||||
|
||||
<arr> "<ARR>"
|
||||
</arr>
|
||||
<arr> "<ARR>"
|
||||
</arr>
|
||||
|
||||
<arc> "<ARC>"
|
||||
</arc>
|
||||
</arc>
|
||||
|
||||
<sup> "<SUP>"
|
||||
</sup> "</SUP>"
|
||||
@ -354,13 +360,13 @@
|
||||
</figure> + "</FIGURE>" +
|
||||
|
||||
<eps> + "<EPS FILE=\"[FILE]\">" +
|
||||
</eps>
|
||||
|
||||
</eps>
|
||||
|
||||
<img> + "<IMG SRC=\"[SRC]\">" +
|
||||
</img>
|
||||
|
||||
<ph> + "<PH VSPACE=\"[VSPACE]\">" +
|
||||
</ph>
|
||||
</ph>
|
||||
|
||||
<caption> + "<CAPTION>"
|
||||
</caption> "</CAPTION>" +
|
||||
@ -403,7 +409,7 @@
|
||||
</opening> "</OPENING>" +
|
||||
|
||||
|
||||
<from> + "<FROM>"
|
||||
<from> + "<FROM>"
|
||||
</from> + "</FROM>" +
|
||||
|
||||
|
||||
@ -419,7 +425,7 @@
|
||||
<email> + "<EMAIL>"
|
||||
</email> "</EMAIL>" +
|
||||
|
||||
<phone> + "<PHONE>"
|
||||
<phone> + "<PHONE>"
|
||||
</phone> "</PHONE>" +
|
||||
|
||||
|
||||
@ -430,16 +436,16 @@
|
||||
</subject> "</SUBJECT>" +
|
||||
|
||||
|
||||
<sref> + "<SREF>"
|
||||
<sref> + "<SREF>"
|
||||
</sref> "</SREF>" +
|
||||
|
||||
<rref> + "<RREF>"
|
||||
<rref> + "<RREF>"
|
||||
</rref> "</RREF>" +
|
||||
|
||||
<rdate> + "<RDATE>"
|
||||
</rdate> "</RDATE>" +
|
||||
|
||||
<closing> + "<CLOSING>"
|
||||
<closing> + "<CLOSING>"
|
||||
</closing> "</CLOSING>" +
|
||||
|
||||
<cc> + "<CC>"
|
||||
|
63
doc/sbase/dist/birddoc/latex2e/mapping
vendored
63
doc/sbase/dist/birddoc/latex2e/mapping
vendored
@ -2,7 +2,9 @@
|
||||
% birddoc to LaTeX replacement file
|
||||
|
||||
% The \relax is there to avoid sgml2latex rewriting the class
|
||||
<book> + "\\relax\\documentclass\[a4paper,10pt,openany\]{book}\n"
|
||||
<book> + "\\relax\\documentclass\[a4paper,10pt,openany,oneside\]{book}\n"
|
||||
"\\usepackage\[colorlinks=true,linkcolor=blue,pdftitle={BIRD User's Guide}\]{hyperref}\n"
|
||||
"\\usepackage{enumitem}\n"
|
||||
"\\usepackage{birddoc}\n"
|
||||
"\\usepackage{qwertz}\n"
|
||||
"\\usepackage{url}\n"
|
||||
@ -14,7 +16,7 @@
|
||||
</book> + "\\end{document}" +
|
||||
|
||||
% Manual Pages are expected to be formatted using nroff (or groff), unless
|
||||
% they are included as sections of other qwertz documents.
|
||||
% they are included as sections of other qwertz documents.
|
||||
|
||||
<manpage>
|
||||
</manpage>
|
||||
@ -26,17 +28,17 @@
|
||||
</titlepag> + "\n\n\\begin{document}\n"
|
||||
"\\maketitle\n" +
|
||||
|
||||
<title> + "\\title{"
|
||||
<title> + "\\title{"
|
||||
</title> "}" +
|
||||
|
||||
<subtitle> "\\\\\n"
|
||||
"{\\large "
|
||||
</subtitle> "}" +
|
||||
|
||||
<author> + "\\author{"
|
||||
<author> + "\\author{"
|
||||
</author> "}" +
|
||||
|
||||
<name>
|
||||
<name>
|
||||
</name>
|
||||
|
||||
<and> "\\and " +
|
||||
@ -51,14 +53,14 @@
|
||||
<date> + "\\date{"
|
||||
</date> "}" +
|
||||
|
||||
<newline> "\\\\ "
|
||||
<newline> "\\\\ "
|
||||
</newline>
|
||||
|
||||
<label> "\\label{[ID]}"
|
||||
</label>
|
||||
</label>
|
||||
|
||||
<header> + "\\markboth"
|
||||
</header>
|
||||
</header>
|
||||
|
||||
<lhead> "{"
|
||||
</lhead> "}"
|
||||
@ -73,7 +75,7 @@
|
||||
</comment> "}"
|
||||
|
||||
% Hacked by mdw to use linuxdoc-sgml \abstract{...}
|
||||
<abstract> + "\\abstract{"
|
||||
<abstract> + "\\abstract{"
|
||||
</abstract> "}" +
|
||||
|
||||
<appendix> + "\n \\appendix \n" +
|
||||
@ -101,15 +103,15 @@
|
||||
</sect2>
|
||||
|
||||
<sect3> + "\n\\paragraph"
|
||||
</sect3>
|
||||
</sect3>
|
||||
|
||||
<sect4> + "\n\\subparagraph"
|
||||
</sect4>
|
||||
|
||||
<heading> "{"
|
||||
</heading> "}\n\n"
|
||||
</heading> "}\n\n"
|
||||
|
||||
<p>
|
||||
<p> "\\phantomsection{}"
|
||||
</p> "\n\n"
|
||||
|
||||
<itemize> + "\\begin{itemize}" +
|
||||
@ -121,13 +123,13 @@
|
||||
<list> + "\\begin{list}{}{}\n" +
|
||||
</list> + "\\end{list}" +
|
||||
|
||||
<descrip> + "\\begin{description}" +
|
||||
<descrip> + "\\begin{description}\[style=unboxed\]" +
|
||||
</descrip> + "\\end{description}" +
|
||||
|
||||
<item> + "\\item "
|
||||
</item>
|
||||
|
||||
<tag> + "\\item\[{\\ttfamily "
|
||||
<tag> + "\\phantomsection\\item\[{\\ttfamily "
|
||||
</tag> "}\] \\hfil\\break\n" +
|
||||
|
||||
<tagp> + "\\item\[ "
|
||||
@ -154,7 +156,7 @@
|
||||
% The idea here is to automatically insert soft hyphens after every slash in
|
||||
% the filename, so long filenames will break naturally. The url{} macro is
|
||||
% a kluge but it works,
|
||||
<file> "\\url{"
|
||||
<file> "{\\tt "
|
||||
</file> "}"
|
||||
|
||||
<footnote> "\\footnote{"
|
||||
@ -223,29 +225,32 @@
|
||||
<cparam> "\\cparam{"
|
||||
</cparam> "}"
|
||||
|
||||
<ref> "\\ref{[ID]} {([NAME])}"
|
||||
<ref> "\\hyperref\[[ID]\]{[NAME]} (p.\\,\\getpagerefnumber{[ID]})"
|
||||
</ref>
|
||||
|
||||
<pageref> "\\pageref{[ID]}"
|
||||
</pageref>
|
||||
|
||||
%url added by HG
|
||||
<url> "\\nameurl{[URL]}{[NAME]}"
|
||||
<url> "\\href{[URL]}{[NAME]}"
|
||||
</url>
|
||||
|
||||
<htmlurl> "\\onlynameurl{[NAME]}"
|
||||
<htmlurl> "\\href{[URL]}{[NAME]}"
|
||||
</htmlurl>
|
||||
|
||||
<x>
|
||||
<rfc> "\\href{http://www.rfc-editor.org/info/rfc[ID]}{RFC [ID]}"
|
||||
</rfc>
|
||||
|
||||
<x>
|
||||
</x>
|
||||
|
||||
<mc>
|
||||
<mc>
|
||||
</mc>
|
||||
|
||||
<biblio> + "\\bibliographystyle{[STYLE]}\n"
|
||||
"\\bibliography{[FILES]}\n"
|
||||
"\\addbibtoc{}" +
|
||||
</biblio>
|
||||
</biblio>
|
||||
|
||||
% <macro> + "\\macro{[ID]}{\\qw[ID]}"
|
||||
% </macro>
|
||||
@ -300,19 +305,19 @@
|
||||
<thtag> "\["
|
||||
</thtag> "\]" +
|
||||
|
||||
% mathematics
|
||||
% mathematics
|
||||
|
||||
<f> "$"
|
||||
</f> "$"
|
||||
|
||||
<dm> + "\\\["
|
||||
<dm> + "\\\["
|
||||
</dm> "\\\]" +
|
||||
|
||||
<eq> + "\\begin{equation}" +
|
||||
</eq> + "\\end{equation}\n" +
|
||||
|
||||
<fr> "\\frac"
|
||||
</fr>
|
||||
</fr>
|
||||
|
||||
<nu> "{"
|
||||
</nu> "}"
|
||||
@ -320,7 +325,7 @@
|
||||
<de> "{"
|
||||
</de> "}"
|
||||
|
||||
<lim>
|
||||
<lim>
|
||||
</lim>
|
||||
|
||||
<op>
|
||||
@ -342,7 +347,7 @@
|
||||
</in>
|
||||
|
||||
<sum> "\\sum"
|
||||
</sum>
|
||||
</sum>
|
||||
|
||||
<root> "\\sqrt\[[n]\]{"
|
||||
</root> "}"
|
||||
@ -390,11 +395,11 @@
|
||||
</figure> + "\\end{figure}\n" +
|
||||
|
||||
<eps> + "\\centerline{\\epsfig{file=[FILE],height=[HEIGHT],angle=[ANGLE]}}" +
|
||||
</eps>
|
||||
|
||||
</eps>
|
||||
|
||||
|
||||
<ph> + "\\vspace{[VSPACE]}\n\\par" +
|
||||
</ph>
|
||||
</ph>
|
||||
|
||||
<caption> + "\\caption{"
|
||||
</caption> "}" +
|
||||
|
4
doc/sbase/dist/fmt_latex2e.pl
vendored
4
doc/sbase/dist/fmt_latex2e.pl
vendored
@ -284,11 +284,11 @@ $latex2e->{postASP} = sub
|
||||
# for nameurl
|
||||
if ( /\\nameurl/ )
|
||||
{
|
||||
($urlid, $urlnam) = ($_ =~ /\\nameurl{(.*)}{(.*)}/);
|
||||
($urlid, $urlnam) = ($_ =~ /\\nameurl\{(.*)\}\{(.*)\}/);
|
||||
print $urlnum . ": " . $urlid . "\n" if ( $global->{debug} );
|
||||
|
||||
$urldef = latex2e_defnam($urlnum) . "url";
|
||||
s/\\nameurl{.*}{.*}/{\\em $urlnam} {\\tt \\$urldef}/;
|
||||
s/\\nameurl\{.*\}\{.*\}/{\\em $urlnam} {\\tt \\$urldef}/;
|
||||
push @urlnames, $_;
|
||||
push @urldefines, "\\urldef{\\$urldef} \\url{$urlid}\n";
|
||||
$urlnum++;
|
||||
|
@ -1,6 +1,6 @@
|
||||
<!-- This is a DTD, but will be read as -*- sgml -*- -->
|
||||
<!-- ================================================= -->
|
||||
<!-- $Id$
|
||||
<!-- $Id$
|
||||
|
||||
This was heavilly modified for use with bird! Don't you dare to use it
|
||||
anywhere else. <pavel@ucw.cz>
|
||||
@ -79,7 +79,7 @@ anywhere else. <pavel@ucw.cz>
|
||||
weren't in the original linuxdoc 1.3 DTD, and are
|
||||
superseded by the new if/unless facility. -->
|
||||
<!-- BK/97/05/09: this is the original Linuxdoc DTD,
|
||||
as of SGML Tools 0.99.0. It is not longer
|
||||
as of SGML Tools 0.99.0. It is not longer
|
||||
supported. Use only if in dire need, for backwards
|
||||
compabitlity. Backend support for undocumented
|
||||
QWERTZ leftovers not in the strict Linuxdoc DTD's
|
||||
@ -92,36 +92,36 @@ anywhere else. <pavel@ucw.cz>
|
||||
any changes to this, just replacing. -->
|
||||
<!-- ================================================= -->
|
||||
|
||||
<!entity % emph
|
||||
<!entity % emph
|
||||
" em|it|bf|sf|sl|tt|cf|m|cparam|const|func|struct|param|type|funcdef " >
|
||||
|
||||
<!entity % index "idx|cdx|nidx|ncdx" >
|
||||
|
||||
<!-- url added by HG; htmlurl added by esr -->
|
||||
<!entity % xref
|
||||
" label|ref|pageref|cite|url|htmlurl|ncite " >
|
||||
" label|ref|pageref|cite|url|htmlurl|rfc|ncite " >
|
||||
|
||||
<!entity % inline
|
||||
<!entity % inline
|
||||
" (#pcdata | f| x| %emph; |sq| %xref | %index | file )* " >
|
||||
|
||||
<!entity % list
|
||||
<!entity % list
|
||||
" list | itemize | enum | descrip " >
|
||||
|
||||
<!entity % par
|
||||
<!entity % par
|
||||
" %list; | comment | lq | quote | tscreen | hrule " >
|
||||
|
||||
<!entity % mathpar " dm | eq " >
|
||||
|
||||
<!entity % thrm
|
||||
<!entity % thrm
|
||||
" def | prop | lemma | coroll | proof | theorem " >
|
||||
|
||||
<!entity % litprog " code | verb " >
|
||||
|
||||
<!entity % sectpar
|
||||
" %par; | figure | tabular | table | %mathpar; |
|
||||
<!entity % sectpar
|
||||
" %par; | figure | tabular | table | %mathpar; |
|
||||
%thrm; | %litprog; | function ">
|
||||
<!element birddoc o o
|
||||
(sect | chapt | article | report |
|
||||
<!element birddoc o o
|
||||
(sect | chapt | article | report |
|
||||
book | letter | telefax | slides | notes | manpage ) >
|
||||
|
||||
<!-- `general' entity replaced with ISO entities - kwm -->
|
||||
@ -150,7 +150,7 @@ anywhere else. <pavel@ucw.cz>
|
||||
<!element hrule - - EMPTY>
|
||||
|
||||
<!shortref pmap
|
||||
"&#RS;B" null
|
||||
"&#RS;B" null
|
||||
"&#RS;B&#RE;" psplit
|
||||
"&#RS;&#RE;" psplit
|
||||
-- '"' qtag --
|
||||
@ -189,7 +189,7 @@ anywhere else. <pavel@ucw.cz>
|
||||
<!entity ftag '<f>' -- formula begin -- >
|
||||
<!entity qendtag '</sq>'>
|
||||
|
||||
<!shortref sqmap
|
||||
<!shortref sqmap
|
||||
"&#RS;B" null
|
||||
-- '"' qendtag --
|
||||
"[" lsqb
|
||||
@ -249,7 +249,7 @@ anywhere else. <pavel@ucw.cz>
|
||||
<!shortref bodymap
|
||||
"&#RS;B&#RE;" ptag
|
||||
"&#RS;&#RE;" ptag
|
||||
'"' qtag
|
||||
'"' qtag
|
||||
"[" lsqb
|
||||
"~" nbsp
|
||||
"_" lowbar
|
||||
@ -285,7 +285,7 @@ anywhere else. <pavel@ucw.cz>
|
||||
|
||||
<!shortref oneline
|
||||
"B&#RE;" space
|
||||
"&#RS;&#RE;" null
|
||||
"&#RS;&#RE;" null
|
||||
"&#RS;B&#RE;" null
|
||||
-- '"' qtag --
|
||||
"[" ftag
|
||||
@ -302,7 +302,7 @@ anywhere else. <pavel@ucw.cz>
|
||||
<!usemap oneline caption>
|
||||
|
||||
<!entity % tabrow "(%inline, (colsep, %inline)*)" >
|
||||
<!element tabular - -
|
||||
<!element tabular - -
|
||||
(hline?, %tabrow, (rowsep, hline?, %tabrow)*, caption?) >
|
||||
|
||||
<!attlist tabular
|
||||
@ -323,7 +323,7 @@ anywhere else. <pavel@ucw.cz>
|
||||
"B&#RE;" null
|
||||
"BB" space
|
||||
"@" rowsep
|
||||
"|" colsep
|
||||
"|" colsep
|
||||
"[" ftag
|
||||
-- '"' qtag --
|
||||
"_" thinsp
|
||||
@ -344,7 +344,7 @@ anywhere else. <pavel@ucw.cz>
|
||||
|
||||
<!shortref ttmap -- also on one-line --
|
||||
"B&#RE;" space
|
||||
"&#RS;&#RE;" null
|
||||
"&#RS;&#RE;" null
|
||||
"&#RS;B&#RE;" null
|
||||
"&#RS;B" null
|
||||
'#' num
|
||||
@ -365,14 +365,14 @@ anywhere else. <pavel@ucw.cz>
|
||||
<!entity % limits "pr|in|sum" >
|
||||
<!entity % fbu "fr|lim|ar|root" >
|
||||
<!entity % fph "unl|ovl|sup|inf" >
|
||||
<!entity % fbutxt "(%fbu;) | (%limits;) |
|
||||
<!entity % fbutxt "(%fbu;) | (%limits;) |
|
||||
(%fcstxt;)|(%fscs;)|(%fph;)" >
|
||||
<!entity % fphtxt "p|#pcdata" >
|
||||
<!element f - - ((%fbutxt;)*) >
|
||||
|
||||
<!entity fendtag '</f>' -- formula end -- >
|
||||
|
||||
<!shortref fmap
|
||||
<!shortref fmap
|
||||
"&#RS;B" null
|
||||
"&#RS;B&#RE;" null
|
||||
"&#RS;&#RE;" null
|
||||
@ -432,7 +432,7 @@ anywhere else. <pavel@ucw.cz>
|
||||
<!shortref arrmap
|
||||
"&#RE;" space
|
||||
"@" arr
|
||||
"|" arc
|
||||
"|" arc
|
||||
"_" thinsp
|
||||
"~" nbsp
|
||||
"#" num
|
||||
@ -448,7 +448,7 @@ anywhere else. <pavel@ucw.cz>
|
||||
<!element ovl - - ((%fbutxt;)*) >
|
||||
<!element rf - o (#pcdata) >
|
||||
<!element phr - o ((%fphtxt;)*) >
|
||||
<!element v - o ((%fcstxt;)*)
|
||||
<!element v - o ((%fcstxt;)*)
|
||||
-(tu|%limits;|%fbu;|%fph;) >
|
||||
<!element fi - o (#pcdata) >
|
||||
<!element tu - o empty >
|
||||
@ -468,7 +468,7 @@ anywhere else. <pavel@ucw.cz>
|
||||
|
||||
<!shortref global
|
||||
"&#RS;B" null -- delete leading blanks --
|
||||
-- '"' qtag --
|
||||
-- '"' qtag --
|
||||
"[" ftag
|
||||
"~" nbsp
|
||||
"_" lowbar
|
||||
@ -485,22 +485,26 @@ anywhere else. <pavel@ucw.cz>
|
||||
|
||||
<!-- ref modified to have an optional name field HG -->
|
||||
<!element ref - o empty>
|
||||
<!attlist ref
|
||||
<!attlist ref
|
||||
id cdata #required
|
||||
name cdata "&refnam">
|
||||
|
||||
<!-- url entity added to have direct url references HG -->
|
||||
<!element url - o empty>
|
||||
<!attlist url
|
||||
<!attlist url
|
||||
url cdata #required
|
||||
name cdata "&urlnam" >
|
||||
|
||||
<!-- htmlurl entity added to have quieter url references esr -->
|
||||
<!element htmlurl - o empty>
|
||||
<!attlist htmlurl
|
||||
<!attlist htmlurl
|
||||
url cdata #required
|
||||
name cdata "&urlnam" >
|
||||
|
||||
<!element rfc - o empty>
|
||||
<!attlist rfc
|
||||
id cdata #required>
|
||||
|
||||
<!element pageref - o empty>
|
||||
<!attlist pageref
|
||||
id cdata #required>
|
||||
@ -510,22 +514,22 @@ anywhere else. <pavel@ucw.cz>
|
||||
|
||||
<!-- Hacked by mdw to exclude abstract; abstract now part of titlepag -->
|
||||
<!element article - -
|
||||
(titlepag, header?,
|
||||
toc?, lof?, lot?, p*, sect*,
|
||||
(titlepag, header?,
|
||||
toc?, lof?, lot?, p*, sect*,
|
||||
(appendix, sect+)?, biblio?) +(footnote)>
|
||||
|
||||
<!attlist article
|
||||
opts cdata "null">
|
||||
|
||||
<!-- Hacked by mdw to exclude abstract; abstract now part of titlepag -->
|
||||
<!element report - -
|
||||
<!element report - -
|
||||
(titlepag, header?, toc?, lof?, lot?, p*,
|
||||
chapt*, (appendix, chapt+)?, biblio?) +(footnote)>
|
||||
|
||||
<!attlist report
|
||||
opts cdata "null">
|
||||
<!element book - -
|
||||
(titlepag, header?, toc?, lof?, lot?, p*, chapt*,
|
||||
<!element book - -
|
||||
(titlepag, header?, toc?, lof?, lot?, p*, chapt*,
|
||||
(appendix, chapt+)?, biblio?) +(footnote) >
|
||||
|
||||
<!attlist book
|
||||
@ -536,7 +540,7 @@ anywhere else. <pavel@ucw.cz>
|
||||
<!element title - o (%inline, subtitle?) +(newline)>
|
||||
<!element subtitle - o (%inline)>
|
||||
<!usemap oneline titlepag>
|
||||
<!element author - o (name, thanks?, inst?,
|
||||
<!element author - o (name, thanks?, inst?,
|
||||
(and, name, thanks?, inst?)*)>
|
||||
<!element name o o (%inline) +(newline)>
|
||||
<!element and - o empty>
|
||||
@ -545,9 +549,9 @@ anywhere else. <pavel@ucw.cz>
|
||||
<!element date - o (#pcdata) >
|
||||
|
||||
<!usemap global thanks>
|
||||
|
||||
|
||||
<!element newline - o empty >
|
||||
<!entity nl "<newline>">
|
||||
<!entity nl "<newline>">
|
||||
|
||||
<!element progdoc - o empty>
|
||||
|
||||
@ -564,9 +568,9 @@ anywhere else. <pavel@ucw.cz>
|
||||
<!element rhead - o (%inline)>
|
||||
<!entity % sect "heading, header?, p* " >
|
||||
<!element heading o o (%inline)>
|
||||
<!element chapt - o (%sect, sect*) +(footnote)>
|
||||
<!element chapt - o (%sect, sect*) +(footnote)>
|
||||
<!element sect - o (%sect, sect1*) +(footnote)>
|
||||
<!element sect1 - o (%sect, sect2*)>
|
||||
<!element sect1 - o (%sect, sect2*) +(footnote)>
|
||||
<!element sect2 - o (%sect, sect3*)>
|
||||
<!element sect3 - o (%sect, sect4*)>
|
||||
<!element sect4 - o (%sect)>
|
||||
@ -575,11 +579,11 @@ anywhere else. <pavel@ucw.cz>
|
||||
<!element footnote - - (%inline)>
|
||||
<!usemap global footnote>
|
||||
<!element cite - o empty>
|
||||
<!attlist cite
|
||||
<!attlist cite
|
||||
id cdata #required>
|
||||
|
||||
<!element ncite - o empty>
|
||||
<!attlist ncite
|
||||
<!attlist ncite
|
||||
id cdata #required
|
||||
note cdata #required>
|
||||
|
||||
@ -599,41 +603,41 @@ anywhere else. <pavel@ucw.cz>
|
||||
<!attlist slides
|
||||
opts cdata "null">
|
||||
<!element slide - o (title?, p+) >
|
||||
<!entity % addr "(address?, email?, phone?, fax?)" >
|
||||
|
||||
<!element letter - -
|
||||
<!entity % addr "(address?, email?, phone?, fax?)" >
|
||||
|
||||
<!element letter - -
|
||||
(from, %addr, to, %addr, cc?, subject?, sref?, rref?,
|
||||
rdate?, opening, p+, closing, encl?, ps?)>
|
||||
|
||||
<!attlist letter
|
||||
opts cdata "null">
|
||||
|
||||
|
||||
<!element from - o (#pcdata) >
|
||||
<!element to - o (#pcdata) >
|
||||
|
||||
|
||||
<!usemap oneline (from,to)>
|
||||
|
||||
|
||||
<!element address - o (#pcdata) +(newline) >
|
||||
<!element email - o (#pcdata) >
|
||||
<!element phone - o (#pcdata) >
|
||||
<!element fax - o (#pcdata) >
|
||||
|
||||
|
||||
<!element subject - o (%inline;) >
|
||||
<!element sref - o (#pcdata) >
|
||||
<!element rref - o (#pcdata) >
|
||||
<!element rdate - o (#pcdata) >
|
||||
|
||||
|
||||
<!element opening - o (%inline;) >
|
||||
<!usemap oneline opening>
|
||||
|
||||
|
||||
<!element closing - o (%inline;) >
|
||||
<!element cc - o (%inline;) +(newline) >
|
||||
<!element encl - o (%inline;) +(newline) >
|
||||
|
||||
|
||||
<!element ps - o (p+) >
|
||||
|
||||
<!element telefax - -
|
||||
(from, %addr, to, address, email?,
|
||||
<!element telefax - -
|
||||
(from, %addr, to, address, email?,
|
||||
phone?, fax, cc?, subject?,
|
||||
opening, p+, closing, ps?)>
|
||||
|
||||
@ -644,8 +648,8 @@ anywhere else. <pavel@ucw.cz>
|
||||
<!element notes - - (title?, p+) >
|
||||
<!attlist notes
|
||||
opts cdata "null" >
|
||||
<!element manpage - - (sect1*)
|
||||
-(sect2 | f | %mathpar | figure | tabular |
|
||||
<!element manpage - - (sect1*)
|
||||
-(sect2 | f | %mathpar | figure | tabular |
|
||||
table | %xref | %thrm )>
|
||||
|
||||
|
||||
@ -673,5 +677,5 @@ anywhere else. <pavel@ucw.cz>
|
||||
<!--
|
||||
Local Variables:
|
||||
mode: sgml
|
||||
End: -->
|
||||
End: -->
|
||||
<!-- ================================================= -->
|
||||
|
@ -17,8 +17,10 @@ use strict;
|
||||
|
||||
use vars qw($prefix $DataDir $BinDir $progs);
|
||||
|
||||
use FindBin;
|
||||
|
||||
$prefix = "/usr";
|
||||
$DataDir = "sbase";
|
||||
$DataDir = "$FindBin::Bin/sbase";
|
||||
$BinDir = "/usr/bin";
|
||||
|
||||
use lib "/usr/share/linuxdoc-tools";
|
||||
@ -32,9 +34,14 @@ $progs = {
|
||||
"GROFFMACRO" => "-ms",
|
||||
"AWK" => "/usr/share/linuxdoc-tools/awkwhich"
|
||||
};
|
||||
$ENV{"SGML_CATALOG_FILES"} = "sbase/dtd/catalog";
|
||||
|
||||
require "./LinuxDocTools.pm";
|
||||
if (! -x $progs->{"NSGMLS"})
|
||||
{ $progs->{"NSGMLS"} = "/usr/bin/onsgmls"; }
|
||||
|
||||
$ENV{"SGML_CATALOG_FILES"} = "$DataDir/dtd/catalog" .
|
||||
(defined $ENV{SGML_CATALOG_FILES} ? ":$ENV{SGML_CATALOG_FILES}" : "");
|
||||
|
||||
require "$FindBin::Bin/LinuxDocTools.pm";
|
||||
&LinuxDocTools::init;
|
||||
|
||||
my @FileList = LinuxDocTools::process_options ("html", @ARGV);
|
||||
|
@ -17,8 +17,10 @@ use strict;
|
||||
|
||||
use vars qw($prefix $DataDir $BinDir $progs);
|
||||
|
||||
use FindBin;
|
||||
|
||||
$prefix = "/usr";
|
||||
$DataDir = "sbase";
|
||||
$DataDir = "$FindBin::Bin/sbase";
|
||||
$BinDir = "/usr/bin";
|
||||
|
||||
use lib "/usr/share/linuxdoc-tools";
|
||||
@ -32,9 +34,14 @@ $progs = {
|
||||
"GROFFMACRO" => "-ms",
|
||||
"AWK" => "/usr/share/linuxdoc-tools/awkwhich"
|
||||
};
|
||||
$ENV{"SGML_CATALOG_FILES"} = "sbase/dtd/catalog";
|
||||
|
||||
require "./LinuxDocTools.pm";
|
||||
if (! -x $progs->{"NSGMLS"})
|
||||
{ $progs->{"NSGMLS"} = "/usr/bin/onsgmls"; }
|
||||
|
||||
$ENV{"SGML_CATALOG_FILES"} = "$DataDir/dtd/catalog" .
|
||||
(defined $ENV{SGML_CATALOG_FILES} ? ":$ENV{SGML_CATALOG_FILES}" : "");
|
||||
|
||||
require "$FindBin::Bin/LinuxDocTools.pm";
|
||||
&LinuxDocTools::init;
|
||||
|
||||
my @FileList = LinuxDocTools::process_options ("latex", @ARGV);
|
||||
|
13
doc/sgml2txt
13
doc/sgml2txt
@ -17,8 +17,10 @@ use strict;
|
||||
|
||||
use vars qw($prefix $DataDir $BinDir $progs);
|
||||
|
||||
use FindBin;
|
||||
|
||||
$prefix = "/usr";
|
||||
$DataDir = "sbase";
|
||||
$DataDir = "$FindBin::Bin/sbase";
|
||||
$BinDir = "/usr/bin";
|
||||
|
||||
use lib "/usr/share/linuxdoc-tools";
|
||||
@ -32,9 +34,14 @@ $progs = {
|
||||
"GROFFMACRO" => "-ms",
|
||||
"AWK" => "/usr/share/linuxdoc-tools/awkwhich"
|
||||
};
|
||||
$ENV{"SGML_CATALOG_FILES"} = "sbase/dtd/catalog";
|
||||
|
||||
require "./LinuxDocTools.pm";
|
||||
if (! -x $progs->{"NSGMLS"})
|
||||
{ $progs->{"NSGMLS"} = "/usr/bin/onsgmls"; }
|
||||
|
||||
$ENV{"SGML_CATALOG_FILES"} = "$DataDir/dtd/catalog" .
|
||||
(defined $ENV{SGML_CATALOG_FILES} ? ":$ENV{SGML_CATALOG_FILES}" : "");
|
||||
|
||||
require "$FindBin::Bin/LinuxDocTools.pm";
|
||||
&LinuxDocTools::init;
|
||||
|
||||
my @FileList = LinuxDocTools::process_options ("txt", @ARGV);
|
||||
|
@ -1,5 +1,24 @@
|
||||
source=f-util.c filter.c tree.c trie.c
|
||||
root-rel=../
|
||||
dir-name=filter
|
||||
src := filter.c data.c f-util.c tree.c trie.c inst-gen.c
|
||||
obj := $(src-o-files)
|
||||
$(all-daemon)
|
||||
$(cf-local)
|
||||
|
||||
include ../Rules
|
||||
#M4FLAGS_FILTERS=$(filter-out -s,$(M4FLAGS))
|
||||
M4FLAGS_FILTERS=$(M4FLAGS)
|
||||
|
||||
$(o)inst-gen.h: $(s)decl.m4 $(s)f-inst.c $(objdir)/.dir-stamp
|
||||
$(M4) $(M4FLAGS_FILTERS) -DTARGET=H -P $^ >$@
|
||||
|
||||
$(o)inst-gen.c: $(s)decl.m4 $(s)f-inst.c $(objdir)/.dir-stamp
|
||||
$(M4) $(M4FLAGS_FILTERS) -DTARGET=C -P $^ >$@
|
||||
|
||||
$(o)inst-interpret.c: $(s)decl.m4 $(s)f-inst.c $(objdir)/.dir-stamp
|
||||
$(M4) $(M4FLAGS_FILTERS) -DTARGET=I -P $^ >$@
|
||||
|
||||
prepare: $(o)inst-interpret.c $(o)inst-gen.h
|
||||
|
||||
tests_src := tree_test.c filter_test.c trie_test.c
|
||||
tests_targets := $(tests_targets) $(tests-target-files)
|
||||
tests_objs := $(tests_objs) $(src-o-files)
|
||||
|
||||
$(call clean,inst-gen.h inst-gen.c inst-interpret.c)
|
||||
|
1037
filter/config.Y
1037
filter/config.Y
File diff suppressed because it is too large
Load Diff
601
filter/data.c
Normal file
601
filter/data.c
Normal file
@ -0,0 +1,601 @@
|
||||
/*
|
||||
* Filters: utility functions
|
||||
*
|
||||
* (c) 1998 Pavel Machek <pavel@ucw.cz>
|
||||
* (c) 2019 Maria Matejka <mq@jmq.cz>
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "nest/bird.h"
|
||||
#include "lib/lists.h"
|
||||
#include "lib/resource.h"
|
||||
#include "lib/socket.h"
|
||||
#include "lib/string.h"
|
||||
#include "lib/unaligned.h"
|
||||
#include "lib/net.h"
|
||||
#include "lib/ip.h"
|
||||
#include "nest/route.h"
|
||||
#include "nest/protocol.h"
|
||||
#include "nest/iface.h"
|
||||
#include "nest/attrs.h"
|
||||
#include "conf/conf.h"
|
||||
#include "filter/filter.h"
|
||||
#include "filter/f-inst.h"
|
||||
#include "filter/data.h"
|
||||
|
||||
static const char * const f_type_str[] = {
|
||||
[T_VOID] = "void",
|
||||
|
||||
[T_INT] = "int",
|
||||
[T_BOOL] = "bool",
|
||||
[T_PAIR] = "pair",
|
||||
[T_QUAD] = "quad",
|
||||
|
||||
[T_ENUM_RTS] = "enum rts",
|
||||
[T_ENUM_BGP_ORIGIN] = "enum bgp_origin",
|
||||
[T_ENUM_SCOPE] = "enum scope",
|
||||
[T_ENUM_RTC] = "enum rtc",
|
||||
[T_ENUM_RTD] = "enum rtd",
|
||||
[T_ENUM_ROA] = "enum roa",
|
||||
[T_ENUM_NETTYPE] = "enum nettype",
|
||||
[T_ENUM_RA_PREFERENCE] = "enum ra_preference",
|
||||
[T_ENUM_AF] = "enum af",
|
||||
|
||||
[T_IP] = "ip",
|
||||
[T_NET] = "prefix",
|
||||
[T_STRING] = "string",
|
||||
[T_PATH_MASK] = "bgpmask",
|
||||
[T_PATH] = "bgppath",
|
||||
[T_CLIST] = "clist",
|
||||
[T_EC] = "ec",
|
||||
[T_ECLIST] = "eclist",
|
||||
[T_LC] = "lc",
|
||||
[T_LCLIST] = "lclist",
|
||||
[T_RD] = "rd",
|
||||
};
|
||||
|
||||
const char *
|
||||
f_type_name(enum f_type t)
|
||||
{
|
||||
if (t < ARRAY_SIZE(f_type_str))
|
||||
return f_type_str[t] ?: "?";
|
||||
|
||||
if ((t == T_SET) || (t == T_PREFIX_SET))
|
||||
return "set";
|
||||
|
||||
return "?";
|
||||
}
|
||||
|
||||
const struct f_val f_const_empty_path = {
|
||||
.type = T_PATH,
|
||||
.val.ad = &null_adata,
|
||||
}, f_const_empty_clist = {
|
||||
.type = T_CLIST,
|
||||
.val.ad = &null_adata,
|
||||
}, f_const_empty_eclist = {
|
||||
.type = T_ECLIST,
|
||||
.val.ad = &null_adata,
|
||||
}, f_const_empty_lclist = {
|
||||
.type = T_LCLIST,
|
||||
.val.ad = &null_adata,
|
||||
};
|
||||
|
||||
static struct adata *
|
||||
adata_empty(struct linpool *pool, int l)
|
||||
{
|
||||
struct adata *res = lp_alloc(pool, sizeof(struct adata) + l);
|
||||
res->length = l;
|
||||
return res;
|
||||
}
|
||||
|
||||
static void
|
||||
pm_format(const struct f_path_mask *p, buffer *buf)
|
||||
{
|
||||
int loop = 0;
|
||||
|
||||
buffer_puts(buf, "[= ");
|
||||
|
||||
for (uint i=0; i<p->len; i++)
|
||||
{
|
||||
switch(p->item[i].kind)
|
||||
{
|
||||
case PM_ASN:
|
||||
buffer_print(buf, "%u ", p->item[i].asn);
|
||||
break;
|
||||
|
||||
case PM_QUESTION:
|
||||
buffer_puts(buf, "? ");
|
||||
break;
|
||||
|
||||
case PM_ASTERISK:
|
||||
buffer_puts(buf, "* ");
|
||||
break;
|
||||
|
||||
case PM_LOOP:
|
||||
loop = 1;
|
||||
break;
|
||||
|
||||
case PM_ASN_RANGE:
|
||||
buffer_print(buf, "%u..%u ", p->item[i].from, p->item[i].to);
|
||||
break;
|
||||
|
||||
case PM_ASN_SET:
|
||||
tree_format(p->item[i].set, buf);
|
||||
buffer_puts(buf, " ");
|
||||
break;
|
||||
|
||||
case PM_ASN_EXPR:
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
if (loop && (p->item[i].kind != PM_LOOP))
|
||||
{
|
||||
buffer_puts(buf, "+ ");
|
||||
loop = 0;
|
||||
}
|
||||
}
|
||||
|
||||
buffer_puts(buf, "=]");
|
||||
}
|
||||
|
||||
static inline int
|
||||
lcomm_cmp(lcomm v1, lcomm v2)
|
||||
{
|
||||
if (v1.asn != v2.asn)
|
||||
return (v1.asn > v2.asn) ? 1 : -1;
|
||||
if (v1.ldp1 != v2.ldp1)
|
||||
return (v1.ldp1 > v2.ldp1) ? 1 : -1;
|
||||
if (v1.ldp2 != v2.ldp2)
|
||||
return (v1.ldp2 > v2.ldp2) ? 1 : -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* val_compare - compare two values
|
||||
* @v1: first value
|
||||
* @v2: second value
|
||||
*
|
||||
* Compares two values and returns -1, 0, 1 on <, =, > or F_CMP_ERROR on
|
||||
* error. Tree module relies on this giving consistent results so
|
||||
* that it can be used for building balanced trees.
|
||||
*/
|
||||
int
|
||||
val_compare(const struct f_val *v1, const struct f_val *v2)
|
||||
{
|
||||
if (v1->type != v2->type) {
|
||||
if (v1->type == T_VOID) /* Hack for else */
|
||||
return -1;
|
||||
if (v2->type == T_VOID)
|
||||
return 1;
|
||||
|
||||
/* IP->Quad implicit conversion */
|
||||
if ((v1->type == T_QUAD) && val_is_ip4(v2))
|
||||
return uint_cmp(v1->val.i, ipa_to_u32(v2->val.ip));
|
||||
if (val_is_ip4(v1) && (v2->type == T_QUAD))
|
||||
return uint_cmp(ipa_to_u32(v1->val.ip), v2->val.i);
|
||||
|
||||
debug( "Types do not match in val_compare\n" );
|
||||
return F_CMP_ERROR;
|
||||
}
|
||||
|
||||
switch (v1->type) {
|
||||
case T_VOID:
|
||||
return 0;
|
||||
case T_ENUM:
|
||||
case T_INT:
|
||||
case T_BOOL:
|
||||
case T_PAIR:
|
||||
case T_QUAD:
|
||||
return uint_cmp(v1->val.i, v2->val.i);
|
||||
case T_EC:
|
||||
case T_RD:
|
||||
return u64_cmp(v1->val.ec, v2->val.ec);
|
||||
case T_LC:
|
||||
return lcomm_cmp(v1->val.lc, v2->val.lc);
|
||||
case T_IP:
|
||||
return ipa_compare(v1->val.ip, v2->val.ip);
|
||||
case T_NET:
|
||||
return net_compare(v1->val.net, v2->val.net);
|
||||
case T_STRING:
|
||||
return strcmp(v1->val.s, v2->val.s);
|
||||
default:
|
||||
return F_CMP_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
static inline int
|
||||
pmi_same(const struct f_path_mask_item *mi1, const struct f_path_mask_item *mi2)
|
||||
{
|
||||
if (mi1->kind != mi2->kind)
|
||||
return 0;
|
||||
|
||||
switch (mi1->kind) {
|
||||
case PM_ASN:
|
||||
if (mi1->asn != mi2->asn)
|
||||
return 0;
|
||||
break;
|
||||
case PM_ASN_EXPR:
|
||||
if (!f_same(mi1->expr, mi2->expr))
|
||||
return 0;
|
||||
break;
|
||||
case PM_ASN_RANGE:
|
||||
if (mi1->from != mi2->from)
|
||||
return 0;
|
||||
if (mi1->to != mi2->to)
|
||||
return 0;
|
||||
break;
|
||||
case PM_ASN_SET:
|
||||
if (!same_tree(mi1->set, mi2->set))
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
pm_same(const struct f_path_mask *m1, const struct f_path_mask *m2)
|
||||
{
|
||||
if (m1->len != m2->len)
|
||||
return 0;
|
||||
|
||||
for (uint i=0; i<m1->len; i++)
|
||||
if (!pmi_same(&(m1->item[i]), &(m2->item[i])))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* val_same - compare two values
|
||||
* @v1: first value
|
||||
* @v2: second value
|
||||
*
|
||||
* Compares two values and returns 1 if they are same and 0 if not.
|
||||
* Comparison of values of different types is valid and returns 0.
|
||||
*/
|
||||
int
|
||||
val_same(const struct f_val *v1, const struct f_val *v2)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = val_compare(v1, v2);
|
||||
if (rc != F_CMP_ERROR)
|
||||
return !rc;
|
||||
|
||||
if (v1->type != v2->type)
|
||||
return 0;
|
||||
|
||||
switch (v1->type) {
|
||||
case T_PATH_MASK:
|
||||
return pm_same(v1->val.path_mask, v2->val.path_mask);
|
||||
case T_PATH_MASK_ITEM:
|
||||
return pmi_same(&(v1->val.pmi), &(v2->val.pmi));
|
||||
case T_PATH:
|
||||
case T_CLIST:
|
||||
case T_ECLIST:
|
||||
case T_LCLIST:
|
||||
return adata_same(v1->val.ad, v2->val.ad);
|
||||
case T_SET:
|
||||
return same_tree(v1->val.t, v2->val.t);
|
||||
case T_PREFIX_SET:
|
||||
return trie_same(v1->val.ti, v2->val.ti);
|
||||
default:
|
||||
bug("Invalid type in val_same(): %x", v1->type);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
clist_set_type(const struct f_tree *set, struct f_val *v)
|
||||
{
|
||||
switch (set->from.type)
|
||||
{
|
||||
case T_PAIR:
|
||||
v->type = T_PAIR;
|
||||
return 1;
|
||||
|
||||
case T_QUAD:
|
||||
v->type = T_QUAD;
|
||||
return 1;
|
||||
|
||||
case T_IP:
|
||||
if (val_is_ip4(&(set->from)) && val_is_ip4(&(set->to)))
|
||||
{
|
||||
v->type = T_QUAD;
|
||||
return 1;
|
||||
}
|
||||
/* Fall through */
|
||||
default:
|
||||
v->type = T_VOID;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
clist_match_set(const struct adata *clist, const struct f_tree *set)
|
||||
{
|
||||
if (!clist)
|
||||
return 0;
|
||||
|
||||
struct f_val v;
|
||||
if (!clist_set_type(set, &v))
|
||||
return F_CMP_ERROR;
|
||||
|
||||
u32 *l = (u32 *) clist->data;
|
||||
u32 *end = l + clist->length/4;
|
||||
|
||||
while (l < end) {
|
||||
v.val.i = *l++;
|
||||
if (find_tree(set, &v))
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
eclist_match_set(const struct adata *list, const struct f_tree *set)
|
||||
{
|
||||
if (!list)
|
||||
return 0;
|
||||
|
||||
if (!eclist_set_type(set))
|
||||
return F_CMP_ERROR;
|
||||
|
||||
struct f_val v;
|
||||
u32 *l = int_set_get_data(list);
|
||||
int len = int_set_get_size(list);
|
||||
int i;
|
||||
|
||||
v.type = T_EC;
|
||||
for (i = 0; i < len; i += 2) {
|
||||
v.val.ec = ec_get(l, i);
|
||||
if (find_tree(set, &v))
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
lclist_match_set(const struct adata *list, const struct f_tree *set)
|
||||
{
|
||||
if (!list)
|
||||
return 0;
|
||||
|
||||
if (!lclist_set_type(set))
|
||||
return F_CMP_ERROR;
|
||||
|
||||
struct f_val v;
|
||||
u32 *l = int_set_get_data(list);
|
||||
int len = int_set_get_size(list);
|
||||
int i;
|
||||
|
||||
v.type = T_LC;
|
||||
for (i = 0; i < len; i += 3) {
|
||||
v.val.lc = lc_get(l, i);
|
||||
if (find_tree(set, &v))
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const struct adata *
|
||||
clist_filter(struct linpool *pool, const struct adata *list, const struct f_val *set, int pos)
|
||||
{
|
||||
if (!list)
|
||||
return NULL;
|
||||
|
||||
int tree = (set->type == T_SET); /* 1 -> set is T_SET, 0 -> set is T_CLIST */
|
||||
struct f_val v;
|
||||
if (tree)
|
||||
clist_set_type(set->val.t, &v);
|
||||
else
|
||||
v.type = T_PAIR;
|
||||
|
||||
int len = int_set_get_size(list);
|
||||
u32 *l = int_set_get_data(list);
|
||||
u32 tmp[len];
|
||||
u32 *k = tmp;
|
||||
u32 *end = l + len;
|
||||
|
||||
while (l < end) {
|
||||
v.val.i = *l++;
|
||||
/* pos && member(val, set) || !pos && !member(val, set), member() depends on tree */
|
||||
if ((tree ? !!find_tree(set->val.t, &v) : int_set_contains(set->val.ad, v.val.i)) == pos)
|
||||
*k++ = v.val.i;
|
||||
}
|
||||
|
||||
uint nl = (k - tmp) * sizeof(u32);
|
||||
if (nl == list->length)
|
||||
return list;
|
||||
|
||||
struct adata *res = adata_empty(pool, nl);
|
||||
memcpy(res->data, tmp, nl);
|
||||
return res;
|
||||
}
|
||||
|
||||
const struct adata *
|
||||
eclist_filter(struct linpool *pool, const struct adata *list, const struct f_val *set, int pos)
|
||||
{
|
||||
if (!list)
|
||||
return NULL;
|
||||
|
||||
int tree = (set->type == T_SET); /* 1 -> set is T_SET, 0 -> set is T_CLIST */
|
||||
struct f_val v;
|
||||
|
||||
int len = int_set_get_size(list);
|
||||
u32 *l = int_set_get_data(list);
|
||||
u32 tmp[len];
|
||||
u32 *k = tmp;
|
||||
int i;
|
||||
|
||||
v.type = T_EC;
|
||||
for (i = 0; i < len; i += 2) {
|
||||
v.val.ec = ec_get(l, i);
|
||||
/* pos && member(val, set) || !pos && !member(val, set), member() depends on tree */
|
||||
if ((tree ? !!find_tree(set->val.t, &v) : ec_set_contains(set->val.ad, v.val.ec)) == pos) {
|
||||
*k++ = l[i];
|
||||
*k++ = l[i+1];
|
||||
}
|
||||
}
|
||||
|
||||
uint nl = (k - tmp) * sizeof(u32);
|
||||
if (nl == list->length)
|
||||
return list;
|
||||
|
||||
struct adata *res = adata_empty(pool, nl);
|
||||
memcpy(res->data, tmp, nl);
|
||||
return res;
|
||||
}
|
||||
|
||||
const struct adata *
|
||||
lclist_filter(struct linpool *pool, const struct adata *list, const struct f_val *set, int pos)
|
||||
{
|
||||
if (!list)
|
||||
return NULL;
|
||||
|
||||
int tree = (set->type == T_SET); /* 1 -> set is T_SET, 0 -> set is T_CLIST */
|
||||
struct f_val v;
|
||||
|
||||
int len = int_set_get_size(list);
|
||||
u32 *l = int_set_get_data(list);
|
||||
u32 tmp[len];
|
||||
u32 *k = tmp;
|
||||
int i;
|
||||
|
||||
v.type = T_LC;
|
||||
for (i = 0; i < len; i += 3) {
|
||||
v.val.lc = lc_get(l, i);
|
||||
/* pos && member(val, set) || !pos && !member(val, set), member() depends on tree */
|
||||
if ((tree ? !!find_tree(set->val.t, &v) : lc_set_contains(set->val.ad, v.val.lc)) == pos)
|
||||
k = lc_copy(k, l+i);
|
||||
}
|
||||
|
||||
uint nl = (k - tmp) * sizeof(u32);
|
||||
if (nl == list->length)
|
||||
return list;
|
||||
|
||||
struct adata *res = adata_empty(pool, nl);
|
||||
memcpy(res->data, tmp, nl);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* val_in_range - implement |~| operator
|
||||
* @v1: element
|
||||
* @v2: set
|
||||
*
|
||||
* Checks if @v1 is element (|~| operator) of @v2.
|
||||
*/
|
||||
int
|
||||
val_in_range(const struct f_val *v1, const struct f_val *v2)
|
||||
{
|
||||
if ((v1->type == T_PATH) && (v2->type == T_PATH_MASK))
|
||||
return as_path_match(v1->val.ad, v2->val.path_mask);
|
||||
|
||||
if ((v1->type == T_INT) && (v2->type == T_PATH))
|
||||
return as_path_contains(v2->val.ad, v1->val.i, 1);
|
||||
|
||||
if (((v1->type == T_PAIR) || (v1->type == T_QUAD)) && (v2->type == T_CLIST))
|
||||
return int_set_contains(v2->val.ad, v1->val.i);
|
||||
/* IP->Quad implicit conversion */
|
||||
if (val_is_ip4(v1) && (v2->type == T_CLIST))
|
||||
return int_set_contains(v2->val.ad, ipa_to_u32(v1->val.ip));
|
||||
|
||||
if ((v1->type == T_EC) && (v2->type == T_ECLIST))
|
||||
return ec_set_contains(v2->val.ad, v1->val.ec);
|
||||
|
||||
if ((v1->type == T_LC) && (v2->type == T_LCLIST))
|
||||
return lc_set_contains(v2->val.ad, v1->val.lc);
|
||||
|
||||
if ((v1->type == T_STRING) && (v2->type == T_STRING))
|
||||
return patmatch(v2->val.s, v1->val.s);
|
||||
|
||||
if ((v1->type == T_IP) && (v2->type == T_NET))
|
||||
return ipa_in_netX(v1->val.ip, v2->val.net);
|
||||
|
||||
if ((v1->type == T_NET) && (v2->type == T_NET))
|
||||
return net_in_netX(v1->val.net, v2->val.net);
|
||||
|
||||
if ((v1->type == T_NET) && (v2->type == T_PREFIX_SET))
|
||||
return trie_match_net(v2->val.ti, v1->val.net);
|
||||
|
||||
if (v2->type != T_SET)
|
||||
return F_CMP_ERROR;
|
||||
|
||||
/* With integrated Quad<->IP implicit conversion */
|
||||
if ((v1->type == v2->val.t->from.type) ||
|
||||
((v1->type == T_QUAD) && val_is_ip4(&(v2->val.t->from)) && val_is_ip4(&(v2->val.t->to))))
|
||||
return !!find_tree(v2->val.t, v1);
|
||||
|
||||
if (v1->type == T_CLIST)
|
||||
return clist_match_set(v1->val.ad, v2->val.t);
|
||||
|
||||
if (v1->type == T_ECLIST)
|
||||
return eclist_match_set(v1->val.ad, v2->val.t);
|
||||
|
||||
if (v1->type == T_LCLIST)
|
||||
return lclist_match_set(v1->val.ad, v2->val.t);
|
||||
|
||||
if (v1->type == T_PATH)
|
||||
return as_path_match_set(v1->val.ad, v2->val.t);
|
||||
|
||||
return F_CMP_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* val_format - format filter value
|
||||
*/
|
||||
void
|
||||
val_format(const struct f_val *v, buffer *buf)
|
||||
{
|
||||
char buf2[1024];
|
||||
switch (v->type)
|
||||
{
|
||||
case T_VOID: buffer_puts(buf, "(void)"); return;
|
||||
case T_BOOL: buffer_puts(buf, v->val.i ? "TRUE" : "FALSE"); return;
|
||||
case T_INT: buffer_print(buf, "%u", v->val.i); return;
|
||||
case T_STRING: buffer_print(buf, "%s", v->val.s); return;
|
||||
case T_IP: buffer_print(buf, "%I", v->val.ip); return;
|
||||
case T_NET: buffer_print(buf, "%N", v->val.net); return;
|
||||
case T_PAIR: buffer_print(buf, "(%u,%u)", v->val.i >> 16, v->val.i & 0xffff); return;
|
||||
case T_QUAD: buffer_print(buf, "%R", v->val.i); return;
|
||||
case T_EC: ec_format(buf2, v->val.ec); buffer_print(buf, "%s", buf2); return;
|
||||
case T_LC: lc_format(buf2, v->val.lc); buffer_print(buf, "%s", buf2); return;
|
||||
case T_RD: rd_format(v->val.ec, buf2, 1024); buffer_print(buf, "%s", buf2); return;
|
||||
case T_PREFIX_SET: trie_format(v->val.ti, buf); return;
|
||||
case T_SET: tree_format(v->val.t, buf); return;
|
||||
case T_ENUM: buffer_print(buf, "(enum %x)%u", v->type, v->val.i); return;
|
||||
case T_PATH: as_path_format(v->val.ad, buf2, 1000); buffer_print(buf, "(path %s)", buf2); return;
|
||||
case T_CLIST: int_set_format(v->val.ad, 1, -1, buf2, 1000); buffer_print(buf, "(clist %s)", buf2); return;
|
||||
case T_ECLIST: ec_set_format(v->val.ad, -1, buf2, 1000); buffer_print(buf, "(eclist %s)", buf2); return;
|
||||
case T_LCLIST: lc_set_format(v->val.ad, -1, buf2, 1000); buffer_print(buf, "(lclist %s)", buf2); return;
|
||||
case T_PATH_MASK: pm_format(v->val.path_mask, buf); return;
|
||||
default: buffer_print(buf, "[unknown type %x]", v->type); return;
|
||||
}
|
||||
}
|
||||
|
||||
char *
|
||||
val_format_str(struct linpool *lp, const struct f_val *v) {
|
||||
buffer b;
|
||||
LOG_BUFFER_INIT(b);
|
||||
val_format(v, &b);
|
||||
return lp_strdup(lp, b.start);
|
||||
}
|
||||
|
||||
|
||||
static char val_dump_buffer[1024];
|
||||
const char *
|
||||
val_dump(const struct f_val *v) {
|
||||
static buffer b = {
|
||||
.start = val_dump_buffer,
|
||||
.end = val_dump_buffer + 1024,
|
||||
};
|
||||
b.pos = b.start;
|
||||
val_format(v, &b);
|
||||
return val_dump_buffer;
|
||||
}
|
||||
|
224
filter/data.h
Normal file
224
filter/data.h
Normal file
@ -0,0 +1,224 @@
|
||||
/*
|
||||
* BIRD Internet Routing Daemon -- Dynamic data structures
|
||||
*
|
||||
* (c) 1999 Pavel Machek <pavel@ucw.cz>
|
||||
* (c) 2018--2019 Maria Matejka <mq@jmq.cz>
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#ifndef _BIRD_FILTER_DATA_H_
|
||||
#define _BIRD_FILTER_DATA_H_
|
||||
|
||||
#include "nest/bird.h"
|
||||
|
||||
/* Type numbers must be in 0..0xff range */
|
||||
#define T_MASK 0xff
|
||||
|
||||
/* Internal types */
|
||||
enum f_type {
|
||||
/* Nothing. Simply nothing. */
|
||||
T_VOID = 0,
|
||||
|
||||
/* User visible types, which fit in int */
|
||||
T_INT = 0x10,
|
||||
T_BOOL = 0x11,
|
||||
T_PAIR = 0x12, /* Notice that pair is stored as integer: first << 16 | second */
|
||||
T_QUAD = 0x13,
|
||||
|
||||
/* Put enumerational types in 0x30..0x3f range */
|
||||
T_ENUM_LO = 0x30,
|
||||
T_ENUM_HI = 0x3f,
|
||||
|
||||
T_ENUM_RTS = 0x30,
|
||||
T_ENUM_BGP_ORIGIN = 0x31,
|
||||
T_ENUM_SCOPE = 0x32,
|
||||
T_ENUM_RTC = 0x33,
|
||||
T_ENUM_RTD = 0x34,
|
||||
T_ENUM_ROA = 0x35,
|
||||
T_ENUM_NETTYPE = 0x36,
|
||||
T_ENUM_RA_PREFERENCE = 0x37,
|
||||
T_ENUM_AF = 0x38,
|
||||
|
||||
/* new enums go here */
|
||||
T_ENUM_EMPTY = 0x3f, /* Special hack for atomic_aggr */
|
||||
|
||||
#define T_ENUM T_ENUM_LO ... T_ENUM_HI
|
||||
|
||||
/* Bigger ones */
|
||||
T_IP = 0x20,
|
||||
T_NET = 0x21,
|
||||
T_STRING = 0x22,
|
||||
T_PATH_MASK = 0x23, /* mask for BGP path */
|
||||
T_PATH = 0x24, /* BGP path */
|
||||
T_CLIST = 0x25, /* Community list */
|
||||
T_EC = 0x26, /* Extended community value, u64 */
|
||||
T_ECLIST = 0x27, /* Extended community list */
|
||||
T_LC = 0x28, /* Large community value, lcomm */
|
||||
T_LCLIST = 0x29, /* Large community list */
|
||||
T_RD = 0x2a, /* Route distinguisher for VPN addresses */
|
||||
T_PATH_MASK_ITEM = 0x2b, /* Path mask item for path mask constructors */
|
||||
|
||||
T_SET = 0x80,
|
||||
T_PREFIX_SET = 0x81,
|
||||
} PACKED;
|
||||
|
||||
/* Filter value; size of this affects filter memory consumption */
|
||||
struct f_val {
|
||||
enum f_type type; /* T_* */
|
||||
union {
|
||||
uint i;
|
||||
u64 ec;
|
||||
lcomm lc;
|
||||
ip_addr ip;
|
||||
const net_addr *net;
|
||||
const char *s;
|
||||
const struct f_tree *t;
|
||||
const struct f_trie *ti;
|
||||
const struct adata *ad;
|
||||
const struct f_path_mask *path_mask;
|
||||
struct f_path_mask_item pmi;
|
||||
} val;
|
||||
};
|
||||
|
||||
/* Dynamic attribute definition (eattrs) */
|
||||
struct f_dynamic_attr {
|
||||
u8 type; /* EA type (EAF_*) */
|
||||
u8 bit; /* For bitfield accessors */
|
||||
enum f_type f_type; /* Filter type */
|
||||
uint ea_code; /* EA code */
|
||||
};
|
||||
|
||||
enum f_sa_code {
|
||||
SA_FROM = 1,
|
||||
SA_GW,
|
||||
SA_NET,
|
||||
SA_PROTO,
|
||||
SA_SOURCE,
|
||||
SA_SCOPE,
|
||||
SA_DEST,
|
||||
SA_IFNAME,
|
||||
SA_IFINDEX,
|
||||
SA_WEIGHT,
|
||||
} PACKED;
|
||||
|
||||
/* Static attribute definition (members of struct rta) */
|
||||
struct f_static_attr {
|
||||
enum f_type f_type; /* Filter type */
|
||||
enum f_sa_code sa_code; /* Static attribute id */
|
||||
int readonly:1; /* Don't allow writing */
|
||||
};
|
||||
|
||||
/* Filter l-value type */
|
||||
enum f_lval_type {
|
||||
F_LVAL_VARIABLE,
|
||||
F_LVAL_PREFERENCE,
|
||||
F_LVAL_SA,
|
||||
F_LVAL_EA,
|
||||
};
|
||||
|
||||
/* Filter l-value */
|
||||
struct f_lval {
|
||||
enum f_lval_type type;
|
||||
union {
|
||||
struct symbol *sym;
|
||||
struct f_dynamic_attr da;
|
||||
struct f_static_attr sa;
|
||||
};
|
||||
};
|
||||
|
||||
/* IP prefix range structure */
|
||||
struct f_prefix {
|
||||
net_addr net; /* The matching prefix must match this net */
|
||||
u8 lo, hi; /* And its length must fit between lo and hi */
|
||||
};
|
||||
|
||||
struct f_tree {
|
||||
struct f_tree *left, *right;
|
||||
struct f_val from, to;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct f_trie_node4
|
||||
{
|
||||
ip4_addr addr, mask, accept;
|
||||
uint plen;
|
||||
struct f_trie_node4 *c[2];
|
||||
};
|
||||
|
||||
struct f_trie_node6
|
||||
{
|
||||
ip6_addr addr, mask, accept;
|
||||
uint plen;
|
||||
struct f_trie_node6 *c[2];
|
||||
};
|
||||
|
||||
struct f_trie_node
|
||||
{
|
||||
union {
|
||||
struct f_trie_node4 v4;
|
||||
struct f_trie_node6 v6;
|
||||
};
|
||||
};
|
||||
|
||||
struct f_trie
|
||||
{
|
||||
linpool *lp;
|
||||
u8 zero;
|
||||
s8 ipv4; /* -1 for undefined / empty */
|
||||
u16 data_size; /* Additional data for each trie node */
|
||||
struct f_trie_node root; /* Root trie node */
|
||||
};
|
||||
|
||||
struct f_tree *f_new_tree(void);
|
||||
struct f_tree *build_tree(struct f_tree *);
|
||||
const struct f_tree *find_tree(const struct f_tree *t, const struct f_val *val);
|
||||
int same_tree(const struct f_tree *t0, const struct f_tree *t2);
|
||||
void tree_format(const struct f_tree *t, buffer *buf);
|
||||
void tree_walk(const struct f_tree *t, void (*hook)(const struct f_tree *, void *), void *data);
|
||||
|
||||
struct f_trie *f_new_trie(linpool *lp, uint data_size);
|
||||
void *trie_add_prefix(struct f_trie *t, const net_addr *n, uint l, uint h);
|
||||
int trie_match_net(const struct f_trie *t, const net_addr *n);
|
||||
int trie_same(const struct f_trie *t1, const struct f_trie *t2);
|
||||
void trie_format(const struct f_trie *t, buffer *buf);
|
||||
|
||||
#define F_CMP_ERROR 999
|
||||
|
||||
const char *f_type_name(enum f_type t);
|
||||
|
||||
int val_same(const struct f_val *v1, const struct f_val *v2);
|
||||
int val_compare(const struct f_val *v1, const struct f_val *v2);
|
||||
void val_format(const struct f_val *v, buffer *buf);
|
||||
char *val_format_str(struct linpool *lp, const struct f_val *v);
|
||||
const char *val_dump(const struct f_val *v);
|
||||
|
||||
static inline int val_is_ip4(const struct f_val *v)
|
||||
{ return (v->type == T_IP) && ipa_is_ip4(v->val.ip); }
|
||||
int val_in_range(const struct f_val *v1, const struct f_val *v2);
|
||||
|
||||
int clist_set_type(const struct f_tree *set, struct f_val *v);
|
||||
static inline int eclist_set_type(const struct f_tree *set)
|
||||
{ return set->from.type == T_EC; }
|
||||
static inline int lclist_set_type(const struct f_tree *set)
|
||||
{ return set->from.type == T_LC; }
|
||||
|
||||
const struct adata *clist_filter(struct linpool *pool, const struct adata *list, const struct f_val *set, int pos);
|
||||
const struct adata *eclist_filter(struct linpool *pool, const struct adata *list, const struct f_val *set, int pos);
|
||||
const struct adata *lclist_filter(struct linpool *pool, const struct adata *list, const struct f_val *set, int pos);
|
||||
|
||||
|
||||
/* Special undef value for paths and clists */
|
||||
static inline int
|
||||
undef_value(struct f_val v)
|
||||
{
|
||||
return ((v.type == T_PATH) || (v.type == T_CLIST) ||
|
||||
(v.type == T_ECLIST) || (v.type == T_LCLIST)) &&
|
||||
(v.val.ad == &null_adata);
|
||||
}
|
||||
|
||||
extern const struct f_val f_const_empty_path, f_const_empty_clist, f_const_empty_eclist, f_const_empty_lclist;
|
||||
|
||||
enum filter_return f_eval(const struct f_line *expr, struct linpool *tmp_pool, struct f_val *pres);
|
||||
|
||||
#endif
|
673
filter/decl.m4
Normal file
673
filter/decl.m4
Normal file
@ -0,0 +1,673 @@
|
||||
m4_divert(-1)m4_dnl
|
||||
#
|
||||
# BIRD -- Construction of per-instruction structures
|
||||
#
|
||||
# (c) 2018 Maria Matejka <mq@jmq.cz>
|
||||
#
|
||||
# Can be freely distributed and used under the terms of the GNU GPL.
|
||||
#
|
||||
# THIS IS A M4 MACRO FILE GENERATING 3 FILES ALTOGETHER.
|
||||
# KEEP YOUR HANDS OFF UNLESS YOU KNOW WHAT YOU'RE DOING.
|
||||
# EDITING AND DEBUGGING THIS FILE MAY DAMAGE YOUR BRAIN SERIOUSLY.
|
||||
#
|
||||
# But you're welcome to read and edit and debug if you aren't scared.
|
||||
#
|
||||
# Uncomment the following line to get exhaustive debug output.
|
||||
# m4_debugmode(aceflqtx)
|
||||
#
|
||||
# How it works:
|
||||
# 1) Instruction to code conversion (uses diversions 100..199)
|
||||
# 2) Code wrapping (uses diversions 1..99)
|
||||
# 3) Final preparation (uses diversions 200..299)
|
||||
# 4) Shipout
|
||||
#
|
||||
# See below for detailed description.
|
||||
#
|
||||
#
|
||||
# 1) Instruction to code conversion
|
||||
# The code provided in f-inst.c between consecutive INST() calls
|
||||
# is interleaved for many different places. It is here processed
|
||||
# and split into separate instances where split-by-instruction
|
||||
# happens. These parts are stored in temporary diversions listed:
|
||||
#
|
||||
# 101 content of per-inst struct
|
||||
# 102 constructor arguments
|
||||
# 103 constructor body
|
||||
# 104 dump line item content
|
||||
# (there may be nothing in dump-line content and
|
||||
# it must be handled specially in phase 2)
|
||||
# 105 linearize body
|
||||
# 106 comparator body
|
||||
# 107 struct f_line_item content
|
||||
# 108 interpreter body
|
||||
# 109 iterator body
|
||||
#
|
||||
# Here are macros to allow you to _divert to the right directions.
|
||||
m4_define(FID_STRUCT_IN, `m4_divert(101)')
|
||||
m4_define(FID_NEW_ARGS, `m4_divert(102)')
|
||||
m4_define(FID_NEW_BODY, `m4_divert(103)')
|
||||
m4_define(FID_DUMP_BODY, `m4_divert(104)m4_define([[FID_DUMP_BODY_EXISTS]])')
|
||||
m4_define(FID_LINEARIZE_BODY, `m4_divert(105)')
|
||||
m4_define(FID_SAME_BODY, `m4_divert(106)')
|
||||
m4_define(FID_LINE_IN, `m4_divert(107)')
|
||||
m4_define(FID_INTERPRET_BODY, `m4_divert(108)')
|
||||
m4_define(FID_ITERATE_BODY, `m4_divert(109)')
|
||||
|
||||
# Sometimes you want slightly different code versions in different
|
||||
# outputs.
|
||||
# Use FID_HIC(code for inst-gen.h, code for inst-gen.c, code for inst-interpret.c)
|
||||
# and put it into [[ ]] quotes if it shall contain commas.
|
||||
m4_define(FID_HIC, `m4_ifelse(TARGET, [[H]], [[$1]], TARGET, [[I]], [[$2]], TARGET, [[C]], [[$3]])')
|
||||
|
||||
# In interpreter code, this is quite common.
|
||||
m4_define(FID_INTERPRET_EXEC, `FID_HIC(,[[FID_INTERPRET_BODY()]],[[m4_divert(-1)]])')
|
||||
m4_define(FID_INTERPRET_NEW, `FID_HIC(,[[m4_divert(-1)]],[[FID_INTERPRET_BODY()]])')
|
||||
|
||||
# If the instruction is never converted to constant, the interpret
|
||||
# code is not produced at all for constructor
|
||||
m4_define(NEVER_CONSTANT, `m4_define([[INST_NEVER_CONSTANT]])')
|
||||
m4_define(FID_IFCONST, `m4_ifdef([[INST_NEVER_CONSTANT]],[[$2]],[[$1]])')
|
||||
|
||||
# If the instruction has some attributes (here called members),
|
||||
# these are typically carried with the instruction from constructor
|
||||
# to interpreter. This yields a line of code everywhere on the path.
|
||||
# FID_MEMBER is a macro to help with this task.
|
||||
m4_define(FID_MEMBER, `m4_dnl
|
||||
FID_LINE_IN()m4_dnl
|
||||
$1 $2;
|
||||
FID_STRUCT_IN()m4_dnl
|
||||
$1 $2;
|
||||
FID_NEW_ARGS()m4_dnl
|
||||
, $1 $2
|
||||
FID_NEW_BODY()m4_dnl
|
||||
whati->$2 = $2;
|
||||
FID_LINEARIZE_BODY()m4_dnl
|
||||
item->$2 = whati->$2;
|
||||
m4_ifelse($3,,,[[
|
||||
FID_SAME_BODY()m4_dnl
|
||||
if ($3) return 0;
|
||||
]])
|
||||
m4_ifelse($4,,,[[
|
||||
FID_DUMP_BODY()m4_dnl
|
||||
debug("%s" $4 "\n", INDENT, $5);
|
||||
]])
|
||||
FID_INTERPRET_EXEC()m4_dnl
|
||||
const $1 $2 = whati->$2
|
||||
FID_INTERPRET_BODY')
|
||||
|
||||
# Instruction arguments are needed only until linearization is done.
|
||||
# This puts the arguments into the filter line to be executed before
|
||||
# the instruction itself.
|
||||
#
|
||||
# To achieve this, ARG_ANY must be called before anything writes into
|
||||
# the instruction line as it moves the instruction pointer forward.
|
||||
m4_define(ARG_ANY, `
|
||||
FID_STRUCT_IN()m4_dnl
|
||||
struct f_inst * f$1;
|
||||
FID_NEW_ARGS()m4_dnl
|
||||
, struct f_inst * f$1
|
||||
FID_NEW_BODY()m4_dnl
|
||||
whati->f$1 = f$1;
|
||||
for (const struct f_inst *child = f$1; child; child = child->next) {
|
||||
what->size += child->size;
|
||||
FID_IFCONST([[
|
||||
if (child->fi_code != FI_CONSTANT)
|
||||
constargs = 0;
|
||||
]])
|
||||
}
|
||||
FID_LINEARIZE_BODY
|
||||
pos = linearize(dest, whati->f$1, pos);
|
||||
FID_INTERPRET_BODY()')
|
||||
|
||||
# Some instructions accept variable number of arguments.
|
||||
m4_define(VARARG, `
|
||||
FID_NEW_ARGS()m4_dnl
|
||||
, struct f_inst * fvar
|
||||
FID_STRUCT_IN()m4_dnl
|
||||
struct f_inst * fvar;
|
||||
uint varcount;
|
||||
FID_LINE_IN()m4_dnl
|
||||
uint varcount;
|
||||
FID_NEW_BODY()m4_dnl
|
||||
whati->varcount = 0;
|
||||
whati->fvar = fvar;
|
||||
for (const struct f_inst *child = fvar; child; child = child->next, whati->varcount++) {
|
||||
what->size += child->size;
|
||||
FID_IFCONST([[
|
||||
if (child->fi_code != FI_CONSTANT)
|
||||
constargs = 0;
|
||||
]])
|
||||
}
|
||||
FID_IFCONST([[
|
||||
const struct f_inst **items = NULL;
|
||||
if (constargs && whati->varcount) {
|
||||
items = alloca(whati->varcount * sizeof(struct f_inst *));
|
||||
const struct f_inst *child = fvar;
|
||||
for (uint i=0; child; i++)
|
||||
child = (items[i] = child)->next;
|
||||
}
|
||||
]])
|
||||
FID_LINEARIZE_BODY()m4_dnl
|
||||
pos = linearize(dest, whati->fvar, pos);
|
||||
item->varcount = whati->varcount;
|
||||
FID_DUMP_BODY()m4_dnl
|
||||
debug("%snumber of varargs %u\n", INDENT, item->varcount);
|
||||
FID_SAME_BODY()m4_dnl
|
||||
if (f1->varcount != f2->varcount) return 0;
|
||||
FID_INTERPRET_BODY()
|
||||
FID_HIC(,[[
|
||||
if (fstk->vcnt < whati->varcount) runtime("Stack underflow");
|
||||
fstk->vcnt -= whati->varcount;
|
||||
]],)
|
||||
')
|
||||
|
||||
# Some arguments need to check their type. After that, ARG_ANY is called.
|
||||
m4_define(ARG, `ARG_ANY($1) ARG_TYPE($1,$2)')
|
||||
m4_define(ARG_TYPE, `ARG_TYPE_STATIC($1,$2) ARG_TYPE_DYNAMIC($1,$2)')
|
||||
|
||||
m4_define(ARG_TYPE_STATIC, `
|
||||
FID_NEW_BODY()m4_dnl
|
||||
if (f$1->type && (f$1->type != ($2)) && !f_const_promotion(f$1, ($2)))
|
||||
cf_error("Argument $1 of %s must be of type %s, got type %s",
|
||||
f_instruction_name(what->fi_code), f_type_name($2), f_type_name(f$1->type));
|
||||
FID_INTERPRET_BODY()')
|
||||
|
||||
m4_define(ARG_TYPE_DYNAMIC, `
|
||||
FID_INTERPRET_EXEC()m4_dnl
|
||||
if (v$1.type != ($2))
|
||||
runtime("Argument $1 of %s must be of type %s, got type %s",
|
||||
f_instruction_name(what->fi_code), f_type_name($2), f_type_name(v$1.type));
|
||||
FID_INTERPRET_BODY()')
|
||||
|
||||
m4_define(ARG_SAME_TYPE, `
|
||||
FID_NEW_BODY()m4_dnl
|
||||
if (f$1->type && f$2->type && (f$1->type != f$2->type) &&
|
||||
!f_const_promotion(f$2, f$1->type) && !f_const_promotion(f$1, f$2->type))
|
||||
cf_error("Arguments $1 and $2 of %s must be of the same type", f_instruction_name(what->fi_code));
|
||||
FID_INTERPRET_BODY()')
|
||||
|
||||
# Executing another filter line. This replaces the recursion
|
||||
# that was needed in the former implementation.
|
||||
m4_define(LINEX, `FID_INTERPRET_EXEC()LINEX_($1)FID_INTERPRET_NEW()return $1 FID_INTERPRET_BODY()')
|
||||
m4_define(LINEX_, `do {
|
||||
fstk->estk[fstk->ecnt].pos = 0;
|
||||
fstk->estk[fstk->ecnt].line = $1;
|
||||
fstk->estk[fstk->ecnt].ventry = fstk->vcnt;
|
||||
fstk->estk[fstk->ecnt].vbase = fstk->estk[fstk->ecnt-1].vbase;
|
||||
fstk->estk[fstk->ecnt].emask = 0;
|
||||
fstk->ecnt++;
|
||||
} while (0)')
|
||||
|
||||
m4_define(LINE, `
|
||||
FID_LINE_IN()m4_dnl
|
||||
const struct f_line * fl$1;
|
||||
FID_STRUCT_IN()m4_dnl
|
||||
struct f_inst * f$1;
|
||||
FID_NEW_ARGS()m4_dnl
|
||||
, struct f_inst * f$1
|
||||
FID_NEW_BODY()m4_dnl
|
||||
whati->f$1 = f$1;
|
||||
FID_DUMP_BODY()m4_dnl
|
||||
f_dump_line(item->fl$1, indent + 1);
|
||||
FID_LINEARIZE_BODY()m4_dnl
|
||||
item->fl$1 = f_linearize(whati->f$1);
|
||||
FID_SAME_BODY()m4_dnl
|
||||
if (!f_same(f1->fl$1, f2->fl$1)) return 0;
|
||||
FID_ITERATE_BODY()m4_dnl
|
||||
if (whati->fl$1) BUFFER_PUSH(fit->lines) = whati->fl$1;
|
||||
FID_INTERPRET_EXEC()m4_dnl
|
||||
do { if (whati->fl$1) {
|
||||
LINEX_(whati->fl$1);
|
||||
} } while(0)
|
||||
FID_INTERPRET_NEW()m4_dnl
|
||||
return whati->f$1
|
||||
FID_INTERPRET_BODY()')
|
||||
|
||||
# Some of the instructions have a result. These constructions
|
||||
# state the result and put it to the right place.
|
||||
m4_define(RESULT, `RESULT_TYPE([[$1]]) RESULT_([[$1]],[[$2]],[[$3]])')
|
||||
m4_define(RESULT_, `RESULT_VAL([[ (struct f_val) { .type = $1, .val.$2 = $3 } ]])')
|
||||
m4_define(RESULT_VAL, `FID_HIC(, [[do { res = $1; fstk->vcnt++; } while (0)]],
|
||||
[[return fi_constant(what, $1)]])')
|
||||
m4_define(RESULT_VOID, `RESULT_VAL([[ (struct f_val) { .type = T_VOID } ]])')
|
||||
|
||||
m4_define(ERROR,
|
||||
`m4_errprint(m4___file__:m4___line__: $*
|
||||
)m4_m4exit(1)')
|
||||
|
||||
# This macro specifies result type and makes there are no conflicting definitions
|
||||
m4_define(RESULT_TYPE,
|
||||
`m4_ifdef([[INST_RESULT_TYPE]],
|
||||
[[m4_ifelse(INST_RESULT_TYPE,$1,,[[ERROR([[Multiple type definitons]])]])]],
|
||||
[[m4_define(INST_RESULT_TYPE,$1) RESULT_TYPE_($1)]])')
|
||||
|
||||
m4_define(RESULT_TYPE_, `
|
||||
FID_NEW_BODY()m4_dnl
|
||||
what->type = $1;
|
||||
FID_INTERPRET_BODY()')
|
||||
|
||||
# Some common filter instruction members
|
||||
m4_define(SYMBOL, `FID_MEMBER(struct symbol *, sym, [[strcmp(f1->sym->name, f2->sym->name) || (f1->sym->class != f2->sym->class)]], "symbol %s", item->sym->name)')
|
||||
m4_define(RTC, `FID_MEMBER(struct rtable_config *, rtc, [[strcmp(f1->rtc->name, f2->rtc->name)]], "route table %s", item->rtc->name)')
|
||||
m4_define(STATIC_ATTR, `FID_MEMBER(struct f_static_attr, sa, f1->sa.sa_code != f2->sa.sa_code,,)')
|
||||
m4_define(DYNAMIC_ATTR, `FID_MEMBER(struct f_dynamic_attr, da, f1->da.ea_code != f2->da.ea_code,,)')
|
||||
m4_define(ACCESS_RTE, `FID_HIC(,[[do { if (!fs->rte) runtime("No route to access"); } while (0)]],NEVER_CONSTANT())')
|
||||
|
||||
# 2) Code wrapping
|
||||
# The code produced in 1xx temporary diversions is a raw code without
|
||||
# any auxiliary commands and syntactical structures around. When the
|
||||
# instruction is done, INST_FLUSH is called. More precisely, it is called
|
||||
# at the beginning of INST() call and at the end of file.
|
||||
#
|
||||
# INST_FLUSH picks all the temporary diversions, wraps their content
|
||||
# into appropriate headers and structures and saves them into global
|
||||
# diversions listed:
|
||||
#
|
||||
# 4 enum fi_code
|
||||
# 5 enum fi_code to string
|
||||
# 6 dump line item
|
||||
# 7 dump line item callers
|
||||
# 8 linearize
|
||||
# 9 same (filter comparator)
|
||||
# 10 iterate
|
||||
# 1 union in struct f_inst
|
||||
# 3 constructors + interpreter
|
||||
#
|
||||
# These global diversions contain blocks of code that can be directly
|
||||
# put into the final file, yet it still can't be written out now as
|
||||
# every instruction writes to all of these diversions.
|
||||
|
||||
# Code wrapping diversion names. Here we want an explicit newline
|
||||
# after the C comment.
|
||||
m4_define(FID_ZONE, `m4_divert($1) /* $2 for INST_NAME() */
|
||||
')
|
||||
m4_define(FID_INST, `FID_ZONE(1, Instruction structure for config)')
|
||||
m4_define(FID_LINE, `FID_ZONE(2, Instruction structure for interpreter)')
|
||||
m4_define(FID_NEW, `FID_ZONE(3, Constructor)')
|
||||
m4_define(FID_ENUM, `FID_ZONE(4, Code enum)')
|
||||
m4_define(FID_ENUM_STR, `FID_ZONE(5, Code enum to string)')
|
||||
m4_define(FID_DUMP, `FID_ZONE(6, Dump line)')
|
||||
m4_define(FID_DUMP_CALLER, `FID_ZONE(7, Dump line caller)')
|
||||
m4_define(FID_LINEARIZE, `FID_ZONE(8, Linearize)')
|
||||
m4_define(FID_SAME, `FID_ZONE(9, Comparison)')
|
||||
m4_define(FID_ITERATE, `FID_ZONE(10, Iteration)')
|
||||
|
||||
# This macro does all the code wrapping. See inline comments.
|
||||
m4_define(INST_FLUSH, `m4_ifdef([[INST_NAME]], [[
|
||||
FID_ENUM()m4_dnl Contents of enum fi_code { ... }
|
||||
INST_NAME(),
|
||||
FID_ENUM_STR()m4_dnl Contents of const char * indexed by enum fi_code
|
||||
[INST_NAME()] = "INST_NAME()",
|
||||
FID_INST()m4_dnl Anonymous structure inside struct f_inst
|
||||
struct {
|
||||
m4_undivert(101)m4_dnl
|
||||
} i_[[]]INST_NAME();
|
||||
FID_LINE()m4_dnl Anonymous structure inside struct f_line_item
|
||||
struct {
|
||||
m4_undivert(107)m4_dnl
|
||||
} i_[[]]INST_NAME();
|
||||
FID_NEW()m4_dnl Constructor and interpreter code together
|
||||
FID_HIC(
|
||||
[[m4_dnl Public declaration of constructor in H file
|
||||
struct f_inst *f_new_inst_]]INST_NAME()[[(enum f_instruction_code fi_code
|
||||
m4_undivert(102)m4_dnl
|
||||
);]],
|
||||
[[m4_dnl The one case in The Big Switch inside interpreter
|
||||
case INST_NAME():
|
||||
#define whati (&(what->i_]]INST_NAME()[[))
|
||||
m4_ifelse(m4_eval(INST_INVAL() > 0), 1, [[if (fstk->vcnt < INST_INVAL()) runtime("Stack underflow"); fstk->vcnt -= INST_INVAL(); ]])
|
||||
m4_undivert(108)m4_dnl
|
||||
#undef whati
|
||||
break;
|
||||
]],
|
||||
[[m4_dnl Constructor itself
|
||||
struct f_inst *f_new_inst_]]INST_NAME()[[(enum f_instruction_code fi_code
|
||||
m4_undivert(102)m4_dnl
|
||||
)
|
||||
{
|
||||
/* Allocate the structure */
|
||||
struct f_inst *what = fi_new(fi_code);
|
||||
FID_IFCONST([[uint constargs = 1;]])
|
||||
|
||||
/* Initialize all the members */
|
||||
#define whati (&(what->i_]]INST_NAME()[[))
|
||||
m4_undivert(103)m4_dnl
|
||||
|
||||
/* If not constant, return the instruction itself */
|
||||
FID_IFCONST([[if (!constargs)]])
|
||||
return what;
|
||||
|
||||
/* Try to pre-calculate the result */
|
||||
FID_IFCONST([[m4_undivert(108)]])m4_dnl
|
||||
#undef whati
|
||||
}
|
||||
]])
|
||||
|
||||
FID_DUMP_CALLER()m4_dnl Case in another big switch used in instruction dumping (debug)
|
||||
case INST_NAME(): f_dump_line_item_]]INST_NAME()[[(item, indent + 1); break;
|
||||
|
||||
FID_DUMP()m4_dnl The dumper itself
|
||||
m4_ifdef([[FID_DUMP_BODY_EXISTS]],
|
||||
[[static inline void f_dump_line_item_]]INST_NAME()[[(const struct f_line_item *item_, const int indent)]],
|
||||
[[static inline void f_dump_line_item_]]INST_NAME()[[(const struct f_line_item *item UNUSED, const int indent UNUSED)]])
|
||||
m4_undefine([[FID_DUMP_BODY_EXISTS]])
|
||||
{
|
||||
#define item (&(item_->i_]]INST_NAME()[[))
|
||||
m4_undivert(104)m4_dnl
|
||||
#undef item
|
||||
}
|
||||
|
||||
FID_LINEARIZE()m4_dnl The linearizer
|
||||
case INST_NAME(): {
|
||||
#define whati (&(what->i_]]INST_NAME()[[))
|
||||
#define item (&(dest->items[pos].i_]]INST_NAME()[[))
|
||||
m4_undivert(105)m4_dnl
|
||||
#undef whati
|
||||
#undef item
|
||||
dest->items[pos].fi_code = what->fi_code;
|
||||
dest->items[pos].lineno = what->lineno;
|
||||
break;
|
||||
}
|
||||
|
||||
FID_SAME()m4_dnl This code compares two f_line"s while reconfiguring
|
||||
case INST_NAME():
|
||||
#define f1 (&(f1_->i_]]INST_NAME()[[))
|
||||
#define f2 (&(f2_->i_]]INST_NAME()[[))
|
||||
m4_undivert(106)m4_dnl
|
||||
#undef f1
|
||||
#undef f2
|
||||
break;
|
||||
|
||||
FID_ITERATE()m4_dnl The iterator
|
||||
case INST_NAME():
|
||||
#define whati (&(what->i_]]INST_NAME()[[))
|
||||
m4_undivert(109)m4_dnl
|
||||
#undef whati
|
||||
break;
|
||||
|
||||
m4_divert(-1)FID_FLUSH(101,200)m4_dnl And finally this flushes all the unused diversions
|
||||
]])')
|
||||
|
||||
m4_define(INST, `m4_dnl This macro is called on beginning of each instruction.
|
||||
INST_FLUSH()m4_dnl First, old data is flushed
|
||||
m4_define([[INST_NAME]], [[$1]])m4_dnl Then we store instruction name,
|
||||
m4_define([[INST_INVAL]], [[$2]])m4_dnl instruction input value count,
|
||||
m4_undefine([[INST_NEVER_CONSTANT]])m4_dnl reset NEVER_CONSTANT trigger,
|
||||
m4_undefine([[INST_RESULT_TYPE]])m4_dnl and reset RESULT_TYPE value.
|
||||
FID_INTERPRET_BODY()m4_dnl By default, every code is interpreter code.
|
||||
')
|
||||
|
||||
# 3) Final preparation
|
||||
#
|
||||
# Now we prepare all the code around the global diversions.
|
||||
# It must be here, not in m4wrap, as we want M4 to mark the code
|
||||
# by #line directives correctly, not to claim that every single line
|
||||
# is at the beginning of the m4wrap directive.
|
||||
#
|
||||
# This part is split by the final file.
|
||||
# H for inst-gen.h
|
||||
# I for inst-interpret.c
|
||||
# C for inst-gen.c
|
||||
#
|
||||
# So we in cycle:
|
||||
# A. open a diversion
|
||||
# B. send there some code
|
||||
# C. close that diversion
|
||||
# D. flush a global diversion
|
||||
# E. open another diversion and goto B.
|
||||
#
|
||||
# Final diversions
|
||||
# 200+ completed text before it is flushed to output
|
||||
|
||||
# This is a list of output diversions
|
||||
m4_define(FID_WR_PUT_LIST)
|
||||
|
||||
# This macro does the steps C to E, see before.
|
||||
m4_define(FID_WR_PUT_ALSO, `m4_define([[FID_WR_PUT_LIST]],FID_WR_PUT_LIST()[[FID_WR_DPUT(]]FID_WR_DIDX[[)FID_WR_DPUT(]]$1[[)]])m4_define([[FID_WR_DIDX]],m4_eval(FID_WR_DIDX+1))m4_divert(FID_WR_DIDX)')
|
||||
|
||||
# These macros do the splitting between H/I/C
|
||||
m4_define(FID_WR_DIRECT, `m4_ifelse(TARGET,[[$1]],[[FID_WR_INIT()]],[[FID_WR_STOP()]])')
|
||||
m4_define(FID_WR_INIT, `m4_define([[FID_WR_DIDX]],200)m4_define([[FID_WR_PUT]],[[FID_WR_PUT_ALSO($]][[@)]])m4_divert(200)')
|
||||
m4_define(FID_WR_STOP, `m4_define([[FID_WR_PUT]])m4_divert(-1)')
|
||||
|
||||
# Here is the direct code to be put into the output files
|
||||
# together with the undiversions, being hidden under FID_WR_PUT()
|
||||
|
||||
m4_changequote([[,]])
|
||||
FID_WR_DIRECT(I)
|
||||
FID_WR_PUT(3)
|
||||
FID_WR_DIRECT(C)
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 6
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmisleading-indentation"
|
||||
#endif
|
||||
|
||||
#include "nest/bird.h"
|
||||
#include "filter/filter.h"
|
||||
#include "filter/f-inst.h"
|
||||
|
||||
/* Instruction codes to string */
|
||||
static const char * const f_instruction_name_str[] = {
|
||||
FID_WR_PUT(5)
|
||||
};
|
||||
|
||||
const char *
|
||||
f_instruction_name_(enum f_instruction_code fi)
|
||||
{
|
||||
if (fi < (sizeof(f_instruction_name_str) / sizeof(f_instruction_name_str[0])))
|
||||
return f_instruction_name_str[fi];
|
||||
else
|
||||
bug("Got unknown instruction code: %d", fi);
|
||||
}
|
||||
|
||||
static inline struct f_inst *
|
||||
fi_new(enum f_instruction_code fi_code)
|
||||
{
|
||||
struct f_inst *what = cfg_allocz(sizeof(struct f_inst));
|
||||
what->lineno = ifs->lino;
|
||||
what->size = 1;
|
||||
what->fi_code = fi_code;
|
||||
return what;
|
||||
}
|
||||
|
||||
static inline struct f_inst *
|
||||
fi_constant(struct f_inst *what, struct f_val val)
|
||||
{
|
||||
what->fi_code = FI_CONSTANT;
|
||||
what->i_FI_CONSTANT.val = val;
|
||||
return what;
|
||||
}
|
||||
|
||||
static int
|
||||
f_const_promotion(struct f_inst *arg, enum f_type want)
|
||||
{
|
||||
if (arg->fi_code != FI_CONSTANT)
|
||||
return 0;
|
||||
|
||||
struct f_val *c = &arg->i_FI_CONSTANT.val;
|
||||
|
||||
if ((c->type == T_IP) && ipa_is_ip4(c->val.ip) && (want == T_QUAD)) {
|
||||
*c = (struct f_val) {
|
||||
.type = T_QUAD,
|
||||
.val.i = ipa_to_u32(c->val.ip),
|
||||
};
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define v1 whati->f1->i_FI_CONSTANT.val
|
||||
#define v2 whati->f2->i_FI_CONSTANT.val
|
||||
#define v3 whati->f3->i_FI_CONSTANT.val
|
||||
#define vv(i) items[i]->i_FI_CONSTANT.val
|
||||
#define runtime(fmt, ...) cf_error("filter preevaluation, line %d: " fmt, ifs->lino, ##__VA_ARGS__)
|
||||
#define fpool cfg_mem
|
||||
#define falloc(size) cfg_alloc(size)
|
||||
/* Instruction constructors */
|
||||
FID_WR_PUT(3)
|
||||
#undef v1
|
||||
#undef v2
|
||||
#undef v3
|
||||
#undef vv
|
||||
|
||||
/* Line dumpers */
|
||||
#define INDENT (((const char *) f_dump_line_indent_str) + sizeof(f_dump_line_indent_str) - (indent) - 1)
|
||||
static const char f_dump_line_indent_str[] = " ";
|
||||
|
||||
FID_WR_PUT(6)
|
||||
|
||||
void f_dump_line(const struct f_line *dest, uint indent)
|
||||
{
|
||||
if (!dest) {
|
||||
debug("%sNo filter line (NULL)\n", INDENT);
|
||||
return;
|
||||
}
|
||||
debug("%sFilter line %p (len=%u)\n", INDENT, dest, dest->len);
|
||||
for (uint i=0; i<dest->len; i++) {
|
||||
const struct f_line_item *item = &dest->items[i];
|
||||
debug("%sInstruction %s at line %u\n", INDENT, f_instruction_name_(item->fi_code), item->lineno);
|
||||
switch (item->fi_code) {
|
||||
FID_WR_PUT(7)
|
||||
default: bug("Unknown instruction %x in f_dump_line", item->fi_code);
|
||||
}
|
||||
}
|
||||
debug("%sFilter line %p dump done\n", INDENT, dest);
|
||||
}
|
||||
|
||||
/* Linearize */
|
||||
static uint
|
||||
linearize(struct f_line *dest, const struct f_inst *what, uint pos)
|
||||
{
|
||||
for ( ; what; what = what->next) {
|
||||
switch (what->fi_code) {
|
||||
FID_WR_PUT(8)
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
struct f_line *
|
||||
f_linearize_concat(const struct f_inst * const inst[], uint count)
|
||||
{
|
||||
uint len = 0;
|
||||
for (uint i=0; i<count; i++)
|
||||
for (const struct f_inst *what = inst[i]; what; what = what->next)
|
||||
len += what->size;
|
||||
|
||||
struct f_line *out = cfg_allocz(sizeof(struct f_line) + sizeof(struct f_line_item)*len);
|
||||
|
||||
for (uint i=0; i<count; i++)
|
||||
out->len = linearize(out, inst[i], out->len);
|
||||
|
||||
#ifdef LOCAL_DEBUG
|
||||
f_dump_line(out, 0);
|
||||
#endif
|
||||
return out;
|
||||
}
|
||||
|
||||
/* Filter line comparison */
|
||||
int
|
||||
f_same(const struct f_line *fl1, const struct f_line *fl2)
|
||||
{
|
||||
if ((!fl1) && (!fl2))
|
||||
return 1;
|
||||
if ((!fl1) || (!fl2))
|
||||
return 0;
|
||||
if (fl1->len != fl2->len)
|
||||
return 0;
|
||||
for (uint i=0; i<fl1->len; i++) {
|
||||
#define f1_ (&(fl1->items[i]))
|
||||
#define f2_ (&(fl2->items[i]))
|
||||
if (f1_->fi_code != f2_->fi_code)
|
||||
return 0;
|
||||
if (f1_->flags != f2_->flags)
|
||||
return 0;
|
||||
|
||||
switch(f1_->fi_code) {
|
||||
FID_WR_PUT(9)
|
||||
}
|
||||
}
|
||||
#undef f1_
|
||||
#undef f2_
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Part of FI_SWITCH filter iterator */
|
||||
static void
|
||||
f_add_tree_lines(const struct f_tree *t, void *fit_)
|
||||
{
|
||||
struct filter_iterator * fit = fit_;
|
||||
|
||||
if (t->data)
|
||||
BUFFER_PUSH(fit->lines) = t->data;
|
||||
}
|
||||
|
||||
/* Filter line iterator */
|
||||
void
|
||||
f_add_lines(const struct f_line_item *what, struct filter_iterator *fit)
|
||||
{
|
||||
switch(what->fi_code) {
|
||||
FID_WR_PUT(10)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 6
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
FID_WR_DIRECT(H)
|
||||
/* Filter instruction codes */
|
||||
enum f_instruction_code {
|
||||
FID_WR_PUT(4)m4_dnl
|
||||
} PACKED;
|
||||
|
||||
/* Filter instruction structure for config */
|
||||
struct f_inst {
|
||||
struct f_inst *next; /* Next instruction */
|
||||
enum f_instruction_code fi_code; /* Instruction code */
|
||||
enum f_type type; /* Type of returned value, if known */
|
||||
int size; /* How many instructions are underneath */
|
||||
int lineno; /* Line number */
|
||||
union {
|
||||
FID_WR_PUT(1)m4_dnl
|
||||
};
|
||||
};
|
||||
|
||||
/* Filter line item */
|
||||
struct f_line_item {
|
||||
enum f_instruction_code fi_code; /* What to do */
|
||||
enum f_instruction_flags flags; /* Flags, instruction-specific */
|
||||
uint lineno; /* Where */
|
||||
union {
|
||||
FID_WR_PUT(2)m4_dnl
|
||||
};
|
||||
};
|
||||
|
||||
/* Instruction constructors */
|
||||
FID_WR_PUT(3)
|
||||
m4_divert(-1)
|
||||
|
||||
# 4) Shipout
|
||||
#
|
||||
# Everything is prepared in FID_WR_PUT_LIST now. Let's go!
|
||||
|
||||
m4_changequote(`,')
|
||||
|
||||
# Flusher auxiliary macro
|
||||
m4_define(FID_FLUSH, `m4_ifelse($1,$2,,[[m4_undivert($1)FID_FLUSH(m4_eval($1+1),$2)]])')
|
||||
|
||||
# Defining the macro used in FID_WR_PUT_LIST
|
||||
m4_define(FID_WR_DPUT, `m4_undivert($1)')
|
||||
|
||||
# After the code is read and parsed, we:
|
||||
m4_m4wrap(`INST_FLUSH()m4_divert(0)FID_WR_PUT_LIST()m4_divert(-1)FID_FLUSH(1,200)')
|
||||
|
||||
m4_changequote([[,]])
|
||||
# And now M4 is going to parse f-inst.c, fill the diversions
|
||||
# and after the file is done, the content of m4_m4wrap (see before)
|
||||
# is executed.
|
1269
filter/f-inst.c
Normal file
1269
filter/f-inst.c
Normal file
File diff suppressed because it is too large
Load Diff
112
filter/f-inst.h
Normal file
112
filter/f-inst.h
Normal file
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* BIRD Internet Routing Daemon -- Filter instructions
|
||||
*
|
||||
* (c) 1999 Pavel Machek <pavel@ucw.cz>
|
||||
* (c) 2018--2019 Maria Matejka <mq@jmq.cz>
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*
|
||||
* Filter interpreter data structures and internal API.
|
||||
* See filter/f-inst.c for documentation.
|
||||
*/
|
||||
|
||||
#ifndef _BIRD_F_INST_H_
|
||||
#define _BIRD_F_INST_H_
|
||||
|
||||
#include "nest/bird.h"
|
||||
#include "conf/conf.h"
|
||||
#include "filter/filter.h"
|
||||
#include "filter/data.h"
|
||||
#include "lib/buffer.h"
|
||||
#include "lib/flowspec.h"
|
||||
|
||||
/* Flags for instructions */
|
||||
enum f_instruction_flags {
|
||||
FIF_PRINTED = 1, /* FI_PRINT_AND_DIE: message put in buffer */
|
||||
} PACKED;
|
||||
|
||||
/* Include generated filter instruction declarations */
|
||||
#include "filter/inst-gen.h"
|
||||
|
||||
#define f_new_inst(...) MACRO_CONCAT_AFTER(f_new_inst_, MACRO_FIRST(__VA_ARGS__))(__VA_ARGS__)
|
||||
|
||||
/* Convert the instruction back to the enum name */
|
||||
const char *f_instruction_name_(enum f_instruction_code fi);
|
||||
static inline const char *f_instruction_name(enum f_instruction_code fi)
|
||||
{ return f_instruction_name_(fi) + 3; }
|
||||
|
||||
/* Filter structures for execution */
|
||||
/* Line of instructions to be unconditionally executed one after another */
|
||||
struct f_line {
|
||||
uint len; /* Line length */
|
||||
u8 args; /* Function: Args required */
|
||||
u8 vars;
|
||||
struct f_line_item items[0]; /* The items themselves */
|
||||
};
|
||||
|
||||
/* Convert the f_inst infix tree to the f_line structures */
|
||||
struct f_line *f_linearize_concat(const struct f_inst * const inst[], uint count);
|
||||
static inline struct f_line *f_linearize(const struct f_inst *root)
|
||||
{ return f_linearize_concat(&root, 1); }
|
||||
|
||||
void f_dump_line(const struct f_line *, uint indent);
|
||||
|
||||
|
||||
/* Recursive iteration over filter instructions */
|
||||
|
||||
struct filter_iterator {
|
||||
BUFFER_(const struct f_line *) lines;
|
||||
};
|
||||
|
||||
void f_add_lines(const struct f_line_item *what, struct filter_iterator *fit);
|
||||
|
||||
#define FILTER_ITERATE_INIT(fit, filter, pool) \
|
||||
({ \
|
||||
BUFFER_INIT((fit)->lines, (pool), 32); \
|
||||
BUFFER_PUSH((fit)->lines) = (filter)->root; \
|
||||
})
|
||||
|
||||
#define FILTER_ITERATE(fit, fi) ({ \
|
||||
const struct f_line *fl_; \
|
||||
while (!BUFFER_EMPTY((fit)->lines)) \
|
||||
{ \
|
||||
BUFFER_POP((fit)->lines); \
|
||||
fl_ = (fit)->lines.data[(fit)->lines.used]; \
|
||||
for (uint i_ = 0; i_ < fl_->len; i_++) \
|
||||
{ \
|
||||
const struct f_line_item *fi = &fl_->items[i_]; \
|
||||
f_add_lines(fi, (fit));
|
||||
|
||||
#define FILTER_ITERATE_END } } })
|
||||
|
||||
#define FILTER_ITERATE_CLEANUP(fit) \
|
||||
({ \
|
||||
mb_free((fit)->lines.data); \
|
||||
memset((fit), 0, sizeof(struct filter_iterator)); \
|
||||
})
|
||||
|
||||
|
||||
struct filter *f_new_where(struct f_inst *);
|
||||
static inline struct f_dynamic_attr f_new_dynamic_attr(u8 type, enum f_type f_type, uint code) /* Type as core knows it, type as filters know it, and code of dynamic attribute */
|
||||
{ return (struct f_dynamic_attr) { .type = type, .f_type = f_type, .ea_code = code }; } /* f_type currently unused; will be handy for static type checking */
|
||||
static inline struct f_dynamic_attr f_new_dynamic_attr_bit(u8 bit, enum f_type f_type, uint code) /* Type as core knows it, type as filters know it, and code of dynamic attribute */
|
||||
{ return (struct f_dynamic_attr) { .type = EAF_TYPE_BITFIELD, .bit = bit, .f_type = f_type, .ea_code = code }; } /* f_type currently unused; will be handy for static type checking */
|
||||
static inline struct f_static_attr f_new_static_attr(int f_type, int code, int readonly)
|
||||
{ return (struct f_static_attr) { .f_type = f_type, .sa_code = code, .readonly = readonly }; }
|
||||
struct f_inst *f_generate_complex(enum f_instruction_code fi_code, struct f_dynamic_attr da, struct f_inst *argument);
|
||||
struct f_inst *f_generate_roa_check(struct rtable_config *table, struct f_inst *prefix, struct f_inst *asn);
|
||||
|
||||
/* Hook for call bt_assert() function in configuration */
|
||||
extern void (*bt_assert_hook)(int result, const struct f_line_item *assert);
|
||||
|
||||
/* Bird Tests */
|
||||
struct f_bt_test_suite {
|
||||
node n; /* Node in config->tests */
|
||||
const struct f_line *fn; /* Root of function */
|
||||
const struct f_line *cmp; /* Compare to this function */
|
||||
const char *fn_name; /* Name of test */
|
||||
const char *dsc; /* Description */
|
||||
int result; /* Desired result */
|
||||
};
|
||||
|
||||
#endif
|
207
filter/f-util.c
207
filter/f-util.c
@ -2,6 +2,7 @@
|
||||
* Filters: utility functions
|
||||
*
|
||||
* Copyright 1998 Pavel Machek <pavel@ucw.cz>
|
||||
* 2017 Jan Maria Matejka <mq@ucw.cz>
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
@ -9,58 +10,174 @@
|
||||
#include "nest/bird.h"
|
||||
#include "conf/conf.h"
|
||||
#include "filter/filter.h"
|
||||
#include "filter/f-inst.h"
|
||||
#include "lib/idm.h"
|
||||
#include "nest/protocol.h"
|
||||
#include "nest/route.h"
|
||||
|
||||
#define P(a,b) ((a<<8) | b)
|
||||
|
||||
struct f_inst *
|
||||
f_new_inst(void)
|
||||
{
|
||||
struct f_inst * ret;
|
||||
ret = cfg_alloc(sizeof(struct f_inst));
|
||||
ret->code = ret->aux = 0;
|
||||
ret->arg1 = ret->arg2 = ret->next = NULL;
|
||||
ret->lineno = ifs->conf_lino;
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct f_inst *
|
||||
f_new_dynamic_attr(int type, int f_type UNUSED, int code)
|
||||
{
|
||||
/* FIXME: Remove the f_type parameter? */
|
||||
struct f_inst *f = f_new_inst();
|
||||
f->aux = type;
|
||||
f->a2.i = code;
|
||||
return f;
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate set_dynamic( operation( get_dynamic(), argument ) )
|
||||
*/
|
||||
struct f_inst *
|
||||
f_generate_complex(int operation, int operation_aux, struct f_inst *dyn, struct f_inst *argument)
|
||||
{
|
||||
struct f_inst *set_dyn = f_new_inst(),
|
||||
*oper = f_new_inst(),
|
||||
*get_dyn = dyn;
|
||||
|
||||
*set_dyn = *get_dyn;
|
||||
get_dyn->code = P('e','a');
|
||||
oper->code = operation;
|
||||
oper->aux = operation_aux;
|
||||
oper->a1.p = get_dyn;
|
||||
oper->a2.p = argument;
|
||||
set_dyn->code = P('e','S');
|
||||
set_dyn->a1.p = oper;
|
||||
return set_dyn;
|
||||
}
|
||||
|
||||
char *
|
||||
filter_name(struct filter *filter)
|
||||
const char *
|
||||
filter_name(const struct filter *filter)
|
||||
{
|
||||
if (!filter)
|
||||
return "ACCEPT";
|
||||
else if (filter == FILTER_REJECT)
|
||||
return "REJECT";
|
||||
else if (!filter->sym)
|
||||
return "(unnamed)";
|
||||
else
|
||||
return filter->name;
|
||||
return filter->sym->name;
|
||||
}
|
||||
|
||||
struct filter *f_new_where(struct f_inst *where)
|
||||
{
|
||||
struct f_inst *cond = f_new_inst(FI_CONDITION, where,
|
||||
f_new_inst(FI_DIE, F_ACCEPT),
|
||||
f_new_inst(FI_DIE, F_REJECT));
|
||||
|
||||
struct filter *f = cfg_allocz(sizeof(struct filter));
|
||||
f->root = f_linearize(cond);
|
||||
return f;
|
||||
}
|
||||
|
||||
#define CA_KEY(n) n->name, n->fda.type
|
||||
#define CA_NEXT(n) n->next
|
||||
#define CA_EQ(na,ta,nb,tb) (!strcmp(na,nb) && (ta == tb))
|
||||
#define CA_FN(n,t) (mem_hash(n, strlen(n)) ^ (t*0xaae99453U))
|
||||
#define CA_ORDER 8 /* Fixed */
|
||||
|
||||
struct ca_storage {
|
||||
struct ca_storage *next;
|
||||
struct f_dynamic_attr fda;
|
||||
u32 uc;
|
||||
char name[0];
|
||||
};
|
||||
|
||||
HASH(struct ca_storage) ca_hash;
|
||||
|
||||
static struct idm ca_idm;
|
||||
static struct ca_storage **ca_storage;
|
||||
static uint ca_storage_max;
|
||||
|
||||
static void
|
||||
ca_free(resource *r)
|
||||
{
|
||||
struct custom_attribute *ca = (void *) r;
|
||||
struct ca_storage *cas = HASH_FIND(ca_hash, CA, ca->name, ca->fda->type);
|
||||
ASSERT(cas);
|
||||
|
||||
ca->name = NULL;
|
||||
ca->fda = NULL;
|
||||
if (!--cas->uc) {
|
||||
uint id = EA_CUSTOM_ID(cas->fda.ea_code);
|
||||
idm_free(&ca_idm, id);
|
||||
HASH_REMOVE(ca_hash, CA, cas);
|
||||
ca_storage[id] = NULL;
|
||||
mb_free(cas);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
ca_dump(resource *r)
|
||||
{
|
||||
struct custom_attribute *ca = (void *) r;
|
||||
debug("name \"%s\" id 0x%04x ea_type 0x%02x f_type 0x%02x\n",
|
||||
ca->name, ca->fda->ea_code, ca->fda->type, ca->fda->f_type);
|
||||
}
|
||||
|
||||
static struct resclass ca_class = {
|
||||
.name = "Custom attribute",
|
||||
.size = sizeof(struct custom_attribute),
|
||||
.free = ca_free,
|
||||
.dump = ca_dump,
|
||||
.lookup = NULL,
|
||||
.memsize = NULL,
|
||||
};
|
||||
|
||||
struct custom_attribute *
|
||||
ca_lookup(pool *p, const char *name, int f_type)
|
||||
{
|
||||
int ea_type;
|
||||
|
||||
switch (f_type) {
|
||||
case T_INT:
|
||||
ea_type = EAF_TYPE_INT;
|
||||
break;
|
||||
case T_IP:
|
||||
ea_type = EAF_TYPE_IP_ADDRESS;
|
||||
break;
|
||||
case T_QUAD:
|
||||
ea_type = EAF_TYPE_ROUTER_ID;
|
||||
break;
|
||||
case T_PATH:
|
||||
ea_type = EAF_TYPE_AS_PATH;
|
||||
break;
|
||||
case T_CLIST:
|
||||
ea_type = EAF_TYPE_INT_SET;
|
||||
break;
|
||||
case T_ECLIST:
|
||||
ea_type = EAF_TYPE_EC_SET;
|
||||
break;
|
||||
case T_LCLIST:
|
||||
ea_type = EAF_TYPE_LC_SET;
|
||||
break;
|
||||
default:
|
||||
cf_error("Custom route attribute of unsupported type");
|
||||
}
|
||||
|
||||
static int inited = 0;
|
||||
if (!inited) {
|
||||
idm_init(&ca_idm, &root_pool, 8);
|
||||
HASH_INIT(ca_hash, &root_pool, CA_ORDER);
|
||||
|
||||
ca_storage_max = 256;
|
||||
ca_storage = mb_allocz(&root_pool, sizeof(struct ca_storage *) * ca_storage_max);
|
||||
|
||||
inited++;
|
||||
}
|
||||
|
||||
struct ca_storage *cas = HASH_FIND(ca_hash, CA, name, ea_type);
|
||||
if (cas) {
|
||||
cas->uc++;
|
||||
} else {
|
||||
|
||||
uint id = idm_alloc(&ca_idm);
|
||||
|
||||
if (id >= EA_CUSTOM_BIT)
|
||||
cf_error("Too many custom attributes.");
|
||||
|
||||
if (id >= ca_storage_max) {
|
||||
ca_storage_max *= 2;
|
||||
ca_storage = mb_realloc(ca_storage, sizeof(struct ca_storage *) * ca_storage_max * 2);
|
||||
}
|
||||
|
||||
cas = mb_allocz(&root_pool, sizeof(struct ca_storage) + strlen(name) + 1);
|
||||
cas->fda = f_new_dynamic_attr(ea_type, f_type, EA_CUSTOM(id));
|
||||
cas->uc = 1;
|
||||
|
||||
strcpy(cas->name, name);
|
||||
ca_storage[id] = cas;
|
||||
|
||||
HASH_INSERT(ca_hash, CA, cas);
|
||||
}
|
||||
|
||||
struct custom_attribute *ca = ralloc(p, &ca_class);
|
||||
ca->fda = &(cas->fda);
|
||||
ca->name = cas->name;
|
||||
return ca;
|
||||
}
|
||||
|
||||
const char *
|
||||
ea_custom_name(uint ea)
|
||||
{
|
||||
uint id = EA_CUSTOM_ID(ea);
|
||||
if (id >= ca_storage_max)
|
||||
return NULL;
|
||||
|
||||
if (!ca_storage[id])
|
||||
return NULL;
|
||||
|
||||
return ca_storage[id]->name;
|
||||
}
|
||||
|
||||
|
1630
filter/filter.c
1630
filter/filter.c
File diff suppressed because it is too large
Load Diff
197
filter/filter.h
197
filter/filter.h
@ -2,6 +2,7 @@
|
||||
* BIRD Internet Routing Daemon -- Filters
|
||||
*
|
||||
* (c) 1999 Pavel Machek <pavel@ucw.cz>
|
||||
* (c) 2018--2019 Maria Matejka <mq@jmq.cz>
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
@ -11,177 +12,71 @@
|
||||
|
||||
#include "lib/resource.h"
|
||||
#include "lib/ip.h"
|
||||
#include "lib/macro.h"
|
||||
#include "nest/route.h"
|
||||
#include "nest/attrs.h"
|
||||
|
||||
struct f_inst { /* Instruction */
|
||||
struct f_inst *next; /* Structure is 16 bytes, anyway */
|
||||
u16 code;
|
||||
u16 aux;
|
||||
union {
|
||||
int i;
|
||||
void *p;
|
||||
} a1;
|
||||
union {
|
||||
int i;
|
||||
void *p;
|
||||
} a2;
|
||||
int lineno;
|
||||
/* Possible return values of filter execution */
|
||||
enum filter_return {
|
||||
F_NOP = 0,
|
||||
F_NONL,
|
||||
F_RETURN,
|
||||
F_ACCEPT, /* Need to preserve ordering: accepts < rejects! */
|
||||
F_REJECT,
|
||||
F_ERROR,
|
||||
};
|
||||
|
||||
#define arg1 a1.p
|
||||
#define arg2 a2.p
|
||||
static inline const char *filter_return_str(const enum filter_return fret) {
|
||||
switch (fret) {
|
||||
#define FRS(x) case x: return #x
|
||||
FRS(F_NOP);
|
||||
FRS(F_NONL);
|
||||
FRS(F_RETURN);
|
||||
FRS(F_ACCEPT);
|
||||
FRS(F_REJECT);
|
||||
FRS(F_ERROR);
|
||||
#undef FRS
|
||||
default: bug("This shall not happen");
|
||||
}
|
||||
}
|
||||
|
||||
struct f_prefix {
|
||||
ip_addr ip;
|
||||
int len;
|
||||
#define LEN_MASK 0xff
|
||||
#define LEN_PLUS 0x1000000
|
||||
#define LEN_MINUS 0x2000000
|
||||
#define LEN_RANGE 0x4000000
|
||||
/* If range then prefix must be in range (len >> 16 & 0xff, len >> 8 & 0xff) */
|
||||
};
|
||||
|
||||
struct f_val {
|
||||
int type;
|
||||
union {
|
||||
int i;
|
||||
u64 ec;
|
||||
/* ip_addr ip; Folded into prefix */
|
||||
struct f_prefix px;
|
||||
char *s;
|
||||
struct f_tree *t;
|
||||
struct f_trie *ti;
|
||||
struct adata *ad;
|
||||
struct f_path_mask *path_mask;
|
||||
} val;
|
||||
};
|
||||
struct f_val;
|
||||
|
||||
/* The filter encapsulating structure to be pointed-to from outside */
|
||||
struct f_line;
|
||||
struct filter {
|
||||
char *name;
|
||||
struct f_inst *root;
|
||||
struct symbol *sym;
|
||||
const struct f_line *root;
|
||||
};
|
||||
|
||||
struct f_inst *f_new_inst(void);
|
||||
struct f_inst *f_new_dynamic_attr(int type, int f_type, int code); /* Type as core knows it, type as filters know it, and code of dynamic attribute */
|
||||
struct f_tree *f_new_tree(void);
|
||||
struct f_inst *f_generate_complex(int operation, int operation_aux, struct f_inst *dyn, struct f_inst *argument);
|
||||
|
||||
struct f_tree *build_tree(struct f_tree *);
|
||||
struct f_tree *find_tree(struct f_tree *t, struct f_val val);
|
||||
int same_tree(struct f_tree *t1, struct f_tree *t2);
|
||||
|
||||
struct f_trie *f_new_trie(linpool *lp);
|
||||
void trie_add_prefix(struct f_trie *t, ip_addr px, int plen, int l, int h);
|
||||
int trie_match_prefix(struct f_trie *t, ip_addr px, int plen);
|
||||
int trie_same(struct f_trie *t1, struct f_trie *t2);
|
||||
void trie_print(struct f_trie *t);
|
||||
|
||||
void fprefix_get_bounds(struct f_prefix *px, int *l, int *h);
|
||||
|
||||
static inline void
|
||||
trie_add_fprefix(struct f_trie *t, struct f_prefix *px)
|
||||
{
|
||||
int l, h;
|
||||
fprefix_get_bounds(px, &l, &h);
|
||||
trie_add_prefix(t, px->ip, px->len & LEN_MASK, l, h);
|
||||
}
|
||||
|
||||
static inline int
|
||||
trie_match_fprefix(struct f_trie *t, struct f_prefix *px)
|
||||
{
|
||||
return trie_match_prefix(t, px->ip, px->len & LEN_MASK);
|
||||
}
|
||||
|
||||
|
||||
struct ea_list;
|
||||
struct rte;
|
||||
|
||||
int f_run(struct filter *filter, struct rte **rte, struct ea_list **tmp_attrs, struct linpool *tmp_pool, int flags);
|
||||
int f_eval_int(struct f_inst *expr);
|
||||
u32 f_eval_asn(struct f_inst *expr);
|
||||
enum filter_return f_run(const struct filter *filter, struct rte **rte, struct linpool *tmp_pool, int flags);
|
||||
enum filter_return f_eval_rte(const struct f_line *expr, struct rte **rte, struct linpool *tmp_pool);
|
||||
uint f_eval_int(const struct f_line *expr);
|
||||
enum filter_return f_eval_buf(const struct f_line *expr, struct linpool *tmp_pool, buffer *buf);
|
||||
|
||||
char *filter_name(struct filter *filter);
|
||||
int filter_same(struct filter *new, struct filter *old);
|
||||
const char *filter_name(const struct filter *filter);
|
||||
int filter_same(const struct filter *new, const struct filter *old);
|
||||
int f_same(const struct f_line *f1, const struct f_line *f2);
|
||||
|
||||
int i_same(struct f_inst *f1, struct f_inst *f2);
|
||||
void filter_commit(struct config *new, struct config *old);
|
||||
|
||||
int val_compare(struct f_val v1, struct f_val v2);
|
||||
int tree_compare(const void *p1, const void *p2);
|
||||
|
||||
#define F_NOP 0
|
||||
#define F_NONL 1
|
||||
#define F_ACCEPT 2 /* Need to preserve ordering: accepts < rejects! */
|
||||
#define F_REJECT 3
|
||||
#define F_ERROR 4
|
||||
#define F_QUITBIRD 5
|
||||
void filters_dump_all(void);
|
||||
|
||||
#define FILTER_ACCEPT NULL
|
||||
#define FILTER_REJECT ((void *) 1)
|
||||
#define FILTER_REJECT ((struct filter *) 1)
|
||||
#define FILTER_UNDEF ((struct filter *) 2) /* Used in BGP */
|
||||
|
||||
/* Type numbers must be in 0..0xff range */
|
||||
#define T_MASK 0xff
|
||||
#define FF_SILENT 2 /* Silent filter execution */
|
||||
|
||||
/* Internal types */
|
||||
/* Do not use type of zero, that way we'll see errors easier. */
|
||||
#define T_VOID 1
|
||||
|
||||
/* User visible types, which fit in int */
|
||||
#define T_INT 0x10
|
||||
#define T_BOOL 0x11
|
||||
#define T_PAIR 0x12 /* Notice that pair is stored as integer: first << 16 | second */
|
||||
#define T_QUAD 0x13
|
||||
|
||||
/* Put enumerational types in 0x30..0x3f range */
|
||||
#define T_ENUM_LO 0x30
|
||||
#define T_ENUM_HI 0x3f
|
||||
|
||||
#define T_ENUM_RTS 0x30
|
||||
#define T_ENUM_BGP_ORIGIN 0x31
|
||||
#define T_ENUM_SCOPE 0x32
|
||||
#define T_ENUM_RTC 0x33
|
||||
#define T_ENUM_RTD 0x34
|
||||
/* new enums go here */
|
||||
#define T_ENUM_EMPTY 0x3f /* Special hack for atomic_aggr */
|
||||
|
||||
#define T_ENUM T_ENUM_LO ... T_ENUM_HI
|
||||
|
||||
/* Bigger ones */
|
||||
#define T_IP 0x20
|
||||
#define T_PREFIX 0x21
|
||||
#define T_STRING 0x22
|
||||
#define T_PATH_MASK 0x23 /* mask for BGP path */
|
||||
#define T_PATH 0x24 /* BGP path */
|
||||
#define T_CLIST 0x25 /* Community list */
|
||||
#define T_ECLIST 0x26 /* Extended community list */
|
||||
#define T_EC 0x27 /* Extended community value, u64 */
|
||||
|
||||
#define T_RETURN 0x40
|
||||
#define T_SET 0x80
|
||||
#define T_PREFIX_SET 0x81
|
||||
|
||||
struct f_tree {
|
||||
struct f_tree *left, *right;
|
||||
struct f_val from, to;
|
||||
void *data;
|
||||
/* Custom route attributes */
|
||||
struct custom_attribute {
|
||||
resource r;
|
||||
struct f_dynamic_attr *fda;
|
||||
const char *name;
|
||||
};
|
||||
|
||||
struct f_trie_node
|
||||
{
|
||||
ip_addr addr, mask, accept;
|
||||
int plen;
|
||||
struct f_trie_node *c[2];
|
||||
};
|
||||
|
||||
struct f_trie
|
||||
{
|
||||
linpool *lp;
|
||||
int zero;
|
||||
struct f_trie_node root;
|
||||
};
|
||||
|
||||
#define NEW_F_VAL struct f_val * val; val = cfg_alloc(sizeof(struct f_val));
|
||||
|
||||
#define FF_FORCE_TMPATTR 1 /* Force all attributes to be temporary */
|
||||
struct custom_attribute *ca_lookup(pool *p, const char *name, int ea_type);
|
||||
|
||||
#endif
|
||||
|
91
filter/filter_test.c
Normal file
91
filter/filter_test.c
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Filters: Tests
|
||||
*
|
||||
* (c) 2015 CZ.NIC z.s.p.o.
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "test/birdtest.h"
|
||||
#include "test/bt-utils.h"
|
||||
|
||||
#include "filter/filter.h"
|
||||
#include "filter/data.h"
|
||||
#include "filter/f-inst.h"
|
||||
#include "conf/conf.h"
|
||||
|
||||
#define BT_CONFIG_FILE "filter/test.conf"
|
||||
|
||||
|
||||
static int
|
||||
t_reconfig(void)
|
||||
{
|
||||
if (!bt_config_file_parse(BT_CONFIG_FILE))
|
||||
return 0;
|
||||
|
||||
struct symbol *s;
|
||||
WALK_LIST(s, config->symbols)
|
||||
if ((s->class == SYM_FUNCTION) || (s->class == SYM_FILTER))
|
||||
bt_assert_msg((s->flags & SYM_FLAG_SAME), "Symbol %s same check", s->name);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
run_function(const void *arg)
|
||||
{
|
||||
const struct f_bt_test_suite *t = arg;
|
||||
|
||||
if (t->cmp)
|
||||
return t->result == f_same(t->fn, t->cmp);
|
||||
|
||||
linpool *tmp = lp_new_default(&root_pool);
|
||||
enum filter_return fret = f_eval(t->fn, tmp, NULL);
|
||||
rfree(tmp);
|
||||
|
||||
return (fret < F_REJECT);
|
||||
}
|
||||
|
||||
static void
|
||||
bt_assert_filter(int result, const struct f_line_item *assert)
|
||||
{
|
||||
int bt_suit_case_result = 1;
|
||||
if (!result)
|
||||
{
|
||||
bt_result = 0;
|
||||
bt_suite_result = 0;
|
||||
bt_suit_case_result = 0;
|
||||
}
|
||||
|
||||
bt_log_suite_case_result(bt_suit_case_result, "Assertion at line %d (%s)",
|
||||
assert->lineno, assert->i_FI_ASSERT.s);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
bt_init(argc, argv);
|
||||
bt_bird_init();
|
||||
|
||||
bt_assert_hook = bt_assert_filter;
|
||||
|
||||
/* Initial test.conf parsing, must be done here */
|
||||
if (!bt_config_file_parse(BT_CONFIG_FILE))
|
||||
abort();
|
||||
|
||||
bt_test_suite(t_reconfig, "Testing reconfiguration");
|
||||
|
||||
struct f_bt_test_suite *t;
|
||||
WALK_LIST(t, config->tests)
|
||||
bt_test_suite_base(run_function, t->fn_name, t, BT_FORKING, BT_TIMEOUT, "%s", t->dsc);
|
||||
|
||||
bt_bird_cleanup();
|
||||
return bt_exit_value();
|
||||
}
|
23
filter/test-reconf-begin.conf
Normal file
23
filter/test-reconf-begin.conf
Normal file
@ -0,0 +1,23 @@
|
||||
router id 1.1.1.1;
|
||||
protocol device {}
|
||||
|
||||
function a() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function b() {
|
||||
return a();
|
||||
}
|
||||
|
||||
function c() {
|
||||
return b();
|
||||
}
|
||||
|
||||
filter d {
|
||||
if c() then accept; else reject;
|
||||
}
|
||||
|
||||
protocol static {
|
||||
ipv4 { import filter d; };
|
||||
route 10.0.0.0/24 unreachable;
|
||||
}
|
23
filter/test-reconf-end.conf
Normal file
23
filter/test-reconf-end.conf
Normal file
@ -0,0 +1,23 @@
|
||||
router id 1.1.1.1;
|
||||
protocol device {}
|
||||
|
||||
function a() {
|
||||
return false;
|
||||
}
|
||||
|
||||
function b() {
|
||||
return a();
|
||||
}
|
||||
|
||||
function c() {
|
||||
return b();
|
||||
}
|
||||
|
||||
filter d {
|
||||
if c() then accept; else reject;
|
||||
}
|
||||
|
||||
protocol static {
|
||||
ipv4 { import filter d; };
|
||||
route 10.0.0.0/24 unreachable;
|
||||
}
|
1548
filter/test.conf
1548
filter/test.conf
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,3 @@
|
||||
|
||||
print "Entering include";
|
||||
print "Should be 2: ", 1+1;
|
||||
print "Leaving include";
|
||||
|
||||
|
||||
bt_assert(1+1 = 2);
|
||||
i = 42;
|
||||
|
@ -18,6 +18,7 @@ protocol direct {
|
||||
|
||||
protocol kernel {
|
||||
disabled;
|
||||
ipv4; # Must be specified at least one channel
|
||||
# learn; # Learn all routes from the kernel
|
||||
# scan time 10; # Scan kernel tables every 10 seconds
|
||||
}
|
||||
@ -25,51 +26,56 @@ protocol kernel {
|
||||
protocol static {
|
||||
# disabled;
|
||||
|
||||
import filter { print "ahoj";
|
||||
print source;
|
||||
if source = RTS_STATIC then {
|
||||
print "It is from static";
|
||||
}
|
||||
print from;
|
||||
from = 1.2.3.4;
|
||||
print from;
|
||||
print scope;
|
||||
scope = SCOPE_HOST;
|
||||
print scope;
|
||||
if !(scope ~ [ SCOPE_HOST, SCOPE_SITE ]) then {
|
||||
print "Failed in test";
|
||||
quitbird;
|
||||
}
|
||||
|
||||
preference = 15;
|
||||
print preference;
|
||||
preference = 29;
|
||||
print preference;
|
||||
rip_metric = 1;
|
||||
print rip_metric;
|
||||
rip_metric = rip_metric + 5;
|
||||
print rip_metric;
|
||||
bgp_community = - empty - ;
|
||||
print "nazdar";
|
||||
bgp_community = add(bgp_community, (1,2));
|
||||
print "cau";
|
||||
bgp_community = add(bgp_community, (2,3));
|
||||
bgp_community.add((4,5));
|
||||
print "community = ", bgp_community;
|
||||
bgp_community.delete((2,3));
|
||||
print "community = ", bgp_community;
|
||||
bgp_community.empty;
|
||||
print "community = ", bgp_community;
|
||||
print "done";
|
||||
};
|
||||
ipv4 {
|
||||
export all;
|
||||
|
||||
import filter {
|
||||
print "ahoj";
|
||||
print source;
|
||||
if source = RTS_STATIC then {
|
||||
print "It is from static";
|
||||
}
|
||||
print from;
|
||||
from = 1.2.3.4;
|
||||
print from;
|
||||
print scope;
|
||||
scope = SCOPE_HOST;
|
||||
print scope;
|
||||
if !(scope ~ [ SCOPE_HOST, SCOPE_SITE ]) then {
|
||||
print "Failed in test";
|
||||
}
|
||||
|
||||
preference = 15;
|
||||
print preference;
|
||||
preference = 29;
|
||||
print preference;
|
||||
rip_metric = 1;
|
||||
print rip_metric;
|
||||
rip_metric = rip_metric + 5;
|
||||
print rip_metric;
|
||||
|
||||
bgp_community = -empty-;
|
||||
print "hi";
|
||||
bgp_community = add(bgp_community, (1,2));
|
||||
print "hello";
|
||||
bgp_community = add(bgp_community, (2,3));
|
||||
bgp_community.add((4,5));
|
||||
print "community = ", bgp_community;
|
||||
bgp_community.delete((2,3));
|
||||
print "community = ", bgp_community;
|
||||
bgp_community.empty;
|
||||
print "community = ", bgp_community;
|
||||
print "done";
|
||||
|
||||
accept;
|
||||
};
|
||||
};
|
||||
route 0.0.0.0/0 via 195.113.31.113;
|
||||
route 62.168.0.0/25 reject;
|
||||
route 1.2.3.4/32 via 195.113.31.124;
|
||||
# route 10.0.0.0/8 reject;
|
||||
# route 10.1.1.0:255.255.255.0 via 62.168.0.3;
|
||||
# route 10.1.2.0:255.255.255.0 via 62.168.0.3;
|
||||
# route 10.1.3.0:255.255.255.0 via 62.168.0.4;
|
||||
# route 10.2.0.0/24 via "arc0";
|
||||
export all;
|
||||
route 10.0.0.0/8 reject;
|
||||
route 10.1.1.0/24 via 62.168.0.3;
|
||||
route 10.1.2.0/24 via 62.168.0.3;
|
||||
route 10.1.3.0/24 via 62.168.0.4;
|
||||
route 10.2.0.0/24 via "arc0";
|
||||
}
|
||||
|
@ -1,182 +0,0 @@
|
||||
/*
|
||||
* This is an example configuration file.
|
||||
* FIXME: add all examples from docs here.
|
||||
*/
|
||||
|
||||
# Yet another comment
|
||||
|
||||
router id 62.168.0.1;
|
||||
|
||||
define xyzzy = (120+10);
|
||||
|
||||
function callme(int arg1; int arg2)
|
||||
int local1;
|
||||
int local2;
|
||||
int i;
|
||||
{
|
||||
printn "Function callme called arguments ", arg1, " and ", arg2, ":" ;
|
||||
i = arg2;
|
||||
|
||||
case arg1 {
|
||||
2: print "dva"; print "jeste jednou dva";
|
||||
3 .. 5: print "tri az pet";
|
||||
else: print "neco jineho";
|
||||
}
|
||||
}
|
||||
|
||||
function fifteen()
|
||||
{
|
||||
print "fifteen called";
|
||||
return 15;
|
||||
}
|
||||
|
||||
function paths()
|
||||
bgpmask pm1;
|
||||
bgpmask pm2;
|
||||
bgppath p2;
|
||||
clist l;
|
||||
{
|
||||
pm1 = / 4 3 2 1 /;
|
||||
pm2 = [= 4 3 2 1 =];
|
||||
print "Testing path masks: ", pm1, " ", pm2;
|
||||
p2 = prepend( + empty +, 1 );
|
||||
p2 = prepend( p2, 2 );
|
||||
p2 = prepend( p2, 3 );
|
||||
p2 = prepend( p2, 4 );
|
||||
print "Testing paths: ", p2;
|
||||
print "Should be true: ", p2 ~ pm1, " ", p2 ~ pm2;
|
||||
print "4 = ", p2.len;
|
||||
p2 = prepend( p2, 5 );
|
||||
print "Should be false: ", p2 ~ pm1, " ", p2 ~ pm2;
|
||||
print "Should be true: ", p2 ~ / ? 4 3 2 1 /, " ", p2, " ", / ? 4 3 2 1 /;
|
||||
print "Should be true: ", p2 ~ [= * 4 3 * 1 =], " ", p2, " ", [= * 4 3 * 1 =];
|
||||
print "5 = ", p2.len;
|
||||
|
||||
pm1 = [= 1 2 * 3 4 5 =];
|
||||
p2 = prepend( + empty +, 5 );
|
||||
p2 = prepend( p2, 4 );
|
||||
p2 = prepend( p2, 3 );
|
||||
p2 = prepend( p2, 3 );
|
||||
p2 = prepend( p2, 2 );
|
||||
p2 = prepend( p2, 1 );
|
||||
print "Should be true: ", p2 ~ pm1, " ", p2, " ", pm1;
|
||||
|
||||
l = - empty -;
|
||||
l = add( l, (1,2) );
|
||||
l = add( l, (2,3) );
|
||||
print "Community list (1,2) (2,3) ", l;
|
||||
print "Should be true: ", (2,3) ~ l;
|
||||
l = delete( l, (2,3) );
|
||||
print "Community list (1,2) ", l;
|
||||
print "Should be false: ", (2,3) ~ l;
|
||||
}
|
||||
|
||||
function bla()
|
||||
{
|
||||
print "fifteen called";
|
||||
return 15;
|
||||
}
|
||||
|
||||
define four=4;
|
||||
|
||||
function test_pxset(prefix set pxs)
|
||||
{
|
||||
print " must be true: ", 1000::/8 ~ pxs, ",", 1000::/10 ~ pxs, ",", 1000::/12 ~ pxs, ",",
|
||||
2000::/24 ~ pxs, ",", 2000:4000::/24 ~ pxs, ",", 2000::/26 ~ pxs, ",",
|
||||
2000:8000::/26 ~ pxs, ",", 2000::/28 ~ pxs, ",", 2000:FFF0::/28 ~ pxs;
|
||||
print " must be false: ", 1000::/7 ~ pxs, ",", 1000::/13 ~ pxs, ",", 1000::/16 ~ pxs, ",",
|
||||
2000::/16 ~ pxs, ",", 2000::/23 ~ pxs, ",", 2000::/29 ~ pxs, ",",
|
||||
1100::/10 ~ pxs, ",", 2010::/26 ~ pxs;
|
||||
}
|
||||
|
||||
function __startup()
|
||||
int i;
|
||||
bool b;
|
||||
prefix px;
|
||||
ip p;
|
||||
pair pp;
|
||||
int set is;
|
||||
prefix set pxs;
|
||||
string s;
|
||||
{
|
||||
print "Testing filter language:";
|
||||
i = four;
|
||||
i = 12*100 + 60/2 + i;
|
||||
i = ( i + 0 );
|
||||
print " arithmetics: 1234 = ", i;
|
||||
printn " if statements ";
|
||||
print "what happens here?";
|
||||
printn ".";
|
||||
if (i = 4) then { print "*** FAIL: if 0"; quitbird; } else printn ".";
|
||||
# if !(i = 3) then { print "*** FAIL: if 0"; quitbird; } else printn ".";
|
||||
if 1234 = i then printn "."; else { print "*** FAIL: if 1 else"; }
|
||||
# if 1 <= 1 then printn "."; else { print "*** FAIL: test 3"; }
|
||||
if 1234 < 1234 then { print "*** FAIL: test 4"; quitbird; } else print "ok";
|
||||
is = [ 2, 3, 4, 7..11 ];
|
||||
print " must be true: ", 1180::/16 ~ [ 1100::/8{ 15 , 17 } ];
|
||||
print " data types; must be true: ", 12::34 = 12::34, ",", 1 ~ [1,2,3], ",", 5 ~ [1..20], ",", 10 ~ is, ",", 2 ~ [ 1, 2, 3 ], ",", 5 ~ [ 4 .. 7 ], ",", 12::34 ~ [ 12::33..12::35 ], ",", 1020::34 ~ 1000::/8, ",", 1000::/8 ~ 1000::/8, ",", 1000::/8 ~ [ 1000::/8+ ];
|
||||
print " must be true: ", true && true, ",", true || false;
|
||||
|
||||
# print " must be true: ", defined(1), ",", defined(1.2.3.4), ",", 1 != 2, ",", 1 <= 2;
|
||||
print " data types: must be false: ", 1 ~ [ 2, 3, 4 ], ",", 5 ~ is, ",", 12::34 ~ [ 12::33, 12::35 ], ",", (1,2) > (2,2), ",", (1,1) > (1,1), ",", 1000::/9 ~ [ 1000::/8- ], ",", 1000::/17 ~ [ 1000::/8{ 15 , 16 } ], ",", true && false;
|
||||
|
||||
px = 1020::/18;
|
||||
print "Testing prefixes: 1020::/18 = ", px;
|
||||
p = 1234:5678::;
|
||||
print "Testing mask : 1200:: = ", p.mask(8);
|
||||
|
||||
pp = (1, 2);
|
||||
print "Testing pairs: (1,2) = ", (1,2), " = ", pp;
|
||||
print "Testing enums: ", RTS_DUMMY, " ", RTS_STATIC;
|
||||
|
||||
s = "Hello";
|
||||
print "Testing string: ", s, " true: ", s ~ "Hell*", " false: ", s ~ "ell*";
|
||||
|
||||
b = true;
|
||||
print "Testing bool: ", b, ", ", !b;
|
||||
|
||||
pxs = [ 1102::/16, 1104::/16+];
|
||||
print "Testing prefix sets: ";
|
||||
print pxs;
|
||||
print " must be true: ", 1102::/16 ~ pxs, ",", 1104::/16 ~ pxs, ",", 1104::/18 ~ pxs, ",", 1104::/32 ~ pxs;
|
||||
print " must be false: ", 1101::/16 ~ pxs, ",", 1103::/16 ~ pxs, ",", 1102::/15 ~ pxs, ",", 1102::/17 ~ pxs, ",",
|
||||
1102::/32 ~ pxs, ",", 1104::/15 ~ pxs;
|
||||
|
||||
test_pxset([ 1000::/16{8,12}, 2000::/16{24,28} ]);
|
||||
print "What will this do? ", [ 1, 2, 1, 1, 1, 3, 4, 1, 1, 1, 5 ];
|
||||
|
||||
print "Testing functions...";
|
||||
# callme ( 1, 2 );
|
||||
callme ( 2, 2 );
|
||||
callme ( 2, 2 );
|
||||
callme ( 3, 2 );
|
||||
callme ( 4, 2 );
|
||||
callme ( 7, 2 );
|
||||
|
||||
i = fifteen();
|
||||
print "Testing function calls: 15 = ", i;
|
||||
|
||||
paths();
|
||||
|
||||
print "done";
|
||||
quitbird;
|
||||
# print "*** FAIL: this is unreachable";
|
||||
}
|
||||
|
||||
filter testf
|
||||
int j;
|
||||
{
|
||||
print "Heya, filtering route to ", net.ip, " prefixlen ", net.len, " source ", source;
|
||||
print "This route was from ", from;
|
||||
j = 7;
|
||||
j = 17;
|
||||
if rip_metric > 15 then {
|
||||
reject "RIP Metric is more than infinity";
|
||||
}
|
||||
rip_metric = 14;
|
||||
unset(rip_metric);
|
||||
|
||||
accept "ok I take that";
|
||||
}
|
||||
|
||||
eval __startup();
|
@ -10,6 +10,7 @@
|
||||
#include "nest/bird.h"
|
||||
#include "conf/conf.h"
|
||||
#include "filter/filter.h"
|
||||
#include "filter/data.h"
|
||||
|
||||
/**
|
||||
* find_tree
|
||||
@ -23,15 +24,15 @@
|
||||
* Both set matching and |switch() { }| construction is implemented using this function,
|
||||
* thus both are as fast as they can be.
|
||||
*/
|
||||
struct f_tree *
|
||||
find_tree(struct f_tree *t, struct f_val val)
|
||||
const struct f_tree *
|
||||
find_tree(const struct f_tree *t, const struct f_val *val)
|
||||
{
|
||||
if (!t)
|
||||
return NULL;
|
||||
if ((val_compare(t->from, val) != 1) &&
|
||||
(val_compare(t->to, val) != -1))
|
||||
if ((val_compare(&(t->from), val) != 1) &&
|
||||
(val_compare(&(t->to), val) != -1))
|
||||
return t;
|
||||
if (val_compare(t->from, val) == -1)
|
||||
if (val_compare(&(t->from), val) == -1)
|
||||
return find_tree(t->right, val);
|
||||
else
|
||||
return find_tree(t->left, val);
|
||||
@ -53,12 +54,17 @@ build_tree_rec(struct f_tree **buf, int l, int h)
|
||||
return n;
|
||||
}
|
||||
|
||||
static int
|
||||
tree_compare(const void *p1, const void *p2)
|
||||
{
|
||||
return val_compare(&((* (struct f_tree **) p1)->from), &((* (struct f_tree **) p2)->from));
|
||||
}
|
||||
|
||||
/**
|
||||
* build_tree
|
||||
* @from: degenerated tree (linked by @tree->left) to be transformed into form suitable for find_tree()
|
||||
*
|
||||
* Transforms denerated tree into balanced tree.
|
||||
* Transforms degenerated tree into balanced tree.
|
||||
*/
|
||||
struct f_tree *
|
||||
build_tree(struct f_tree *from)
|
||||
@ -77,7 +83,7 @@ build_tree(struct f_tree *from)
|
||||
if (len <= 1024)
|
||||
buf = alloca(len * sizeof(struct f_tree *));
|
||||
else
|
||||
buf = malloc(len * sizeof(struct f_tree *));
|
||||
buf = xmalloc(len * sizeof(struct f_tree *));
|
||||
|
||||
/* Convert a degenerated tree into an sorted array */
|
||||
i = 0;
|
||||
@ -89,7 +95,7 @@ build_tree(struct f_tree *from)
|
||||
root = build_tree_rec(buf, 0, len);
|
||||
|
||||
if (len > 1024)
|
||||
free(buf);
|
||||
xfree(buf);
|
||||
|
||||
return root;
|
||||
}
|
||||
@ -97,12 +103,7 @@ build_tree(struct f_tree *from)
|
||||
struct f_tree *
|
||||
f_new_tree(void)
|
||||
{
|
||||
struct f_tree * ret;
|
||||
ret = cfg_alloc(sizeof(struct f_tree));
|
||||
ret->left = ret->right = NULL;
|
||||
ret->from.type = ret->to.type = T_VOID;
|
||||
ret->from.val.i = ret->to.val.i = 0;
|
||||
ret->data = NULL;
|
||||
struct f_tree *ret = cfg_allocz(sizeof(struct f_tree));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -114,21 +115,69 @@ f_new_tree(void)
|
||||
* Compares two trees and returns 1 if they are same
|
||||
*/
|
||||
int
|
||||
same_tree(struct f_tree *t1, struct f_tree *t2)
|
||||
same_tree(const struct f_tree *t1, const struct f_tree *t2)
|
||||
{
|
||||
if ((!!t1) != (!!t2))
|
||||
return 0;
|
||||
if (!t1)
|
||||
return 1;
|
||||
if (val_compare(t1->from, t2->from))
|
||||
if (val_compare(&(t1->from), &(t2->from)))
|
||||
return 0;
|
||||
if (val_compare(t1->to, t2->to))
|
||||
if (val_compare(&(t1->to), &(t2->to)))
|
||||
return 0;
|
||||
if (!same_tree(t1->left, t2->left))
|
||||
return 0;
|
||||
if (!same_tree(t1->right, t2->right))
|
||||
return 0;
|
||||
if (!i_same(t1->data, t2->data))
|
||||
if (!f_same(t1->data, t2->data))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
tree_node_format(const struct f_tree *t, buffer *buf)
|
||||
{
|
||||
if (t == NULL)
|
||||
return;
|
||||
|
||||
tree_node_format(t->left, buf);
|
||||
|
||||
val_format(&(t->from), buf);
|
||||
if (val_compare(&(t->from), &(t->to)) != 0)
|
||||
{
|
||||
buffer_puts(buf, "..");
|
||||
val_format(&(t->to), buf);
|
||||
}
|
||||
buffer_puts(buf, ", ");
|
||||
|
||||
tree_node_format(t->right, buf);
|
||||
}
|
||||
|
||||
void
|
||||
tree_format(const struct f_tree *t, buffer *buf)
|
||||
{
|
||||
buffer_puts(buf, "[");
|
||||
|
||||
tree_node_format(t, buf);
|
||||
|
||||
if (buf->pos == buf->end)
|
||||
return;
|
||||
|
||||
/* Undo last separator */
|
||||
if (buf->pos[-1] != '[')
|
||||
buf->pos -= 2;
|
||||
|
||||
buffer_puts(buf, "]");
|
||||
}
|
||||
|
||||
void
|
||||
tree_walk(const struct f_tree *t, void (*hook)(const struct f_tree *, void *), void *data)
|
||||
{
|
||||
if (!t)
|
||||
return;
|
||||
|
||||
tree_walk(t->left, hook, data);
|
||||
hook(t, data);
|
||||
tree_walk(t->right, hook, data);
|
||||
}
|
||||
|
305
filter/tree_test.c
Normal file
305
filter/tree_test.c
Normal file
@ -0,0 +1,305 @@
|
||||
/*
|
||||
* Filters: Utility Functions Tests
|
||||
*
|
||||
* (c) 2015 CZ.NIC z.s.p.o.
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#include "test/birdtest.h"
|
||||
#include "test/bt-utils.h"
|
||||
|
||||
#include "filter/filter.h"
|
||||
#include "filter/data.h"
|
||||
#include "conf/conf.h"
|
||||
|
||||
#define MAX_TREE_HEIGHT 13
|
||||
|
||||
static void
|
||||
start_conf_env(void)
|
||||
{
|
||||
bt_bird_init();
|
||||
|
||||
pool *p = rp_new(&root_pool, "helper_pool");
|
||||
linpool *l = lp_new_default(p);
|
||||
cfg_mem = l;
|
||||
}
|
||||
|
||||
static struct f_tree *
|
||||
new_tree(uint id)
|
||||
{
|
||||
struct f_tree *tree = f_new_tree();
|
||||
tree->from.type = tree->to.type = T_INT;
|
||||
tree->from.val.i = tree->to.val.i = id;
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
/*
|
||||
* Show subtree in infix notation
|
||||
*/
|
||||
static void
|
||||
show_subtree(struct f_tree *node)
|
||||
{
|
||||
if (!node)
|
||||
return;
|
||||
|
||||
show_subtree(node->left);
|
||||
|
||||
if (node->from.val.i == node->to.val.i)
|
||||
bt_debug("%u ", node->from.val.i);
|
||||
else
|
||||
bt_debug("%u..%u ", node->from.val.i, node->to.val.i);
|
||||
|
||||
show_subtree(node->right);
|
||||
}
|
||||
|
||||
static void
|
||||
show_tree2(struct f_tree *root_node, const char *tree_name)
|
||||
{
|
||||
bt_debug("%s: \n", tree_name);
|
||||
bt_debug("[ ");
|
||||
show_subtree(root_node);
|
||||
bt_debug("]\n\n");
|
||||
}
|
||||
|
||||
#define show_tree(tree) show_tree2(tree, #tree);
|
||||
|
||||
static uint
|
||||
get_nodes_count_full_bin_tree(uint height)
|
||||
{
|
||||
return (bt_naive_pow(2, height+1) - 1);
|
||||
}
|
||||
|
||||
static struct f_tree *
|
||||
get_balanced_full_subtree(uint height, uint idx)
|
||||
{
|
||||
struct f_tree *node = new_tree(idx);
|
||||
if (height > 0)
|
||||
{
|
||||
uint nodes_in_subtree = get_nodes_count_full_bin_tree(--height);
|
||||
node->left = get_balanced_full_subtree(height, idx - nodes_in_subtree/2 - 1);
|
||||
node->right = get_balanced_full_subtree(height, idx + nodes_in_subtree/2 + 1);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
static struct f_tree *
|
||||
get_balanced_full_tree(uint height)
|
||||
{
|
||||
return get_balanced_full_subtree(height, get_nodes_count_full_bin_tree(height)/2);
|
||||
}
|
||||
|
||||
static struct f_tree *
|
||||
get_degenerated_left_tree(uint nodes_count)
|
||||
{
|
||||
struct f_tree *old = NULL;
|
||||
struct f_tree *new = NULL;
|
||||
uint i;
|
||||
|
||||
for (i = 0; i < nodes_count; i++)
|
||||
{
|
||||
old = new;
|
||||
new = new_tree(nodes_count-1-i);
|
||||
new->left = old;
|
||||
}
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
static struct f_tree *
|
||||
get_random_degenerated_left_tree(uint nodes_count)
|
||||
{
|
||||
struct f_tree *tree = get_degenerated_left_tree(nodes_count);
|
||||
|
||||
size_t avaible_indexes_size = nodes_count * sizeof(byte);
|
||||
byte *avaible_indexes = malloc(avaible_indexes_size);
|
||||
memset(avaible_indexes, 0, avaible_indexes_size);
|
||||
|
||||
struct f_tree *n;
|
||||
for (n = tree; n; n = n->left)
|
||||
{
|
||||
uint selected_idx;
|
||||
do
|
||||
{
|
||||
selected_idx = bt_random() % nodes_count;
|
||||
} while(avaible_indexes[selected_idx] != 0);
|
||||
|
||||
avaible_indexes[selected_idx] = 1;
|
||||
n->from.type = n->to.type = T_INT;
|
||||
n->from.val.i = n->to.val.i = selected_idx;
|
||||
}
|
||||
|
||||
free(avaible_indexes);
|
||||
return tree;
|
||||
}
|
||||
|
||||
static struct f_tree *
|
||||
get_balanced_tree_with_ranged_values(uint nodes_count)
|
||||
{
|
||||
struct f_tree *tree = get_degenerated_left_tree(nodes_count);
|
||||
|
||||
uint idx = 0;
|
||||
struct f_tree *n;
|
||||
for (n = tree; n; n = n->left)
|
||||
{
|
||||
n->from.type = n->to.type = T_INT;
|
||||
n->from.val.i = idx;
|
||||
idx += (uint)bt_random() / nodes_count; /* (... / nodes_count) preventing overflow an uint idx */
|
||||
n->to.val.i = idx++;
|
||||
}
|
||||
|
||||
return build_tree(tree);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
t_balancing(void)
|
||||
{
|
||||
start_conf_env();
|
||||
|
||||
uint height;
|
||||
for (height = 1; height < MAX_TREE_HEIGHT; height++)
|
||||
{
|
||||
uint nodes_count = get_nodes_count_full_bin_tree(height);
|
||||
|
||||
struct f_tree *simple_degenerated_tree = get_degenerated_left_tree(nodes_count);
|
||||
show_tree(simple_degenerated_tree);
|
||||
|
||||
struct f_tree *expected_balanced_tree = get_balanced_full_tree(height);
|
||||
show_tree(expected_balanced_tree);
|
||||
|
||||
struct f_tree *balanced_tree_from_simple = build_tree(simple_degenerated_tree);
|
||||
show_tree(balanced_tree_from_simple);
|
||||
|
||||
bt_assert(same_tree(balanced_tree_from_simple, expected_balanced_tree));
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
t_balancing_random(void)
|
||||
{
|
||||
start_conf_env();
|
||||
|
||||
uint height;
|
||||
for (height = 1; height < MAX_TREE_HEIGHT; height++)
|
||||
{
|
||||
uint nodes_count = get_nodes_count_full_bin_tree(height);
|
||||
|
||||
struct f_tree *expected_balanced_tree = get_balanced_full_tree(height);
|
||||
|
||||
uint i;
|
||||
for(i = 0; i < 10; i++)
|
||||
{
|
||||
struct f_tree *random_degenerated_tree = get_random_degenerated_left_tree(nodes_count);
|
||||
show_tree(random_degenerated_tree);
|
||||
|
||||
struct f_tree *balanced_tree_from_random = build_tree(random_degenerated_tree);
|
||||
|
||||
show_tree(expected_balanced_tree);
|
||||
show_tree(balanced_tree_from_random);
|
||||
|
||||
bt_assert(same_tree(balanced_tree_from_random, expected_balanced_tree));
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_find(void)
|
||||
{
|
||||
start_conf_env();
|
||||
|
||||
uint height;
|
||||
for (height = 1; height < MAX_TREE_HEIGHT; height++)
|
||||
{
|
||||
uint nodes_count = get_nodes_count_full_bin_tree(height);
|
||||
|
||||
struct f_tree *tree = get_balanced_full_tree(height);
|
||||
show_tree(tree);
|
||||
|
||||
struct f_val looking_up_value = {
|
||||
.type = T_INT
|
||||
};
|
||||
for(looking_up_value.val.i = 0; looking_up_value.val.i < nodes_count; looking_up_value.val.i++)
|
||||
{
|
||||
const struct f_tree *found_tree = find_tree(tree, &looking_up_value);
|
||||
bt_assert((val_compare(&looking_up_value, &(found_tree->from)) == 0) && (val_compare(&looking_up_value, &(found_tree->to)) == 0));
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static uint
|
||||
get_max_value_in_unbalanced_tree(struct f_tree *node, uint max)
|
||||
{
|
||||
if (!node)
|
||||
return max;
|
||||
|
||||
if (node->to.val.i > max)
|
||||
max = node->to.val.i;
|
||||
|
||||
uint max_left = get_max_value_in_unbalanced_tree(node->left, max);
|
||||
if (max_left > max)
|
||||
max = max_left;
|
||||
|
||||
uint max_right = get_max_value_in_unbalanced_tree(node->right, max);
|
||||
if (max_right > max)
|
||||
max = max_right;
|
||||
|
||||
return max;
|
||||
}
|
||||
|
||||
static int
|
||||
t_find_ranges(void)
|
||||
{
|
||||
start_conf_env();
|
||||
|
||||
uint height;
|
||||
for (height = 1; height < MAX_TREE_HEIGHT; height++)
|
||||
{
|
||||
uint nodes_count = get_nodes_count_full_bin_tree(height);
|
||||
|
||||
struct f_tree *tree = get_balanced_tree_with_ranged_values(nodes_count);
|
||||
uint max_value = get_max_value_in_unbalanced_tree(tree, 0);
|
||||
|
||||
show_tree(tree);
|
||||
|
||||
bt_debug("max_value: %u \n", max_value);
|
||||
|
||||
struct f_val needle = {
|
||||
.type = T_INT
|
||||
};
|
||||
uint *i = &needle.val.i;
|
||||
|
||||
for(*i = 0; *i <= max_value; *i += (uint)bt_random()/nodes_count)
|
||||
{
|
||||
const struct f_tree *found_tree = find_tree(tree, &needle);
|
||||
bt_debug("searching: %u \n", *i);
|
||||
bt_assert(
|
||||
(val_compare(&needle, &(found_tree->from)) == 0) || (val_compare(&needle, &(found_tree->to)) == 0) ||
|
||||
((val_compare(&needle, &(found_tree->from)) == 1) && (val_compare(&needle, &(found_tree->to)) == -1))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
bt_init(argc, argv);
|
||||
|
||||
bt_test_suite(t_balancing, "Balancing strong unbalanced trees");
|
||||
bt_test_suite(t_balancing_random, "Balancing random unbalanced trees");
|
||||
bt_test_suite(t_find, "Finding values in trees");
|
||||
bt_test_suite(t_find_ranges, "Finding values in trees with random ranged values");
|
||||
|
||||
return bt_exit_value();
|
||||
}
|
379
filter/trie.c
379
filter/trie.c
@ -21,7 +21,7 @@
|
||||
*
|
||||
* We use a bitmask (&accept) to represent accepted prefix lengths
|
||||
* at a node. As there are 33 prefix lengths (0..32 for IPv4), but
|
||||
* there is just one prefix of zero length in the whole trie so we
|
||||
* there is just one prefix of zero length in the whole trie so we
|
||||
* have &zero flag in &f_trie (indicating whether the trie accepts
|
||||
* prefix 0.0.0.0/0) as a special case, and &accept bitmask
|
||||
* represents accepted prefix lengths from 1 to 32.
|
||||
@ -73,25 +73,45 @@
|
||||
#include "lib/string.h"
|
||||
#include "conf/conf.h"
|
||||
#include "filter/filter.h"
|
||||
#include "filter/data.h"
|
||||
|
||||
|
||||
/*
|
||||
* In the trie_add_prefix(), we use ip_addr (assuming that it is the same as
|
||||
* ip6_addr) to handle both IPv4 and IPv6 prefixes. In contrast to rest of the
|
||||
* BIRD, IPv4 addresses are just zero-padded from right. That is why we have
|
||||
* ipt_from_ip4() and ipt_to_ip4() macros below.
|
||||
*/
|
||||
|
||||
#define ipa_mkmask(x) ip6_mkmask(x)
|
||||
#define ipa_masklen(x) ip6_masklen(&x)
|
||||
#define ipa_pxlen(x,y) ip6_pxlen(x,y)
|
||||
#define ipa_getbit(x,n) ip6_getbit(x,n)
|
||||
|
||||
#define ipt_from_ip4(x) _MI6(_I(x), 0, 0, 0)
|
||||
#define ipt_to_ip4(x) _MI4(_I0(x))
|
||||
|
||||
|
||||
/**
|
||||
* f_new_trie
|
||||
*
|
||||
* Allocates and returns a new empty trie.
|
||||
* f_new_trie - allocates and returns a new empty trie
|
||||
* @lp: linear pool to allocate items from
|
||||
* @data_size: user data attached to node
|
||||
*/
|
||||
struct f_trie *
|
||||
f_new_trie(linpool *lp)
|
||||
f_new_trie(linpool *lp, uint data_size)
|
||||
{
|
||||
struct f_trie * ret;
|
||||
ret = lp_allocz(lp, sizeof(struct f_trie));
|
||||
ret = lp_allocz(lp, sizeof(struct f_trie) + data_size);
|
||||
ret->lp = lp;
|
||||
ret->ipv4 = -1;
|
||||
ret->data_size = data_size;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline struct f_trie_node *
|
||||
new_node(struct f_trie *t, int plen, ip_addr paddr, ip_addr pmask, ip_addr amask)
|
||||
static inline struct f_trie_node4 *
|
||||
new_node4(struct f_trie *t, int plen, ip4_addr paddr, ip4_addr pmask, ip4_addr amask)
|
||||
{
|
||||
struct f_trie_node *n = lp_allocz(t->lp, sizeof(struct f_trie_node));
|
||||
struct f_trie_node4 *n = lp_allocz(t->lp, sizeof(struct f_trie_node4) + t->data_size);
|
||||
n->plen = plen;
|
||||
n->addr = paddr;
|
||||
n->mask = pmask;
|
||||
@ -99,28 +119,90 @@ new_node(struct f_trie *t, int plen, ip_addr paddr, ip_addr pmask, ip_addr amask
|
||||
return n;
|
||||
}
|
||||
|
||||
static inline void
|
||||
attach_node(struct f_trie_node *parent, struct f_trie_node *child)
|
||||
static inline struct f_trie_node6 *
|
||||
new_node6(struct f_trie *t, int plen, ip6_addr paddr, ip6_addr pmask, ip6_addr amask)
|
||||
{
|
||||
parent->c[ipa_getbit(child->addr, parent->plen) ? 1 : 0] = child;
|
||||
struct f_trie_node6 *n = lp_allocz(t->lp, sizeof(struct f_trie_node6) + t->data_size);
|
||||
n->plen = plen;
|
||||
n->addr = paddr;
|
||||
n->mask = pmask;
|
||||
n->accept = amask;
|
||||
return n;
|
||||
}
|
||||
|
||||
static inline struct f_trie_node *
|
||||
new_node(struct f_trie *t, int plen, ip_addr paddr, ip_addr pmask, ip_addr amask)
|
||||
{
|
||||
if (t->ipv4)
|
||||
return (struct f_trie_node *) new_node4(t, plen, ipt_to_ip4(paddr), ipt_to_ip4(pmask), ipt_to_ip4(amask));
|
||||
else
|
||||
return (struct f_trie_node *) new_node6(t, plen, ipa_to_ip6(paddr), ipa_to_ip6(pmask), ipa_to_ip6(amask));
|
||||
}
|
||||
|
||||
static inline void
|
||||
attach_node4(struct f_trie_node4 *parent, struct f_trie_node4 *child)
|
||||
{
|
||||
parent->c[ip4_getbit(child->addr, parent->plen) ? 1 : 0] = child;
|
||||
}
|
||||
|
||||
static inline void
|
||||
attach_node6(struct f_trie_node6 *parent, struct f_trie_node6 *child)
|
||||
{
|
||||
parent->c[ip6_getbit(child->addr, parent->plen) ? 1 : 0] = child;
|
||||
}
|
||||
|
||||
static inline void
|
||||
attach_node(struct f_trie_node *parent, struct f_trie_node *child, int v4)
|
||||
{
|
||||
if (v4)
|
||||
attach_node4(&parent->v4, &child->v4);
|
||||
else
|
||||
attach_node6(&parent->v6, &child->v6);
|
||||
}
|
||||
|
||||
#define GET_ADDR(N,F,X) ((X) ? ipt_from_ip4((N)->v4.F) : ipa_from_ip6((N)->v6.F))
|
||||
#define SET_ADDR(N,F,X,V) ({ if (X) (N)->v4.F =ipt_to_ip4(V); else (N)->v6.F =ipa_to_ip6(V); })
|
||||
|
||||
#define GET_CHILD(N,F,X,I) ((X) ? (struct f_trie_node *) (N)->v4.c[I] : (struct f_trie_node *) (N)->v6.c[I])
|
||||
/**
|
||||
* trie_add_prefix
|
||||
* @t: trie to add to
|
||||
* @px: prefix address
|
||||
* @plen: prefix length
|
||||
* @l: prefix lower bound
|
||||
* @net: IP network prefix
|
||||
* @l: prefix lower bound
|
||||
* @h: prefix upper bound
|
||||
*
|
||||
* Adds prefix (prefix pattern) @px/@plen to trie @t. @l and @h are lower
|
||||
* Adds prefix (prefix pattern) @n to trie @t. @l and @h are lower
|
||||
* and upper bounds on accepted prefix lengths, both inclusive.
|
||||
* 0 <= l, h <= 32 (128 for IPv6).
|
||||
*
|
||||
* Returns a pointer to the allocated node. The function can return a pointer to
|
||||
* an existing node if @px and @plen are the same. If px/plen == 0/0 (or ::/0),
|
||||
* a pointer to the root node is returned. Returns NULL when called with
|
||||
* mismatched IPv4/IPv6 net type.
|
||||
*/
|
||||
|
||||
void
|
||||
trie_add_prefix(struct f_trie *t, ip_addr px, int plen, int l, int h)
|
||||
void *
|
||||
trie_add_prefix(struct f_trie *t, const net_addr *net, uint l, uint h)
|
||||
{
|
||||
uint plen = net_pxlen(net);
|
||||
ip_addr px;
|
||||
int v4;
|
||||
|
||||
switch (net->type)
|
||||
{
|
||||
case NET_IP4: px = ipt_from_ip4(net4_prefix(net)); v4 = 1; break;
|
||||
case NET_IP6: px = ipa_from_ip6(net6_prefix(net)); v4 = 0; break;
|
||||
default: bug("invalid type");
|
||||
}
|
||||
|
||||
if (t->ipv4 != v4)
|
||||
{
|
||||
if (t->ipv4 < 0)
|
||||
t->ipv4 = v4;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (l == 0)
|
||||
t->zero = 1;
|
||||
else
|
||||
@ -135,107 +217,169 @@ trie_add_prefix(struct f_trie *t, ip_addr px, int plen, int l, int h)
|
||||
struct f_trie_node *o = NULL;
|
||||
struct f_trie_node *n = &t->root;
|
||||
|
||||
while(n)
|
||||
while (n)
|
||||
{
|
||||
ip_addr cmask = ipa_and(n->mask, pmask);
|
||||
ip_addr naddr = GET_ADDR(n, addr, v4);
|
||||
ip_addr nmask = GET_ADDR(n, mask, v4);
|
||||
ip_addr accept = GET_ADDR(n, accept, v4);
|
||||
ip_addr cmask = ipa_and(nmask, pmask);
|
||||
uint nlen = v4 ? n->v4.plen : n->v6.plen;
|
||||
|
||||
if (ipa_compare(ipa_and(paddr, cmask), ipa_and(n->addr, cmask)))
|
||||
{
|
||||
if (ipa_compare(ipa_and(paddr, cmask), ipa_and(naddr, cmask)))
|
||||
{
|
||||
/* We are out of path - we have to add branching node 'b'
|
||||
between node 'o' and node 'n', and attach new node 'a'
|
||||
as the other child of 'b'. */
|
||||
int blen = ipa_pxlen(paddr, n->addr);
|
||||
int blen = ipa_pxlen(paddr, naddr);
|
||||
ip_addr bmask = ipa_mkmask(blen);
|
||||
ip_addr baddr = ipa_and(px, bmask);
|
||||
|
||||
/* Merge accept masks from children to get accept mask for node 'b' */
|
||||
ip_addr baccm = ipa_and(ipa_or(amask, n->accept), bmask);
|
||||
ip_addr baccm = ipa_and(ipa_or(amask, accept), bmask);
|
||||
|
||||
struct f_trie_node *a = new_node(t, plen, paddr, pmask, amask);
|
||||
struct f_trie_node *b = new_node(t, blen, baddr, bmask, baccm);
|
||||
attach_node(o, b);
|
||||
attach_node(b, n);
|
||||
attach_node(b, a);
|
||||
return;
|
||||
attach_node(o, b, v4);
|
||||
attach_node(b, n, v4);
|
||||
attach_node(b, a, v4);
|
||||
return a;
|
||||
}
|
||||
|
||||
if (plen < n->plen)
|
||||
if (plen < nlen)
|
||||
{
|
||||
/* We add new node 'a' between node 'o' and node 'n' */
|
||||
amask = ipa_or(amask, ipa_and(n->accept, pmask));
|
||||
amask = ipa_or(amask, ipa_and(accept, pmask));
|
||||
struct f_trie_node *a = new_node(t, plen, paddr, pmask, amask);
|
||||
attach_node(o, a);
|
||||
attach_node(a, n);
|
||||
return;
|
||||
attach_node(o, a, v4);
|
||||
attach_node(a, n, v4);
|
||||
return a;
|
||||
}
|
||||
|
||||
if (plen == n->plen)
|
||||
|
||||
if (plen == nlen)
|
||||
{
|
||||
/* We already found added node in trie. Just update accept mask */
|
||||
n->accept = ipa_or(n->accept, amask);
|
||||
return;
|
||||
accept = ipa_or(accept, amask);
|
||||
SET_ADDR(n, accept, v4, accept);
|
||||
return n;
|
||||
}
|
||||
|
||||
/* Update accept mask part M2 and go deeper */
|
||||
n->accept = ipa_or(n->accept, ipa_and(amask, n->mask));
|
||||
accept = ipa_or(accept, ipa_and(amask, nmask));
|
||||
SET_ADDR(n, accept, v4, accept);
|
||||
|
||||
/* n->plen < plen and plen <= 32 (128) */
|
||||
o = n;
|
||||
n = n->c[ipa_getbit(paddr, n->plen) ? 1 : 0];
|
||||
n = GET_CHILD(n, c, v4, ipa_getbit(paddr, nlen) ? 1 : 0);
|
||||
}
|
||||
|
||||
/* We add new tail node 'a' after node 'o' */
|
||||
struct f_trie_node *a = new_node(t, plen, paddr, pmask, amask);
|
||||
attach_node(o, a);
|
||||
attach_node(o, a, v4);
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* trie_match
|
||||
* @t: trie
|
||||
* @px: prefix address
|
||||
* @plen: prefix length
|
||||
*
|
||||
* Tries to find a matching prefix pattern in the trie such that
|
||||
* prefix @px/@plen matches that prefix pattern. Returns 1 if there
|
||||
* is such prefix pattern in the trie.
|
||||
*/
|
||||
int
|
||||
trie_match_prefix(struct f_trie *t, ip_addr px, int plen)
|
||||
static int
|
||||
trie_match_net4(const struct f_trie *t, ip4_addr px, uint plen)
|
||||
{
|
||||
ip_addr pmask = ipa_mkmask(plen);
|
||||
ip_addr paddr = ipa_and(px, pmask);
|
||||
ip4_addr pmask = ip4_mkmask(plen);
|
||||
ip4_addr paddr = ip4_and(px, pmask);
|
||||
|
||||
if (plen == 0)
|
||||
return t->zero;
|
||||
|
||||
int plentest = plen - 1;
|
||||
struct f_trie_node *n = &t->root;
|
||||
const struct f_trie_node4 *n = &t->root.v4;
|
||||
|
||||
while(n)
|
||||
{
|
||||
ip_addr cmask = ipa_and(n->mask, pmask);
|
||||
while (n)
|
||||
{
|
||||
ip4_addr cmask = ip4_and(n->mask, pmask);
|
||||
|
||||
/* We are out of path */
|
||||
if (ipa_compare(ipa_and(paddr, cmask), ipa_and(n->addr, cmask)))
|
||||
return 0;
|
||||
/* We are out of path */
|
||||
if (ip4_compare(ip4_and(paddr, cmask), ip4_and(n->addr, cmask)))
|
||||
return 0;
|
||||
|
||||
/* Check accept mask */
|
||||
if (ipa_getbit(n->accept, plentest))
|
||||
return 1;
|
||||
/* Check accept mask */
|
||||
if (ip4_getbit(n->accept, plentest))
|
||||
return 1;
|
||||
|
||||
/* We finished trie walk and still no match */
|
||||
if (plen <= n->plen)
|
||||
return 0;
|
||||
/* We finished trie walk and still no match */
|
||||
if (plen <= n->plen)
|
||||
return 0;
|
||||
|
||||
/* Choose children */
|
||||
n = n->c[(ipa_getbit(paddr, n->plen)) ? 1 : 0];
|
||||
}
|
||||
/* Choose children */
|
||||
n = n->c[(ip4_getbit(paddr, n->plen)) ? 1 : 0];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
trie_node_same(struct f_trie_node *t1, struct f_trie_node *t2)
|
||||
trie_match_net6(const struct f_trie *t, ip6_addr px, uint plen)
|
||||
{
|
||||
ip6_addr pmask = ip6_mkmask(plen);
|
||||
ip6_addr paddr = ip6_and(px, pmask);
|
||||
|
||||
if (plen == 0)
|
||||
return t->zero;
|
||||
|
||||
int plentest = plen - 1;
|
||||
const struct f_trie_node6 *n = &t->root.v6;
|
||||
|
||||
while (n)
|
||||
{
|
||||
ip6_addr cmask = ip6_and(n->mask, pmask);
|
||||
|
||||
/* We are out of path */
|
||||
if (ip6_compare(ip6_and(paddr, cmask), ip6_and(n->addr, cmask)))
|
||||
return 0;
|
||||
|
||||
/* Check accept mask */
|
||||
if (ip6_getbit(n->accept, plentest))
|
||||
return 1;
|
||||
|
||||
/* We finished trie walk and still no match */
|
||||
if (plen <= n->plen)
|
||||
return 0;
|
||||
|
||||
/* Choose children */
|
||||
n = n->c[(ip6_getbit(paddr, n->plen)) ? 1 : 0];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* trie_match_net
|
||||
* @t: trie
|
||||
* @n: net address
|
||||
*
|
||||
* Tries to find a matching net in the trie such that
|
||||
* prefix @n matches that prefix pattern. Returns 1 if there
|
||||
* is such prefix pattern in the trie.
|
||||
*/
|
||||
int
|
||||
trie_match_net(const struct f_trie *t, const net_addr *n)
|
||||
{
|
||||
switch (n->type)
|
||||
{
|
||||
case NET_IP4:
|
||||
case NET_VPN4:
|
||||
case NET_ROA4:
|
||||
return t->ipv4 ? trie_match_net4(t, net4_prefix(n), net_pxlen(n)) : 0;
|
||||
|
||||
case NET_IP6:
|
||||
case NET_VPN6:
|
||||
case NET_ROA6:
|
||||
return !t->ipv4 ? trie_match_net6(t, net6_prefix(n), net_pxlen(n)) : 0;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
trie_node_same4(const struct f_trie_node4 *t1, const struct f_trie_node4 *t2)
|
||||
{
|
||||
if ((t1 == NULL) && (t2 == NULL))
|
||||
return 1;
|
||||
@ -244,11 +388,28 @@ trie_node_same(struct f_trie_node *t1, struct f_trie_node *t2)
|
||||
return 0;
|
||||
|
||||
if ((t1->plen != t2->plen) ||
|
||||
(! ipa_equal(t1->addr, t2->addr)) ||
|
||||
(! ipa_equal(t1->accept, t2->accept)))
|
||||
(! ip4_equal(t1->addr, t2->addr)) ||
|
||||
(! ip4_equal(t1->accept, t2->accept)))
|
||||
return 0;
|
||||
|
||||
return trie_node_same(t1->c[0], t2->c[0]) && trie_node_same(t1->c[1], t2->c[1]);
|
||||
return trie_node_same4(t1->c[0], t2->c[0]) && trie_node_same4(t1->c[1], t2->c[1]);
|
||||
}
|
||||
|
||||
static int
|
||||
trie_node_same6(const struct f_trie_node6 *t1, const struct f_trie_node6 *t2)
|
||||
{
|
||||
if ((t1 == NULL) && (t2 == NULL))
|
||||
return 1;
|
||||
|
||||
if ((t1 == NULL) || (t2 == NULL))
|
||||
return 0;
|
||||
|
||||
if ((t1->plen != t2->plen) ||
|
||||
(! ip6_equal(t1->addr, t2->addr)) ||
|
||||
(! ip6_equal(t1->accept, t2->accept)))
|
||||
return 0;
|
||||
|
||||
return trie_node_same6(t1->c[0], t2->c[0]) && trie_node_same6(t1->c[1], t2->c[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -259,43 +420,69 @@ trie_node_same(struct f_trie_node *t1, struct f_trie_node *t2)
|
||||
* Compares two tries and returns 1 if they are same
|
||||
*/
|
||||
int
|
||||
trie_same(struct f_trie *t1, struct f_trie *t2)
|
||||
trie_same(const struct f_trie *t1, const struct f_trie *t2)
|
||||
{
|
||||
return (t1->zero == t2->zero) && trie_node_same(&t1->root, &t2->root);
|
||||
if ((t1->zero != t2->zero) || (t1->ipv4 != t2->ipv4))
|
||||
return 0;
|
||||
|
||||
if (t1->ipv4)
|
||||
return trie_node_same4(&t1->root.v4, &t2->root.v4);
|
||||
else
|
||||
return trie_node_same6(&t1->root.v6, &t2->root.v6);
|
||||
}
|
||||
|
||||
static void
|
||||
trie_node_print(struct f_trie_node *t, char **sep)
|
||||
trie_node_format4(const struct f_trie_node4 *t, buffer *buf)
|
||||
{
|
||||
if (t == NULL)
|
||||
return;
|
||||
|
||||
if (ipa_nonzero(t->accept))
|
||||
{
|
||||
logn("%s%I/%d{%I}", *sep, t->addr, t->plen, t->accept);
|
||||
*sep = ", ";
|
||||
}
|
||||
if (ip4_nonzero(t->accept))
|
||||
buffer_print(buf, "%I4/%d{%I4}, ", t->addr, t->plen, t->accept);
|
||||
|
||||
trie_node_print(t->c[0], sep);
|
||||
trie_node_print(t->c[1], sep);
|
||||
trie_node_format4(t->c[0], buf);
|
||||
trie_node_format4(t->c[1], buf);
|
||||
}
|
||||
|
||||
static void
|
||||
trie_node_format6(const struct f_trie_node6 *t, buffer *buf)
|
||||
{
|
||||
if (t == NULL)
|
||||
return;
|
||||
|
||||
if (ip6_nonzero(t->accept))
|
||||
buffer_print(buf, "%I6/%d{%I6}, ", t->addr, t->plen, t->accept);
|
||||
|
||||
trie_node_format6(t->c[0], buf);
|
||||
trie_node_format6(t->c[1], buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* trie_print
|
||||
* @t: trie to be printed
|
||||
* trie_format
|
||||
* @t: trie to be formatted
|
||||
* @buf: destination buffer
|
||||
*
|
||||
* Prints the trie to the log buffer.
|
||||
* Prints the trie to the supplied buffer.
|
||||
*/
|
||||
void
|
||||
trie_print(struct f_trie *t)
|
||||
trie_format(const struct f_trie *t, buffer *buf)
|
||||
{
|
||||
char *sep = "";
|
||||
logn("[");
|
||||
buffer_puts(buf, "[");
|
||||
|
||||
if (t->zero)
|
||||
{
|
||||
logn("0.0.0.0/0");
|
||||
sep = ", ";
|
||||
}
|
||||
trie_node_print(&t->root, &sep);
|
||||
logn("]");
|
||||
buffer_print(buf, "%I/%d, ", t->ipv4 ? IPA_NONE4 : IPA_NONE6, 0);
|
||||
|
||||
if (t->ipv4)
|
||||
trie_node_format4(&t->root.v4, buf);
|
||||
else
|
||||
trie_node_format6(&t->root.v6, buf);
|
||||
|
||||
if (buf->pos == buf->end)
|
||||
return;
|
||||
|
||||
/* Undo last separator */
|
||||
if (buf->pos[-1] != '[')
|
||||
buf->pos -= 2;
|
||||
|
||||
buffer_puts(buf, "]");
|
||||
}
|
||||
|
186
filter/trie_test.c
Normal file
186
filter/trie_test.c
Normal file
@ -0,0 +1,186 @@
|
||||
/*
|
||||
* Filters: Utility Functions Tests
|
||||
*
|
||||
* (c) 2015 CZ.NIC z.s.p.o.
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#include "test/birdtest.h"
|
||||
#include "test/bt-utils.h"
|
||||
|
||||
#include "filter/filter.h"
|
||||
#include "filter/data.h"
|
||||
#include "conf/conf.h"
|
||||
|
||||
#define TESTS_NUM 10
|
||||
#define PREFIXES_NUM 10
|
||||
#define PREFIX_TESTS_NUM 10000
|
||||
|
||||
#define BIG_BUFFER_SIZE 10000
|
||||
|
||||
/* Wrapping structure for storing f_prefixes structures in list */
|
||||
struct f_prefix_node {
|
||||
node n;
|
||||
struct f_prefix prefix;
|
||||
};
|
||||
|
||||
static u32
|
||||
xrandom(u32 max)
|
||||
{
|
||||
return (bt_random() % max);
|
||||
}
|
||||
|
||||
static int
|
||||
is_prefix_included(list *prefixes, struct f_prefix *needle)
|
||||
{
|
||||
struct f_prefix_node *n;
|
||||
WALK_LIST(n, *prefixes)
|
||||
{
|
||||
ip6_addr cmask = ip6_mkmask(MIN(n->prefix.net.pxlen, needle->net.pxlen));
|
||||
|
||||
ip6_addr ip = net6_prefix(&n->prefix.net);
|
||||
ip6_addr needle_ip = net6_prefix(&needle->net);
|
||||
|
||||
if ((ipa_compare(ipa_and(ip, cmask), ipa_and(needle_ip, cmask)) == 0) &&
|
||||
(n->prefix.lo <= needle->net.pxlen) && (needle->net.pxlen <= n->prefix.hi))
|
||||
{
|
||||
bt_debug("FOUND\t" PRIip6 "/%d %d-%d\n", ARGip6(net6_prefix(&n->prefix.net)), n->prefix.net.pxlen, n->prefix.lo, n->prefix.hi);
|
||||
return 1; /* OK */
|
||||
}
|
||||
}
|
||||
return 0; /* FAIL */
|
||||
}
|
||||
|
||||
static struct f_prefix
|
||||
get_random_ip6_prefix(void)
|
||||
{
|
||||
struct f_prefix p;
|
||||
u8 pxlen = xrandom(120)+8;
|
||||
ip6_addr ip6 = ip6_build(bt_random(),bt_random(),bt_random(),bt_random());
|
||||
net_addr_ip6 net6 = NET_ADDR_IP6(ip6, pxlen);
|
||||
|
||||
p.net = *((net_addr*) &net6);
|
||||
|
||||
if (bt_random() % 2)
|
||||
{
|
||||
p.lo = 0;
|
||||
p.hi = p.net.pxlen;
|
||||
}
|
||||
else
|
||||
{
|
||||
p.lo = p.net.pxlen;
|
||||
p.hi = net_max_prefix_length[p.net.type];
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
static void
|
||||
generate_random_ipv6_prefixes(list *prefixes)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < PREFIXES_NUM; i++)
|
||||
{
|
||||
struct f_prefix f = get_random_ip6_prefix();
|
||||
|
||||
struct f_prefix_node *px = calloc(1, sizeof(struct f_prefix_node));
|
||||
px->prefix = f;
|
||||
|
||||
bt_debug("ADD\t" PRIip6 "/%d %d-%d\n", ARGip6(net6_prefix(&px->prefix.net)), px->prefix.net.pxlen, px->prefix.lo, px->prefix.hi);
|
||||
add_tail(prefixes, &px->n);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
t_match_net(void)
|
||||
{
|
||||
bt_bird_init();
|
||||
bt_config_parse(BT_CONFIG_SIMPLE);
|
||||
|
||||
uint round;
|
||||
for (round = 0; round < TESTS_NUM; round++)
|
||||
{
|
||||
list prefixes; /* of structs f_extended_prefix */
|
||||
init_list(&prefixes);
|
||||
struct f_trie *trie = f_new_trie(config->mem, 0);
|
||||
|
||||
generate_random_ipv6_prefixes(&prefixes);
|
||||
struct f_prefix_node *n;
|
||||
WALK_LIST(n, prefixes)
|
||||
{
|
||||
trie_add_prefix(trie, &n->prefix.net, n->prefix.lo, n->prefix.hi);
|
||||
}
|
||||
|
||||
int i;
|
||||
for (i = 0; i < PREFIX_TESTS_NUM; i++)
|
||||
{
|
||||
struct f_prefix f = get_random_ip6_prefix();
|
||||
bt_debug("TEST\t" PRIip6 "/%d\n", ARGip6(net6_prefix(&f.net)), f.net.pxlen);
|
||||
|
||||
int should_be = is_prefix_included(&prefixes, &f);
|
||||
int is_there = trie_match_net(trie, &f.net);
|
||||
bt_assert_msg(should_be == is_there, "Prefix " PRIip6 "/%d %s", ARGip6(net6_prefix(&f.net)), f.net.pxlen, (should_be ? "should be found in trie" : "should not be found in trie"));
|
||||
}
|
||||
|
||||
struct f_prefix_node *nxt;
|
||||
WALK_LIST_DELSAFE(n, nxt, prefixes)
|
||||
{
|
||||
free(n);
|
||||
}
|
||||
}
|
||||
|
||||
bt_bird_cleanup();
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_trie_same(void)
|
||||
{
|
||||
bt_bird_init();
|
||||
bt_config_parse(BT_CONFIG_SIMPLE);
|
||||
|
||||
int round;
|
||||
for (round = 0; round < TESTS_NUM*4; round++)
|
||||
{
|
||||
struct f_trie * trie1 = f_new_trie(config->mem, 0);
|
||||
struct f_trie * trie2 = f_new_trie(config->mem, 0);
|
||||
|
||||
list prefixes; /* a list of f_extended_prefix structures */
|
||||
init_list(&prefixes);
|
||||
int i;
|
||||
for (i = 0; i < 100; i++)
|
||||
generate_random_ipv6_prefixes(&prefixes);
|
||||
|
||||
struct f_prefix_node *n;
|
||||
WALK_LIST(n, prefixes)
|
||||
{
|
||||
trie_add_prefix(trie1, &n->prefix.net, n->prefix.lo, n->prefix.hi);
|
||||
}
|
||||
WALK_LIST_BACKWARDS(n, prefixes)
|
||||
{
|
||||
trie_add_prefix(trie2, &n->prefix.net, n->prefix.lo, n->prefix.hi);
|
||||
}
|
||||
|
||||
bt_assert(trie_same(trie1, trie2));
|
||||
|
||||
struct f_prefix_node *nxt;
|
||||
WALK_LIST_DELSAFE(n, nxt, prefixes)
|
||||
{
|
||||
free(n);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
bt_init(argc, argv);
|
||||
|
||||
bt_test_suite(t_match_net, "Testing random prefix matching");
|
||||
bt_test_suite(t_trie_same, "A trie filled forward should be same with a trie filled backward.");
|
||||
|
||||
return bt_exit_value();
|
||||
}
|
6
lib/Doc
6
lib/Doc
@ -1,7 +1,9 @@
|
||||
H Library functions
|
||||
S ip.c ipv4.c ipv6.c
|
||||
S ip.c
|
||||
S lists.c
|
||||
S checksum.c bitops.c patmatch.c printf.c xmalloc.c
|
||||
S checksum.c bitops.c patmatch.c printf.c xmalloc.c tbf.c
|
||||
S mac.c
|
||||
S flowspec.c
|
||||
D resource.sgml
|
||||
S resource.c
|
||||
S mempool.c
|
||||
|
7
lib/Makefile
Normal file
7
lib/Makefile
Normal file
@ -0,0 +1,7 @@
|
||||
src := bitmap.c bitops.c checksum.c event.c flowspec.c idm.c ip.c lists.c mac.c md5.c mempool.c net.c patmatch.c printf.c resource.c sha1.c sha256.c sha512.c slab.c slists.c strtoul.c tbf.c timer.c xmalloc.c
|
||||
obj := $(src-o-files)
|
||||
$(all-daemon)
|
||||
|
||||
tests_src := bitmap_test.c heap_test.c buffer_test.c event_test.c flowspec_test.c bitops_test.c patmatch_test.c fletcher16_test.c slist_test.c checksum_test.c lists_test.c mac_test.c ip_test.c hash_test.c printf_test.c
|
||||
tests_targets := $(tests_targets) $(tests-target-files)
|
||||
tests_objs := $(tests_objs) $(src-o-files)
|
33
lib/Modules
33
lib/Modules
@ -1,33 +0,0 @@
|
||||
birdlib.h
|
||||
bitops.c
|
||||
bitops.h
|
||||
ip.h
|
||||
ip.c
|
||||
#ifdef IPV6
|
||||
ipv6.c
|
||||
ipv6.h
|
||||
#else
|
||||
ipv4.c
|
||||
ipv4.h
|
||||
#endif
|
||||
lists.c
|
||||
lists.h
|
||||
md5.c
|
||||
md5.h
|
||||
mempool.c
|
||||
resource.c
|
||||
resource.h
|
||||
slab.c
|
||||
socket.h
|
||||
unaligned.h
|
||||
xmalloc.c
|
||||
printf.c
|
||||
string.h
|
||||
patmatch.c
|
||||
slists.c
|
||||
slists.h
|
||||
event.c
|
||||
event.h
|
||||
checksum.c
|
||||
checksum.h
|
||||
alloca.h
|
@ -15,4 +15,6 @@
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#define allocz(len) ({ void *_x = alloca(len); memset(_x, 0, len); _x; })
|
||||
|
||||
#endif
|
||||
|
150
lib/birdlib.h
150
lib/birdlib.h
@ -9,26 +9,59 @@
|
||||
#ifndef _BIRD_BIRDLIB_H_
|
||||
#define _BIRD_BIRDLIB_H_
|
||||
|
||||
#include "timer.h"
|
||||
#include "lib/alloca.h"
|
||||
|
||||
/* Ugly structure offset handling macros */
|
||||
|
||||
struct align_probe { char x; long int y; };
|
||||
|
||||
#define OFFSETOF(s, i) ((size_t) &((s *)0)->i)
|
||||
#define SKIP_BACK(s, i, p) ((s *)((char *)p - OFFSETOF(s, i)))
|
||||
#define BIRD_ALIGN(s, a) (((s)+a-1)&~(a-1))
|
||||
#define CPU_STRUCT_ALIGN (sizeof(struct align_probe))
|
||||
|
||||
/* Utility macros */
|
||||
|
||||
#ifdef PARSER
|
||||
#define _MIN(a,b) (((a)<(b))?(a):(b))
|
||||
#define _MAX(a,b) (((a)>(b))?(a):(b))
|
||||
#else
|
||||
#define MIN(a,b) (((a)<(b))?(a):(b))
|
||||
#define MAX(a,b) (((a)>(b))?(a):(b))
|
||||
#define MIN_(a,b) (((a)<(b))?(a):(b))
|
||||
#define MAX_(a,b) (((a)>(b))?(a):(b))
|
||||
|
||||
#ifndef PARSER
|
||||
#undef MIN
|
||||
#undef MAX
|
||||
#define MIN(a,b) MIN_(a,b)
|
||||
#define MAX(a,b) MAX_(a,b)
|
||||
#endif
|
||||
|
||||
#define U64(c) UINT64_C(c)
|
||||
#define ABS(a) ((a)>=0 ? (a) : -(a))
|
||||
#define DELTA(a,b) (((a)>=(b))?(a)-(b):(b)-(a))
|
||||
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(*(a)))
|
||||
#define BYTES(n) ((((uint) (n)) + 7) / 8)
|
||||
#define CALL(fn, args...) ({ if (fn) fn(args); })
|
||||
#define ADVANCE(w, r, l) ({ r -= (l); w += (l); })
|
||||
|
||||
static inline int uint_cmp(uint i1, uint i2)
|
||||
{ return (int)(i1 > i2) - (int)(i1 < i2); }
|
||||
|
||||
static inline int u64_cmp(u64 i1, u64 i2)
|
||||
{ return (int)(i1 > i2) - (int)(i1 < i2); }
|
||||
|
||||
|
||||
/* Bitfield macros */
|
||||
|
||||
/* b is u32 array (or ptr), l is size of it in bits (multiple of 32), p is 0..(l-1) */
|
||||
#define BIT32_VAL(p) (((u32) 1) << ((p) % 32))
|
||||
#define BIT32_TEST(b,p) ((b)[(p)/32] & BIT32_VAL(p))
|
||||
#define BIT32_SET(b,p) ((b)[(p)/32] |= BIT32_VAL(p))
|
||||
#define BIT32_CLR(b,p) ((b)[(p)/32] &= ~BIT32_VAL(p))
|
||||
#define BIT32_ZERO(b,l) memset((b), 0, (l)/8)
|
||||
|
||||
/* The same, but counting bits from MSB */
|
||||
#define BIT32R_VAL(p) ((((u32) 1) << 31) >> ((p) % 32))
|
||||
#define BIT32R_TEST(b,p) ((b)[(p)/32] & BIT32R_VAL(p))
|
||||
#define BIT32R_SET(b,p) ((b)[(p)/32] |= BIT32R_VAL(p))
|
||||
#define BIT32R_CLR(b,p) ((b)[(p)/32] &= ~BIT32R_VAL(p))
|
||||
#define BIT32R_ZERO(b,l) memset((b), 0, (l)/8)
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void *) 0)
|
||||
@ -38,22 +71,77 @@
|
||||
|
||||
#define NORET __attribute__((noreturn))
|
||||
#define UNUSED __attribute__((unused))
|
||||
#define PACKED __attribute__((packed))
|
||||
#define NONNULL(...) __attribute__((nonnull((__VA_ARGS__))))
|
||||
|
||||
#ifndef HAVE_THREAD_LOCAL
|
||||
#define _Thread_local
|
||||
#endif
|
||||
|
||||
/* Microsecond time */
|
||||
|
||||
typedef s64 btime;
|
||||
//typedef s64 bird_clock_t;
|
||||
|
||||
#define S_ * (btime) 1000000
|
||||
#define MS_ * (btime) 1000
|
||||
#define US_ * (btime) 1
|
||||
#define TO_S /1000000
|
||||
#define TO_MS /1000
|
||||
#define TO_US /1
|
||||
|
||||
#ifndef PARSER
|
||||
#define S S_
|
||||
#define MS MS_
|
||||
#define US US_
|
||||
#define NS /1000
|
||||
#endif
|
||||
|
||||
#define TIME_INFINITY ((s64) 0x7fffffffffffffff)
|
||||
|
||||
|
||||
/* Rate limiting */
|
||||
|
||||
struct tbf {
|
||||
btime timestamp; /* Last update */
|
||||
u64 count; /* Available micro-tokens */
|
||||
u16 burst; /* Max number of tokens */
|
||||
u16 rate; /* Rate of replenishment (tokens / sec) */
|
||||
u32 drop; /* Number of failed request since last successful */
|
||||
};
|
||||
|
||||
/* Default TBF values for rate limiting log messages */
|
||||
#define TBF_DEFAULT_LOG_LIMITS { .rate = 1, .burst = 5 }
|
||||
|
||||
int tbf_limit(struct tbf *f);
|
||||
|
||||
|
||||
/* Logging and dying */
|
||||
|
||||
struct rate_limit {
|
||||
bird_clock_t timestamp;
|
||||
int count;
|
||||
};
|
||||
typedef struct buffer {
|
||||
byte *start;
|
||||
byte *pos;
|
||||
byte *end;
|
||||
} buffer;
|
||||
|
||||
#define STACK_BUFFER_INIT(buf,size) \
|
||||
do { \
|
||||
buf.start = alloca(size); \
|
||||
buf.pos = buf.start; \
|
||||
buf.end = buf.start + size; \
|
||||
} while(0)
|
||||
|
||||
#define LOG_BUFFER_INIT(buf) \
|
||||
STACK_BUFFER_INIT(buf, LOG_BUFFER_SIZE)
|
||||
|
||||
#define LOG_BUFFER_SIZE 1024
|
||||
|
||||
#define log log_msg
|
||||
void log_reset(void);
|
||||
void log_commit(int class);
|
||||
void log_msg(char *msg, ...);
|
||||
void log_rl(struct rate_limit *rl, char *msg, ...);
|
||||
void logn(char *msg, ...);
|
||||
void die(char *msg, ...) NORET;
|
||||
void bug(char *msg, ...) NORET;
|
||||
void log_commit(int class, buffer *buf);
|
||||
void log_msg(const char *msg, ...);
|
||||
void log_rl(struct tbf *rl, const char *msg, ...);
|
||||
void die(const char *msg, ...) NORET;
|
||||
void bug(const char *msg, ...) NORET;
|
||||
|
||||
#define L_DEBUG "\001" /* Debugging messages */
|
||||
#define L_TRACE "\002" /* Protocol tracing */
|
||||
@ -65,7 +153,7 @@ void bug(char *msg, ...) NORET;
|
||||
#define L_FATAL "\010" /* Fatal errors */
|
||||
#define L_BUG "\011" /* BIRD bugs */
|
||||
|
||||
void debug(char *msg, ...); /* Printf to debug output */
|
||||
void debug(const char *msg, ...); /* Printf to debug output */
|
||||
|
||||
/* Debugging */
|
||||
|
||||
@ -75,10 +163,30 @@ void debug(char *msg, ...); /* Printf to debug output */
|
||||
#define DBG(x, y...) do { } while(0)
|
||||
#endif
|
||||
|
||||
#define ASSERT_DIE(x) do { if (!(x)) bug("Assertion '%s' failed at %s:%d", #x, __FILE__, __LINE__); } while(0)
|
||||
|
||||
#define EXPENSIVE_CHECK(x) /* intentionally left blank */
|
||||
|
||||
#ifdef DEBUGGING
|
||||
#define ASSERT(x) do { if (!(x)) bug("Assertion `%s' failed at %s:%d", #x, __FILE__, __LINE__); } while(0)
|
||||
#define ASSERT(x) ASSERT_DIE(x)
|
||||
#define ASSUME(x) ASSERT_DIE(x)
|
||||
#ifdef ENABLE_EXPENSIVE_CHECKS
|
||||
#undef EXPENSIVE_CHECK
|
||||
#define EXPENSIVE_CHECK(x) ASSERT_DIE(x)
|
||||
#endif
|
||||
#else
|
||||
#define ASSERT(x) do { } while(0)
|
||||
#define ASSERT(x) do { if (!(x)) log(L_BUG "Assertion '%s' failed at %s:%d", #x, __FILE__, __LINE__); } while(0)
|
||||
#define ASSUME(x) /* intentionally left blank */
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef DEBUGGING
|
||||
asm(
|
||||
".pushsection \".debug_gdb_scripts\", \"MS\",@progbits,1\n"
|
||||
".byte 1\n" /* Python */
|
||||
".asciz \"bird-gdb.py\"\n"
|
||||
".popsection\n"
|
||||
);
|
||||
#endif
|
||||
|
||||
/* Pseudorandom numbers */
|
||||
|
197
lib/bitmap.c
Normal file
197
lib/bitmap.c
Normal file
@ -0,0 +1,197 @@
|
||||
/*
|
||||
* BIRD Library -- Bitmaps
|
||||
*
|
||||
* (c) 2019 Ondrej Zajicek <santiago@crfreenet.org>
|
||||
* (c) 2019 CZ.NIC z.s.p.o.
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "nest/bird.h"
|
||||
#include "lib/bitmap.h"
|
||||
#include "lib/bitops.h"
|
||||
#include "lib/resource.h"
|
||||
|
||||
|
||||
/*
|
||||
* Basic bitmap
|
||||
*/
|
||||
|
||||
void
|
||||
bmap_init(struct bmap *b, pool *p, uint size)
|
||||
{
|
||||
b->size = BIRD_ALIGN(size, 4);
|
||||
b->data = mb_allocz(p, b->size);
|
||||
}
|
||||
|
||||
void
|
||||
bmap_reset(struct bmap *b, uint size)
|
||||
{
|
||||
b->size = BIRD_ALIGN(size, 4);
|
||||
memset(b->data, 0, b->size);
|
||||
}
|
||||
|
||||
void
|
||||
bmap_grow(struct bmap *b, uint need)
|
||||
{
|
||||
uint size = b->size * 2;
|
||||
while (size < need)
|
||||
size *= 2;
|
||||
|
||||
uint old_size = b->size;
|
||||
b->size = size;
|
||||
b->data = mb_realloc(b->data, b->size);
|
||||
|
||||
ASSERT(size >= old_size);
|
||||
memset(b->data + (old_size / 4), 0, size - old_size);
|
||||
}
|
||||
|
||||
void
|
||||
bmap_free(struct bmap *b)
|
||||
{
|
||||
mb_free(b->data);
|
||||
b->size = 0;
|
||||
b->data = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Hierarchical bitmap
|
||||
*/
|
||||
|
||||
#define B256_SIZE(b) BIRD_ALIGN(b, 32)
|
||||
#define B256_STEP(b) (BIRD_ALIGN(b, 8192) >> 8)
|
||||
|
||||
void
|
||||
hmap_init(struct hmap *b, pool *p, uint size)
|
||||
{
|
||||
b->size[0] = B256_SIZE(size);
|
||||
b->size[1] = B256_STEP(b->size[0]);
|
||||
b->size[2] = B256_STEP(b->size[1]);
|
||||
b->size[3] = sizeof(b->root);
|
||||
|
||||
b->data[0] = mb_allocz(p, b->size[0]);
|
||||
b->data[1] = mb_allocz(p, b->size[1]);
|
||||
b->data[2] = mb_allocz(p, b->size[2]);
|
||||
b->data[3] = b->root;
|
||||
|
||||
memset(b->root, 0, sizeof(b->root));
|
||||
}
|
||||
|
||||
static void
|
||||
hmap_grow(struct hmap *b, uint need)
|
||||
{
|
||||
uint size = b->size[0] * 2;
|
||||
while (size < need)
|
||||
size *= 2;
|
||||
|
||||
for (uint i = 0; i < 3; i++)
|
||||
{
|
||||
uint old_size = b->size[i];
|
||||
b->size[i] = size;
|
||||
b->data[i] = mb_realloc(b->data[i], b->size[i]);
|
||||
|
||||
ASSERT(size >= old_size);
|
||||
memset(b->data[i] + (old_size / 4), 0, size - old_size);
|
||||
|
||||
size = B256_STEP(size);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
hmap_free(struct hmap *b)
|
||||
{
|
||||
mb_free(b->data[0]);
|
||||
mb_free(b->data[1]);
|
||||
mb_free(b->data[2]);
|
||||
|
||||
memset(b, 0, sizeof(struct hmap));
|
||||
}
|
||||
|
||||
static inline int
|
||||
b256_and(u32 *p)
|
||||
{
|
||||
for (int i = 0; i < 8; i++)
|
||||
if (~p[i])
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
hmap_set(struct hmap *b, uint n)
|
||||
{
|
||||
if (n >= hmap_max(b))
|
||||
hmap_grow(b, n/8 + 1);
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
BIT32_SET(b->data[i], n);
|
||||
n = n >> 8;
|
||||
|
||||
/* Continue if all bits in 256-bit block are set */
|
||||
if (! b256_and(b->data[i] + 8*n))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
hmap_clear(struct hmap *b, uint n)
|
||||
{
|
||||
if (n >= hmap_max(b))
|
||||
return;
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
BIT32_CLR(b->data[i], n);
|
||||
n = n >> 8;
|
||||
}
|
||||
}
|
||||
|
||||
static inline int
|
||||
b256_first_zero(u32 *p)
|
||||
{
|
||||
for (int i = 0; i < 8; i++)
|
||||
if (~p[i])
|
||||
return 32*i + u32_ctz(~p[i]);
|
||||
|
||||
return 256;
|
||||
}
|
||||
|
||||
u32
|
||||
hmap_first_zero(struct hmap *b)
|
||||
{
|
||||
u32 n = 0;
|
||||
|
||||
for (int i = 3; i >= 0; i--)
|
||||
{
|
||||
if (32*n >= b->size[i])
|
||||
return hmap_max(b);
|
||||
|
||||
u32 *p = b->data[i] + 8*n;
|
||||
|
||||
n = (n << 8) + b256_first_zero(p);
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
void
|
||||
hmap_check(struct hmap *b)
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
int max = b->size[i] / 32;
|
||||
|
||||
for (int j = 0; j < max; j++)
|
||||
{
|
||||
int x = b256_and(b->data[i] + 8*j);
|
||||
int y = !!BIT32_TEST(b->data[i+1], j);
|
||||
if (x != y)
|
||||
bug("Inconsistent data on %d:%d (%d vs %d)", i, j, x, y);
|
||||
}
|
||||
}
|
||||
}
|
63
lib/bitmap.h
Normal file
63
lib/bitmap.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* BIRD Library -- Bitmaps
|
||||
*
|
||||
* (c) 2019 Ondrej Zajicek <santiago@crfreenet.org>
|
||||
* (c) 2019 CZ.NIC z.s.p.o.
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#ifndef _BIRD_BITMAP_H_
|
||||
#define _BIRD_BITMAP_H_
|
||||
|
||||
struct bmap
|
||||
{
|
||||
u32 size;
|
||||
u32 *data;
|
||||
};
|
||||
|
||||
void bmap_init(struct bmap *b, pool *p, uint size);
|
||||
void bmap_reset(struct bmap *b, uint size);
|
||||
void bmap_grow(struct bmap *b, uint need);
|
||||
void bmap_free(struct bmap *b);
|
||||
|
||||
static inline uint bmap_max(struct bmap *b)
|
||||
{ return 8 * b->size; }
|
||||
|
||||
static inline int bmap_test(struct bmap *b, uint n)
|
||||
{ return (n < bmap_max(b)) && BIT32_TEST(b->data, n); }
|
||||
|
||||
static inline void bmap_set(struct bmap *b, uint n)
|
||||
{
|
||||
if (n >= bmap_max(b)) bmap_grow(b, n/8 + 1);
|
||||
BIT32_SET(b->data, n);
|
||||
}
|
||||
|
||||
static inline void bmap_clear(struct bmap *b, uint n)
|
||||
{
|
||||
if (n >= bmap_max(b)) return;
|
||||
BIT32_CLR(b->data, n);
|
||||
}
|
||||
|
||||
|
||||
struct hmap
|
||||
{
|
||||
u32 size[4];
|
||||
u32 *data[4];
|
||||
u32 root[8];
|
||||
};
|
||||
|
||||
static inline uint hmap_max(struct hmap *b)
|
||||
{ return 8 * b->size[0]; }
|
||||
|
||||
static inline int hmap_test(struct hmap *b, uint n)
|
||||
{ return (n < hmap_max(b)) && BIT32_TEST(b->data[0], n); }
|
||||
|
||||
void hmap_init(struct hmap *b, pool *p, uint size);
|
||||
void hmap_free(struct hmap *b);
|
||||
void hmap_set(struct hmap *b, uint n);
|
||||
void hmap_clear(struct hmap *b, uint n);
|
||||
u32 hmap_first_zero(struct hmap *b);
|
||||
void hmap_check(struct hmap *b);
|
||||
|
||||
#endif
|
186
lib/bitmap_test.c
Normal file
186
lib/bitmap_test.c
Normal file
@ -0,0 +1,186 @@
|
||||
/*
|
||||
* BIRD Library -- Bitmap Tests
|
||||
*
|
||||
* (c) 2019 Ondrej Zajicek <santiago@crfreenet.org>
|
||||
* (c) 2019 CZ.NIC z.s.p.o.
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#include "test/birdtest.h"
|
||||
#include "sysdep/config.h"
|
||||
#include "lib/bitmap.h"
|
||||
|
||||
#define MAX_NUM (1 << 20)
|
||||
#define MAX_SET (1 << 19)
|
||||
#define MAX_CLR (1 << 17)
|
||||
|
||||
#define STEP_NUM 1000
|
||||
#define STEP_SET 1000
|
||||
#define STEP_CLR 500
|
||||
|
||||
static int
|
||||
t_bmap_set_clear_random(void)
|
||||
{
|
||||
struct bmap b;
|
||||
|
||||
resource_init();
|
||||
bmap_init(&b, &root_pool, 1024);
|
||||
|
||||
char expected[MAX_NUM] = {};
|
||||
uint i, n;
|
||||
|
||||
for (i = 0; i < MAX_SET; i++)
|
||||
{
|
||||
do n = bt_random() % MAX_NUM;
|
||||
while (expected[n]);
|
||||
|
||||
bmap_set(&b, n);
|
||||
expected[n] = 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < MAX_CLR; i++)
|
||||
{
|
||||
do n = bt_random() % MAX_NUM;
|
||||
while (!expected[n]);
|
||||
|
||||
bmap_clear(&b, n);
|
||||
expected[n] = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
if (bmap_test(&b, i) != expected[i])
|
||||
bt_abort_msg("Bitmap mismatch on %d (should be %d %d)", i, bmap_test(&b, i), expected[i]);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_hmap_set_clear_random(void)
|
||||
{
|
||||
struct hmap b;
|
||||
|
||||
resource_init();
|
||||
hmap_init(&b, &root_pool, 1024);
|
||||
|
||||
char expected[MAX_NUM] = {};
|
||||
uint i, n;
|
||||
|
||||
for (i = 0; i < MAX_SET; i++)
|
||||
{
|
||||
do n = bt_random() % MAX_NUM;
|
||||
while (expected[n]);
|
||||
|
||||
hmap_set(&b, n);
|
||||
expected[n] = 1;
|
||||
}
|
||||
|
||||
hmap_check(&b);
|
||||
|
||||
for (i = 0; i < MAX_CLR; i++)
|
||||
{
|
||||
do n = bt_random() % MAX_NUM;
|
||||
while (!expected[n]);
|
||||
|
||||
hmap_clear(&b, n);
|
||||
expected[n] = 0;
|
||||
}
|
||||
|
||||
hmap_check(&b);
|
||||
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
if (hmap_test(&b, i) != expected[i])
|
||||
bt_abort_msg("Bitmap mismatch on %d (should be %d %d)", i, hmap_test(&b, i), expected[i]);
|
||||
|
||||
for (i = 0; 1; i++)
|
||||
{
|
||||
n = hmap_first_zero(&b);
|
||||
bt_assert(n >= i);
|
||||
bt_assert(n <= MAX_NUM);
|
||||
|
||||
for (; i < n; i++)
|
||||
bt_assert(expected[i]);
|
||||
|
||||
if (n == MAX_NUM)
|
||||
break;
|
||||
|
||||
bt_assert(!expected[i]);
|
||||
|
||||
hmap_set(&b, n);
|
||||
}
|
||||
|
||||
hmap_check(&b);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_hmap_set_clear_fill(void)
|
||||
{
|
||||
struct hmap b;
|
||||
|
||||
resource_init();
|
||||
hmap_init(&b, &root_pool, 1024);
|
||||
|
||||
char expected[MAX_NUM] = {};
|
||||
uint i, j, n, max = 0;
|
||||
|
||||
for (i = 0; i < STEP_NUM; i++)
|
||||
{
|
||||
uint last = 0;
|
||||
uint step_set = bt_random() % STEP_SET;
|
||||
uint step_clr = bt_random() % STEP_CLR;
|
||||
|
||||
for (j = 0; j < step_set; j++)
|
||||
{
|
||||
n = hmap_first_zero(&b);
|
||||
bt_assert(n > last || !last);
|
||||
bt_assert(n < MAX_NUM);
|
||||
|
||||
if (!last)
|
||||
last = n;
|
||||
|
||||
for (; last < n; last++)
|
||||
bt_assert(expected[last]);
|
||||
|
||||
bt_assert(!expected[n]);
|
||||
|
||||
hmap_set(&b, n);
|
||||
expected[n] = 1;
|
||||
max = MAX(max, n);
|
||||
}
|
||||
|
||||
for (j = 0; j < step_clr; j++)
|
||||
{
|
||||
uint k = 0;
|
||||
do n = bt_random() % max;
|
||||
while (!expected[n] && (k++ < 8));
|
||||
|
||||
if (!expected[n])
|
||||
continue;
|
||||
|
||||
hmap_clear(&b, n);
|
||||
expected[n] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
if (hmap_test(&b, i) != expected[i])
|
||||
bt_abort_msg("Bitmap mismatch on %d (should be %d %d)", i, hmap_test(&b, i), expected[i]);
|
||||
|
||||
hmap_check(&b);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
bt_init(argc, argv);
|
||||
|
||||
bt_test_suite(t_bmap_set_clear_random, "BMap - random sequence of sets / clears");
|
||||
bt_test_suite(t_hmap_set_clear_random, "HMap - random sequence of sets / clears");
|
||||
bt_test_suite(t_hmap_set_clear_fill, "HMap - linear sets and random clears");
|
||||
|
||||
return bt_exit_value();
|
||||
}
|
@ -17,7 +17,7 @@
|
||||
* representation consists of @n ones followed by zeroes.
|
||||
*/
|
||||
u32
|
||||
u32_mkmask(unsigned n)
|
||||
u32_mkmask(uint n)
|
||||
{
|
||||
return n ? ~((1 << (32 - n)) - 1) : 0;
|
||||
}
|
||||
@ -28,15 +28,15 @@ u32_mkmask(unsigned n)
|
||||
*
|
||||
* This function checks whether the given integer @x represents
|
||||
* a valid bit mask (binary representation contains first ones, then
|
||||
* zeroes) and returns the number of ones or -1 if the mask is invalid.
|
||||
* zeroes) and returns the number of ones or 255 if the mask is invalid.
|
||||
*/
|
||||
int
|
||||
uint
|
||||
u32_masklen(u32 x)
|
||||
{
|
||||
int l = 0;
|
||||
u32 n = ~x;
|
||||
|
||||
if (n & (n+1)) return -1;
|
||||
if (n & (n+1)) return 255;
|
||||
if (x & 0x0000ffff) { x &= 0x0000ffff; l += 16; }
|
||||
if (x & 0x00ff00ff) { x &= 0x00ff00ff; l += 8; }
|
||||
if (x & 0x0f0f0f0f) { x &= 0x0f0f0f0f; l += 4; }
|
||||
|
20
lib/bitops.h
20
lib/bitops.h
@ -6,6 +6,11 @@
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#ifndef _BIRD_BITOPTS_H_
|
||||
#define _BIRD_BITOPTS_H_
|
||||
|
||||
#include "sysdep/config.h"
|
||||
|
||||
/*
|
||||
* Bit mask operations:
|
||||
*
|
||||
@ -15,7 +20,18 @@
|
||||
* u32_masklen Inverse operation to u32_mkmask, -1 if not a bitmask.
|
||||
*/
|
||||
|
||||
u32 u32_mkmask(unsigned n);
|
||||
int u32_masklen(u32 x);
|
||||
u32 u32_mkmask(uint n);
|
||||
uint u32_masklen(u32 x);
|
||||
|
||||
u32 u32_log2(u32 v);
|
||||
|
||||
static inline u32 u32_hash(u32 v) { return v * 2902958171u; }
|
||||
|
||||
static inline u8 u32_popcount(u32 v) { return __builtin_popcount(v); }
|
||||
|
||||
static inline int u32_clz(u32 v) { return __builtin_clz(v); }
|
||||
static inline int u32_ctz(u32 v) { return __builtin_ctz(v); }
|
||||
|
||||
static inline int uint_is_pow2(uint n) { return n && !(n & (n-1)); }
|
||||
|
||||
#endif
|
||||
|
123
lib/bitops_test.c
Normal file
123
lib/bitops_test.c
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
* BIRD Library -- Generic Bit Operations Tests
|
||||
*
|
||||
* (c) 2015 CZ.NIC z.s.p.o.
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#include "test/birdtest.h"
|
||||
#include "test/bt-utils.h" /* naive_pow() */
|
||||
|
||||
#include "lib/bitops.h"
|
||||
|
||||
#define MAX_NUM 1000
|
||||
#define CHECK_BIT(var,pos) ((var) & (u32)(1<<(pos)))
|
||||
|
||||
static int
|
||||
t_mkmask(void)
|
||||
{
|
||||
int i;
|
||||
u32 compute, expect;
|
||||
|
||||
bt_assert(u32_mkmask(0) == 0x00000000);
|
||||
for (i = 1; i <= 32; i++)
|
||||
{
|
||||
compute = u32_mkmask(i);
|
||||
expect = (u32) (0xffffffff << (32-i));
|
||||
bt_assert_msg(compute == expect, "u32_mkmask(%d) = 0x%08X, expected 0x%08X", i, compute, expect);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
u32_masklen_expected(u32 mask)
|
||||
{
|
||||
int j, expect = 0;
|
||||
|
||||
int valid = 0;
|
||||
for (j = 0; j <= 32; j++)
|
||||
if (mask == (j ? (0xffffffff << (32-j)) : 0)) /* Shifting 32-bit value by 32 bits is undefined behavior */
|
||||
valid = 1;
|
||||
|
||||
if (!valid && mask != 0)
|
||||
expect = 255;
|
||||
else
|
||||
for (j = 0; j <= 31; j++)
|
||||
if (CHECK_BIT(mask, (31-j)))
|
||||
expect = j+1;
|
||||
else
|
||||
break;
|
||||
return expect;
|
||||
}
|
||||
|
||||
static void
|
||||
check_mask(u32 mask)
|
||||
{
|
||||
int expected, masklen;
|
||||
|
||||
expected = u32_masklen_expected(mask);
|
||||
masklen = u32_masklen(mask);
|
||||
int ok = (expected == masklen);
|
||||
bt_debug("u32_masklen(Ox%08x) = %d, expected %d %s\n", mask, masklen, expected, ok ? "OK" : "FAIL!");
|
||||
bt_assert(ok);
|
||||
}
|
||||
|
||||
static int
|
||||
t_masklen(void)
|
||||
{
|
||||
u32 i;
|
||||
|
||||
check_mask(0x82828282);
|
||||
check_mask(0x00000000);
|
||||
|
||||
for (i = 0; i <= 32; i++)
|
||||
check_mask(((u32) (i ? (0xffffffff << (32-i)) : 0)) & 0xffffffff); /* Shifting 32-bit value by 32 bits is undefined behavior */
|
||||
|
||||
for (i = 0; i <= MAX_NUM; i++)
|
||||
check_mask(bt_random());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
check_log2(u32 n)
|
||||
{
|
||||
u32 log = u32_log2(n);
|
||||
u32 low = bt_naive_pow(2, log);
|
||||
u32 high = bt_naive_pow(2, log+1);
|
||||
|
||||
bt_assert_msg(n >= low && n < high,
|
||||
"u32_log2(%u) = %u, %u should be in the range <%u, %u)",
|
||||
n, log, n, low, high);
|
||||
}
|
||||
|
||||
static int
|
||||
t_log2(void)
|
||||
{
|
||||
u32 i;
|
||||
|
||||
for (i = 0; i < 31; i++)
|
||||
bt_assert(u32_log2(bt_naive_pow(2, i+1)) == i+1);
|
||||
|
||||
for (i = 1; i < MAX_NUM; i++)
|
||||
check_log2(i);
|
||||
|
||||
for (i = 1; i < MAX_NUM; i++)
|
||||
check_log2(((u32) bt_random()) % 0x0fffffff);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
bt_init(argc, argv);
|
||||
|
||||
bt_test_suite(t_mkmask, "u32_mkmask()");
|
||||
bt_test_suite(t_masklen, "u32_masklen()");
|
||||
bt_test_suite(t_log2, "u32_log2()");
|
||||
|
||||
return bt_exit_value();
|
||||
}
|
65
lib/buffer.h
Normal file
65
lib/buffer.h
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* BIRD Library -- Generic Buffer Structure
|
||||
*
|
||||
* (c) 2013 Ondrej Zajicek <santiago@crfreenet.org>
|
||||
* (c) 2013 CZ.NIC z.s.p.o.
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#ifndef _BIRD_BUFFER_H_
|
||||
#define _BIRD_BUFFER_H_
|
||||
|
||||
#include "lib/resource.h"
|
||||
#include "sysdep/config.h"
|
||||
|
||||
#define BUFFER_(type) struct { type *data; uint used, size; }
|
||||
#define BUFFER_TYPE(v) typeof(* (v).data)
|
||||
#define BUFFER_SIZE(v) ((v).size * sizeof(* (v).data))
|
||||
|
||||
#ifndef PARSER
|
||||
#define BUFFER(type) BUFFER_(type)
|
||||
#endif
|
||||
|
||||
#define BUFFER_INIT(v,pool,isize) \
|
||||
({ \
|
||||
(v).used = 0; \
|
||||
(v).size = (isize); \
|
||||
(v).data = mb_alloc(pool, BUFFER_SIZE(v)); \
|
||||
})
|
||||
|
||||
#define BUFFER_SET(v,nsize) \
|
||||
({ \
|
||||
(v).used = (nsize); \
|
||||
if ((v).used > (v).size) \
|
||||
buffer_realloc((void **) &((v).data), &((v).size), (v).used, sizeof(* (v).data)); \
|
||||
})
|
||||
|
||||
#define BUFFER_INC(v,step) \
|
||||
({ \
|
||||
uint _o = (v).used; \
|
||||
BUFFER_SET(v, (v).used + (step)); \
|
||||
(v).data + _o; \
|
||||
})
|
||||
|
||||
#define BUFFER_DEC(v,step) ({ (v).used -= (step); })
|
||||
|
||||
#define BUFFER_PUSH(v) (*BUFFER_INC(v,1))
|
||||
|
||||
#define BUFFER_POP(v) BUFFER_DEC(v,1)
|
||||
|
||||
#define BUFFER_FLUSH(v) ({ (v).used = 0; })
|
||||
|
||||
#define BUFFER_EMPTY(v) ({ (v).used == 0; })
|
||||
|
||||
#define BUFFER_WALK(v,n) \
|
||||
for (BUFFER_TYPE(v) *_n = (v).data, n; _n < ((v).data + (v).used) && (n = *_n, 1); _n++)
|
||||
|
||||
#define BUFFER_SHALLOW_COPY(dst, src) \
|
||||
({ \
|
||||
(dst).used = (src).used; \
|
||||
(dst).size = (src).size; \
|
||||
(dst).data = (src).data; \
|
||||
})
|
||||
|
||||
#endif /* _BIRD_BUFFER_H_ */
|
167
lib/buffer_test.c
Normal file
167
lib/buffer_test.c
Normal file
@ -0,0 +1,167 @@
|
||||
/*
|
||||
* BIRD Library -- Buffer Tests
|
||||
*
|
||||
* (c) 2015 CZ.NIC z.s.p.o.
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "test/birdtest.h"
|
||||
|
||||
#include "lib/buffer.h"
|
||||
|
||||
#define MAX_NUM 33
|
||||
|
||||
typedef BUFFER(int) buffer_int;
|
||||
static int expected[MAX_NUM];
|
||||
static buffer_int buf;
|
||||
static struct pool *buffer_pool;
|
||||
|
||||
static void
|
||||
show_buf(buffer_int *b)
|
||||
{
|
||||
uint i;
|
||||
bt_debug(".used = %d, .size = %d\n", b->used, b->size);
|
||||
|
||||
for (i = 0; i < b->used; i++)
|
||||
bt_debug(" .data[%3u] = %-16d expected %-16d %s\n", i, b->data[i], expected[i], (b->data[i] == expected[i] ? "OK" : "FAIL!"));
|
||||
}
|
||||
|
||||
static void
|
||||
fill_expected_array(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
expected[i] = bt_random();
|
||||
}
|
||||
|
||||
static void
|
||||
init_buffer(void)
|
||||
{
|
||||
resource_init();
|
||||
buffer_pool = &root_pool;
|
||||
BUFFER_INIT(buf, buffer_pool, MAX_NUM);
|
||||
}
|
||||
|
||||
static int
|
||||
is_buffer_as_expected(buffer_int *b)
|
||||
{
|
||||
show_buf(b);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
bt_assert(b->data[i] == expected[i]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_buffer_push(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
init_buffer();
|
||||
fill_expected_array();
|
||||
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
BUFFER_PUSH(buf) = expected[i];
|
||||
is_buffer_as_expected(&buf);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_buffer_pop(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
init_buffer();
|
||||
fill_expected_array();
|
||||
|
||||
/* POP a half of elements */
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
BUFFER_PUSH(buf) = expected[i];
|
||||
for (i = MAX_NUM-1; i >= MAX_NUM/2; i--)
|
||||
BUFFER_POP(buf);
|
||||
for (i = MAX_NUM/2; i < MAX_NUM; i++)
|
||||
BUFFER_PUSH(buf) = expected[i] = bt_random();
|
||||
is_buffer_as_expected(&buf);
|
||||
|
||||
/* POP all of elements */
|
||||
for (i = MAX_NUM-1; i >= 0; i--)
|
||||
BUFFER_POP(buf);
|
||||
bt_assert(buf.used == 0);
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
BUFFER_PUSH(buf) = expected[i];
|
||||
is_buffer_as_expected(&buf);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_buffer_resize(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
init_buffer();
|
||||
BUFFER_INIT(buf, buffer_pool, 0);
|
||||
fill_expected_array();
|
||||
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
BUFFER_PUSH(buf) = expected[i];
|
||||
is_buffer_as_expected(&buf);
|
||||
bt_assert(buf.size >= MAX_NUM);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_buffer_flush(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
init_buffer();
|
||||
fill_expected_array();
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
BUFFER_PUSH(buf) = expected[i];
|
||||
|
||||
BUFFER_FLUSH(buf);
|
||||
bt_assert(buf.used == 0);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_buffer_walk(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
init_buffer();
|
||||
fill_expected_array();
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
BUFFER_PUSH(buf) = expected[i];
|
||||
|
||||
i = 0;
|
||||
BUFFER_WALK(buf, v)
|
||||
bt_assert(v == expected[i++]);
|
||||
|
||||
bt_assert(i == MAX_NUM);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
bt_init(argc, argv);
|
||||
|
||||
bt_test_suite(t_buffer_push, "Pushing new elements");
|
||||
bt_test_suite(t_buffer_pop, "Fill whole buffer (PUSH), a half of elements POP and PUSH new elements");
|
||||
bt_test_suite(t_buffer_resize, "Init a small buffer and try overfill");
|
||||
bt_test_suite(t_buffer_flush, "Fill and flush all elements");
|
||||
bt_test_suite(t_buffer_walk, "Fill and walk through buffer");
|
||||
|
||||
return bt_exit_value();
|
||||
}
|
@ -28,7 +28,7 @@ add32(u32 sum, u32 x)
|
||||
}
|
||||
|
||||
static u16
|
||||
ipsum_calc_block(u32 *buf, unsigned len, u16 isum)
|
||||
ipsum_calc_block(u32 *buf, uint len, u16 isum)
|
||||
{
|
||||
/*
|
||||
* A few simple facts about the IP checksum (see RFC 1071 for detailed
|
||||
@ -57,7 +57,7 @@ ipsum_calc_block(u32 *buf, unsigned len, u16 isum)
|
||||
}
|
||||
|
||||
static u16
|
||||
ipsum_calc(void *frag, unsigned len, va_list args)
|
||||
ipsum_calc(void *frag, uint len, va_list args)
|
||||
{
|
||||
u16 sum = 0;
|
||||
|
||||
@ -67,7 +67,7 @@ ipsum_calc(void *frag, unsigned len, va_list args)
|
||||
frag = va_arg(args, void *);
|
||||
if (!frag)
|
||||
break;
|
||||
len = va_arg(args, unsigned);
|
||||
len = va_arg(args, uint);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
@ -87,7 +87,7 @@ ipsum_calc(void *frag, unsigned len, va_list args)
|
||||
* Result: 1 if the checksum is correct, 0 else.
|
||||
*/
|
||||
int
|
||||
ipsum_verify(void *frag, unsigned len, ...)
|
||||
ipsum_verify(void *frag, uint len, ...)
|
||||
{
|
||||
va_list args;
|
||||
u16 sum;
|
||||
@ -110,7 +110,7 @@ ipsum_verify(void *frag, unsigned len, ...)
|
||||
* up checksum calculation as much as possible.
|
||||
*/
|
||||
u16
|
||||
ipsum_calculate(void *frag, unsigned len, ...)
|
||||
ipsum_calculate(void *frag, uint len, ...)
|
||||
{
|
||||
va_list args;
|
||||
u16 sum;
|
||||
|
@ -14,7 +14,7 @@
|
||||
* fragments finished by NULL pointer.
|
||||
*/
|
||||
|
||||
int ipsum_verify(void *frag, unsigned len, ...);
|
||||
u16 ipsum_calculate(void *frag, unsigned len, ...);
|
||||
int ipsum_verify(void *frag, uint len, ...);
|
||||
u16 ipsum_calculate(void *frag, uint len, ...);
|
||||
|
||||
#endif
|
||||
|
94
lib/checksum_test.c
Normal file
94
lib/checksum_test.c
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* BIRD Library -- IP One-Complement Checksum Tests
|
||||
*
|
||||
* (c) 2015 CZ.NIC z.s.p.o.
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "test/birdtest.h"
|
||||
|
||||
#include "lib/checksum.h"
|
||||
|
||||
#define MAX_NUM 10000
|
||||
|
||||
static u16
|
||||
ipsum_calculate_expected(u32 *a)
|
||||
{
|
||||
int i;
|
||||
u32 sum = 0;
|
||||
|
||||
for(i = 0; i < MAX_NUM; i++)
|
||||
{
|
||||
sum += a[i] & 0xffff;
|
||||
bt_debug("low) \t0x%08X \n", sum);
|
||||
|
||||
sum += a[i] >> 16;
|
||||
bt_debug("high) \t0x%08X \n", sum);
|
||||
|
||||
u16 carry = sum >> 16;
|
||||
sum = (sum & 0xffff) + carry;
|
||||
bt_debug("carry) \t0x%08X \n\n", sum);
|
||||
}
|
||||
bt_debug("sum) \t0x%08X \n", sum);
|
||||
|
||||
sum = sum ^ 0xffff;
|
||||
bt_debug("~sum) \t0x%08X \n", sum);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
static int
|
||||
t_calculate(void)
|
||||
{
|
||||
u32 a[MAX_NUM];
|
||||
int i;
|
||||
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
a[i] = bt_random();
|
||||
|
||||
u16 sum_calculated = ipsum_calculate(a, sizeof(a), NULL);
|
||||
u16 sum_calculated_2 = ipsum_calculate(&a[0], sizeof(u32)*(MAX_NUM/2), &a[MAX_NUM/2], sizeof(u32)*(MAX_NUM - MAX_NUM/2), NULL);
|
||||
bt_assert(sum_calculated == sum_calculated_2);
|
||||
|
||||
u16 sum_expected = ipsum_calculate_expected(a);
|
||||
|
||||
bt_debug("sum_calculated: %08X \n", sum_calculated);
|
||||
bt_debug("sum_expected: %08X \n", sum_expected);
|
||||
|
||||
bt_assert(sum_calculated == sum_expected);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_verify(void)
|
||||
{
|
||||
u32 a[MAX_NUM+1];
|
||||
int i;
|
||||
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
a[i] = bt_random();
|
||||
|
||||
u16 sum = ipsum_calculate_expected(a);
|
||||
|
||||
a[MAX_NUM] = sum;
|
||||
|
||||
bt_assert(ipsum_verify(a, sizeof(a), NULL));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
bt_init(argc, argv);
|
||||
|
||||
bt_test_suite(t_calculate, "Checksum of pseudo-random data");
|
||||
bt_test_suite(t_verify, "Verification of pseudo-random data.");
|
||||
|
||||
return bt_exit_value();
|
||||
}
|
63
lib/event.c
63
lib/event.c
@ -23,11 +23,12 @@
|
||||
#include "lib/event.h"
|
||||
|
||||
event_list global_event_list;
|
||||
event_list global_work_list;
|
||||
|
||||
inline void
|
||||
ev_postpone(event *e)
|
||||
{
|
||||
if (e->n.next)
|
||||
if (ev_active(e))
|
||||
{
|
||||
rem_node(&e->n);
|
||||
e->n.next = NULL;
|
||||
@ -114,6 +115,24 @@ ev_schedule(event *e)
|
||||
ev_enqueue(&global_event_list, e);
|
||||
}
|
||||
|
||||
/**
|
||||
* ev_schedule_work - schedule a work-event.
|
||||
* @e: an event
|
||||
*
|
||||
* This function schedules an event by enqueueing it to a system-wide work-event
|
||||
* list which is run by the platform dependent code whenever appropriate. This
|
||||
* is designated for work-events instead of regular events. They are executed
|
||||
* less often in order to not clog I/O loop.
|
||||
*/
|
||||
void
|
||||
ev_schedule_work(event *e)
|
||||
{
|
||||
if (!ev_active(e))
|
||||
add_tail(&global_work_list, &e->n);
|
||||
}
|
||||
|
||||
void io_log_event(void *hook, void *data);
|
||||
|
||||
/**
|
||||
* ev_run_list - run an event list
|
||||
* @l: an event list
|
||||
@ -132,7 +151,49 @@ ev_run_list(event_list *l)
|
||||
WALK_LIST_FIRST(n, tmp_list)
|
||||
{
|
||||
event *e = SKIP_BACK(event, n, n);
|
||||
|
||||
/* This is ugly hack, we want to log just events executed from the main I/O loop */
|
||||
if ((l == &global_event_list) || (l == &global_work_list))
|
||||
io_log_event(e->hook, e->data);
|
||||
|
||||
ev_run(e);
|
||||
}
|
||||
|
||||
return !EMPTY_LIST(*l);
|
||||
}
|
||||
|
||||
int
|
||||
ev_run_list_limited(event_list *l, uint limit)
|
||||
{
|
||||
node *n;
|
||||
list tmp_list;
|
||||
|
||||
init_list(&tmp_list);
|
||||
add_tail_list(&tmp_list, l);
|
||||
init_list(l);
|
||||
|
||||
WALK_LIST_FIRST(n, tmp_list)
|
||||
{
|
||||
event *e = SKIP_BACK(event, n, n);
|
||||
|
||||
if (!limit)
|
||||
break;
|
||||
|
||||
/* This is ugly hack, we want to log just events executed from the main I/O loop */
|
||||
if ((l == &global_event_list) || (l == &global_work_list))
|
||||
io_log_event(e->hook, e->data);
|
||||
|
||||
ev_run(e);
|
||||
limit--;
|
||||
}
|
||||
|
||||
if (!EMPTY_LIST(tmp_list))
|
||||
{
|
||||
/* Attach new items after the unprocessed old items */
|
||||
add_tail_list(&tmp_list, l);
|
||||
init_list(l);
|
||||
add_tail_list(l, &tmp_list);
|
||||
}
|
||||
|
||||
return !EMPTY_LIST(*l);
|
||||
}
|
||||
|
19
lib/event.h
19
lib/event.h
@ -21,13 +21,32 @@ typedef struct event {
|
||||
typedef list event_list;
|
||||
|
||||
extern event_list global_event_list;
|
||||
extern event_list global_work_list;
|
||||
|
||||
event *ev_new(pool *);
|
||||
void ev_run(event *);
|
||||
#define ev_init_list(el) init_list(el)
|
||||
void ev_enqueue(event_list *, event *);
|
||||
void ev_schedule(event *);
|
||||
void ev_schedule_work(event *);
|
||||
void ev_postpone(event *);
|
||||
int ev_run_list(event_list *);
|
||||
int ev_run_list_limited(event_list *, uint);
|
||||
|
||||
static inline int
|
||||
ev_active(event *e)
|
||||
{
|
||||
return e->n.next != NULL;
|
||||
}
|
||||
|
||||
static inline event*
|
||||
ev_new_init(pool *p, void (*hook)(void *), void *data)
|
||||
{
|
||||
event *e = ev_new(p);
|
||||
e->hook = hook;
|
||||
e->data = data;
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
89
lib/event_test.c
Normal file
89
lib/event_test.c
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* BIRD Library -- Event Processing Tests
|
||||
*
|
||||
* (c) 2015 CZ.NIC z.s.p.o.
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
|
||||
#include "test/birdtest.h"
|
||||
|
||||
#include "lib/net.h"
|
||||
#include "lib/event.h"
|
||||
#include "conf/conf.h"
|
||||
#include "nest/locks.h"
|
||||
#include "sysdep/unix/unix.h"
|
||||
#include "nest/iface.h"
|
||||
#include "nest/route.h"
|
||||
|
||||
#define MAX_NUM 4
|
||||
|
||||
int event_check_points[MAX_NUM];
|
||||
|
||||
#define event_hook_body(num) \
|
||||
do { \
|
||||
bt_debug("Event Hook " #num "\n"); \
|
||||
event_check_points[num] = 1; \
|
||||
bt_assert_msg(event_check_points[num-1], "Events should be run in right order"); \
|
||||
} while (0)
|
||||
|
||||
static void event_hook_1(void *data UNUSED) { event_hook_body(1); }
|
||||
static void event_hook_2(void *data UNUSED) { event_hook_body(2); }
|
||||
static void event_hook_3(void *data UNUSED) { event_hook_body(3); }
|
||||
|
||||
#define schedule_event(num) \
|
||||
do { \
|
||||
struct event *event_##num = ev_new(&root_pool); \
|
||||
event_##num->hook = event_hook_##num; \
|
||||
ev_schedule(event_##num); \
|
||||
} while (0)
|
||||
|
||||
static void
|
||||
init_event_check_points(void)
|
||||
{
|
||||
int i;
|
||||
event_check_points[0] = 1;
|
||||
for (i = 1; i < MAX_NUM; i++)
|
||||
event_check_points[i] = 0;
|
||||
}
|
||||
|
||||
static int
|
||||
t_ev_run_list(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
resource_init();
|
||||
olock_init();
|
||||
timer_init();
|
||||
io_init();
|
||||
rt_init();
|
||||
if_init();
|
||||
// roa_init();
|
||||
config_init();
|
||||
config = config_alloc("");
|
||||
|
||||
init_event_check_points();
|
||||
|
||||
schedule_event(1);
|
||||
schedule_event(2);
|
||||
schedule_event(3);
|
||||
|
||||
ev_run_list(&global_event_list);
|
||||
|
||||
for (i = 1; i < MAX_NUM; i++)
|
||||
bt_assert(event_check_points[i]);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
bt_init(argc, argv);
|
||||
|
||||
bt_test_suite(t_ev_run_list, "Schedule and run 3 events in right order.");
|
||||
|
||||
return bt_exit_value();
|
||||
}
|
||||
|
196
lib/fletcher16.h
Normal file
196
lib/fletcher16.h
Normal file
@ -0,0 +1,196 @@
|
||||
/*
|
||||
* BIRD Library -- Fletcher-16 checksum
|
||||
*
|
||||
* (c) 2015 Ondrej Zajicek <santiago@crfreenet.org>
|
||||
* (c) 2015 CZ.NIC z.s.p.o.
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
/**
|
||||
* DOC: Fletcher-16 checksum
|
||||
*
|
||||
* Fletcher-16 checksum is a position-dependent checksum algorithm used for
|
||||
* error-detection e.g. in OSPF LSAs.
|
||||
*
|
||||
* To generate Fletcher-16 checksum, zero the checksum field in data, initialize
|
||||
* the context by fletcher16_init(), process the data by fletcher16_update(),
|
||||
* compute the checksum value by fletcher16_final() and store it to the checksum
|
||||
* field in data by put_u16() (or other means involving htons() conversion).
|
||||
*
|
||||
* To verify Fletcher-16 checksum, initialize the context by fletcher16_init(),
|
||||
* process the data by fletcher16_update(), compute a passing checksum by
|
||||
* fletcher16_compute() and check if it is zero.
|
||||
*/
|
||||
|
||||
#ifndef _BIRD_FLETCHER16_H_
|
||||
#define _BIRD_FLETCHER16_H_
|
||||
|
||||
#include "nest/bird.h"
|
||||
|
||||
|
||||
struct fletcher16_context
|
||||
{
|
||||
int c0, c1;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* fletcher16_init - initialize Fletcher-16 context
|
||||
* @ctx: the context
|
||||
*/
|
||||
static inline void
|
||||
fletcher16_init(struct fletcher16_context *ctx)
|
||||
{
|
||||
ctx->c0 = ctx->c1 = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* fletcher16_update - process data to Fletcher-16 context
|
||||
* @ctx: the context
|
||||
* @buf: data buffer
|
||||
* @len: data length
|
||||
*
|
||||
* fletcher16_update() reads data from the buffer @buf and updates passing sums
|
||||
* in the context @ctx. It may be used multiple times for multiple blocks of
|
||||
* checksummed data.
|
||||
*/
|
||||
static inline void
|
||||
fletcher16_update(struct fletcher16_context *ctx, const u8* buf, int len)
|
||||
{
|
||||
/*
|
||||
* The Fletcher-16 sum is essentially a sequence of
|
||||
* ctx->c1 += ctx->c0 += *buf++, modulo 255.
|
||||
*
|
||||
* In the inner loop, we eliminate modulo operation and we do some loop
|
||||
* unrolling. MODX is the maximal number of steps that can be done without
|
||||
* modulo before overflow, see RFC 1008 for details. We use a bit smaller
|
||||
* value to cover for initial steps due to loop unrolling.
|
||||
*/
|
||||
|
||||
#define MODX 4096
|
||||
|
||||
int blen, i;
|
||||
|
||||
blen = len % 4;
|
||||
len -= blen;
|
||||
|
||||
for (i = 0; i < blen; i++)
|
||||
ctx->c1 += ctx->c0 += *buf++;
|
||||
|
||||
do {
|
||||
blen = MIN(len, MODX);
|
||||
len -= blen;
|
||||
|
||||
for (i = 0; i < blen; i += 4)
|
||||
{
|
||||
ctx->c1 += ctx->c0 += *buf++;
|
||||
ctx->c1 += ctx->c0 += *buf++;
|
||||
ctx->c1 += ctx->c0 += *buf++;
|
||||
ctx->c1 += ctx->c0 += *buf++;
|
||||
}
|
||||
|
||||
ctx->c0 %= 255;
|
||||
ctx->c1 %= 255;
|
||||
|
||||
} while (len);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* fletcher16_update_n32 - process data to Fletcher-16 context, with endianity adjustment
|
||||
* @ctx: the context
|
||||
* @buf: data buffer
|
||||
* @len: data length
|
||||
*
|
||||
* fletcher16_update_n32() works like fletcher16_update(), except it applies
|
||||
* 32-bit host/network endianity swap to the data before they are processed.
|
||||
* I.e., it assumes that the data is a sequence of u32 that must be converted by
|
||||
* ntohl() or htonl() before processing. The @buf need not to be aligned, but
|
||||
* its length (@len) must be multiple of 4. Note that on big endian systems the
|
||||
* host endianity is the same as the network endianity, therefore there is no
|
||||
* endianity swap.
|
||||
*/
|
||||
static inline void
|
||||
fletcher16_update_n32(struct fletcher16_context *ctx, const u8* buf, int len)
|
||||
{
|
||||
/* See fletcher16_update() for details */
|
||||
|
||||
int blen, i;
|
||||
|
||||
do {
|
||||
blen = MIN(len, MODX);
|
||||
len -= blen;
|
||||
|
||||
for (i = 0; i < blen; i += 4)
|
||||
{
|
||||
#ifdef CPU_BIG_ENDIAN
|
||||
ctx->c1 += ctx->c0 += *buf++;
|
||||
ctx->c1 += ctx->c0 += *buf++;
|
||||
ctx->c1 += ctx->c0 += *buf++;
|
||||
ctx->c1 += ctx->c0 += *buf++;
|
||||
#else
|
||||
ctx->c1 += ctx->c0 += buf[3];
|
||||
ctx->c1 += ctx->c0 += buf[2];
|
||||
ctx->c1 += ctx->c0 += buf[1];
|
||||
ctx->c1 += ctx->c0 += buf[0];
|
||||
buf += 4;
|
||||
#endif
|
||||
}
|
||||
|
||||
ctx->c0 %= 255;
|
||||
ctx->c1 %= 255;
|
||||
|
||||
} while (len);
|
||||
}
|
||||
|
||||
/**
|
||||
* fletcher16_final - compute final Fletcher-16 checksum value
|
||||
* @ctx: the context
|
||||
* @len: total data length
|
||||
* @pos: offset in data where the checksum will be stored
|
||||
*
|
||||
* fletcher16_final() computes the final checksum value and returns it.
|
||||
* The caller is responsible for storing it in the appropriate position.
|
||||
* The checksum value depends on @len and @pos, but only their difference
|
||||
* (i.e. the offset from the end) is significant.
|
||||
*
|
||||
* The checksum value is represented as u16, although it is defined as two
|
||||
* consecutive bytes. We treat them as one u16 in big endian / network order.
|
||||
* I.e., the returned value is in the form that would be returned by get_u16()
|
||||
* from the checksum field in the data buffer, therefore the caller should use
|
||||
* put_u16() or an explicit host-to-network conversion when storing it to the
|
||||
* checksum field in the data buffer.
|
||||
*
|
||||
* Note that the returned checksum value is always nonzero.
|
||||
*/
|
||||
static inline u16
|
||||
fletcher16_final(struct fletcher16_context *ctx, int len, int pos)
|
||||
{
|
||||
int x = ((len - pos - 1) * ctx->c0 - ctx->c1) % 255;
|
||||
if (x <= 0)
|
||||
x += 255;
|
||||
|
||||
int y = 510 - ctx->c0 - x;
|
||||
if (y > 255)
|
||||
y -= 255;
|
||||
|
||||
return (x << 8) | y;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* fletcher16_compute - compute Fletcher-16 sum for verification
|
||||
* @ctx: the context
|
||||
*
|
||||
* fletcher16_compute() returns a passing Fletcher-16 sum for processed data.
|
||||
* If the data contains the proper Fletcher-16 checksum value, the returned
|
||||
* value is zero.
|
||||
*/
|
||||
static inline u16
|
||||
fletcher16_compute(struct fletcher16_context *ctx)
|
||||
{
|
||||
return (ctx->c0 << 8) | ctx->c1;
|
||||
}
|
||||
|
||||
#endif
|
180
lib/fletcher16_test.c
Normal file
180
lib/fletcher16_test.c
Normal file
@ -0,0 +1,180 @@
|
||||
/*
|
||||
* BIRD Library -- Fletcher-16 Tests
|
||||
*
|
||||
* (c) 2015 CZ.NIC z.s.p.o.
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#include "test/birdtest.h"
|
||||
#include "lib/fletcher16.h"
|
||||
|
||||
static u16
|
||||
straightforward_fletcher16_compute(const char *data)
|
||||
{
|
||||
int count = strlen(data);
|
||||
|
||||
u16 sum1 = 0;
|
||||
u16 sum2 = 0;
|
||||
int index;
|
||||
|
||||
for (index = 0; index < count; ++index)
|
||||
{
|
||||
sum1 = (sum1 + data[index]) % 255;
|
||||
sum2 = (sum2 + sum1) % 255;
|
||||
}
|
||||
|
||||
sum2 = (sum2 + sum1) % 255;
|
||||
sum2 = (sum2 + sum1) % 255;
|
||||
|
||||
return (sum1 << 8) | sum2;
|
||||
}
|
||||
|
||||
static u16
|
||||
straightforward_fletcher16_checksum(const char *data)
|
||||
{
|
||||
u16 csum;
|
||||
u16 c0,c1,x,y;
|
||||
|
||||
csum = straightforward_fletcher16_compute(data);
|
||||
c0 = (csum >> 8) & 0xff;
|
||||
c1 = csum & 0xff;
|
||||
|
||||
x = (255 + c0 - c1) % 255;
|
||||
y = (510 - 2*c0 + c1) % 255;
|
||||
|
||||
if (!x) x = 255;
|
||||
if (!y) y = 255;
|
||||
|
||||
return (x << 8) | y;
|
||||
}
|
||||
|
||||
const u8 zero16[2] = {};
|
||||
|
||||
static int
|
||||
test_fletcher16(void *out_, const void *in_, const void *expected_out_)
|
||||
{
|
||||
u16 *out = out_;
|
||||
const char *in = in_;
|
||||
const u16 *expected_out = expected_out_;
|
||||
|
||||
struct fletcher16_context ctxt;
|
||||
|
||||
fletcher16_init(&ctxt);
|
||||
fletcher16_update(&ctxt, in, strlen(in));
|
||||
fletcher16_update(&ctxt, zero16, 2);
|
||||
*out = fletcher16_compute(&ctxt);
|
||||
|
||||
return *out == *expected_out;
|
||||
}
|
||||
|
||||
static int
|
||||
test_fletcher16_checksum(void *out_, const void *in_, const void *expected_out_)
|
||||
{
|
||||
u16 *out = out_;
|
||||
const char *in = in_;
|
||||
const u16 *expected_out = expected_out_;
|
||||
|
||||
struct fletcher16_context ctxt;
|
||||
int len = strlen(in);
|
||||
|
||||
fletcher16_init(&ctxt);
|
||||
fletcher16_update(&ctxt, in, len);
|
||||
fletcher16_update(&ctxt, zero16, 2);
|
||||
*out = fletcher16_final(&ctxt, len+2, len);
|
||||
|
||||
return *out == *expected_out;
|
||||
}
|
||||
|
||||
static int
|
||||
t_fletcher16_compute(void)
|
||||
{
|
||||
struct bt_pair test_vectors[] = {
|
||||
{
|
||||
.in = "\001\002",
|
||||
.out = & ((const u16) { straightforward_fletcher16_compute("\001\002") }),
|
||||
},
|
||||
{
|
||||
.in = "",
|
||||
.out = & ((const u16) { straightforward_fletcher16_compute("") }),
|
||||
},
|
||||
{
|
||||
.in = "a",
|
||||
.out = & ((const u16) { straightforward_fletcher16_compute("a") }),
|
||||
},
|
||||
{
|
||||
.in = "abcd",
|
||||
.out = & ((const u16) { straightforward_fletcher16_compute("abcd") }),
|
||||
},
|
||||
{
|
||||
.in = "message digest",
|
||||
.out = & ((const u16) { straightforward_fletcher16_compute("message digest") }),
|
||||
},
|
||||
{
|
||||
.in = "abcdefghijklmnopqrstuvwxyz",
|
||||
.out = & ((const u16) { straightforward_fletcher16_compute("abcdefghijklmnopqrstuvwxyz") }),
|
||||
},
|
||||
{
|
||||
.in = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
||||
.out = & ((const u16) { straightforward_fletcher16_compute("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") }),
|
||||
},
|
||||
{
|
||||
.in = "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
|
||||
.out = & ((const u16) { straightforward_fletcher16_compute("12345678901234567890123456789012345678901234567890123456789012345678901234567890") }),
|
||||
},
|
||||
};
|
||||
|
||||
return bt_assert_batch(test_vectors, test_fletcher16, bt_fmt_str, bt_fmt_unsigned);
|
||||
}
|
||||
|
||||
static int
|
||||
t_fletcher16_checksum(void)
|
||||
{
|
||||
struct bt_pair test_vectors[] = {
|
||||
{
|
||||
.in = "\001\002",
|
||||
.out = & ((const u16) { straightforward_fletcher16_checksum("\001\002") }),
|
||||
},
|
||||
{
|
||||
.in = "",
|
||||
.out = & ((const u16) { straightforward_fletcher16_checksum("") }),
|
||||
},
|
||||
{
|
||||
.in = "a",
|
||||
.out = & ((const u16) { straightforward_fletcher16_checksum("a") }),
|
||||
},
|
||||
{
|
||||
.in = "abcd",
|
||||
.out = & ((const u16) { straightforward_fletcher16_checksum("abcd") }),
|
||||
},
|
||||
{
|
||||
.in = "message digest",
|
||||
.out = & ((const u16) { straightforward_fletcher16_checksum("message digest") }),
|
||||
},
|
||||
{
|
||||
.in = "abcdefghijklmnopqrstuvwxyz",
|
||||
.out = & ((const u16) { straightforward_fletcher16_checksum("abcdefghijklmnopqrstuvwxyz") }),
|
||||
},
|
||||
{
|
||||
.in = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
||||
.out = & ((const u16) { straightforward_fletcher16_checksum("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") }),
|
||||
},
|
||||
{
|
||||
.in = "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
|
||||
.out = & ((const u16) { straightforward_fletcher16_checksum("12345678901234567890123456789012345678901234567890123456789012345678901234567890") }),
|
||||
},
|
||||
};
|
||||
|
||||
return bt_assert_batch(test_vectors, test_fletcher16_checksum, bt_fmt_str, bt_fmt_unsigned);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
bt_init(argc, argv);
|
||||
|
||||
bt_test_suite(t_fletcher16_compute, "Fletcher-16 Compute Tests");
|
||||
bt_test_suite(t_fletcher16_checksum, "Fletcher-16 Checksum Tests");
|
||||
|
||||
return bt_exit_value();
|
||||
}
|
1211
lib/flowspec.c
Normal file
1211
lib/flowspec.c
Normal file
File diff suppressed because it is too large
Load Diff
163
lib/flowspec.h
Normal file
163
lib/flowspec.h
Normal file
@ -0,0 +1,163 @@
|
||||
/*
|
||||
* BIRD Library -- Flow specification (RFC 5575)
|
||||
*
|
||||
* (c) 2016 CZ.NIC z.s.p.o.
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#ifndef _BIRD_FLOWSPEC_H_
|
||||
#define _BIRD_FLOWSPEC_H_
|
||||
|
||||
#include "nest/bird.h"
|
||||
#include "lib/buffer.h"
|
||||
#include "lib/net.h"
|
||||
|
||||
|
||||
/* Flow component operators */
|
||||
#define FLOW_OP_TRUE 0x00 /* 0b000 */
|
||||
#define FLOW_OP_EQ 0x01 /* 0b001 */
|
||||
#define FLOW_OP_GT 0x02 /* 0b010 */
|
||||
#define FLOW_OP_GEQ 0x03 /* 0b011 */
|
||||
#define FLOW_OP_LT 0x04 /* 0b100 */
|
||||
#define FLOW_OP_LEQ 0x05 /* 0b101 */
|
||||
#define FLOW_OP_NEQ 0x06 /* 0b110 */
|
||||
#define FLOW_OP_FALSE 0x07 /* 0b111 */
|
||||
|
||||
#define FLOW_OP_OR 0x00
|
||||
#define FLOW_OP_AND 0x40
|
||||
|
||||
|
||||
/* Types of components in flowspec */
|
||||
enum flow_type {
|
||||
FLOW_TYPE_DST_PREFIX = 1,
|
||||
FLOW_TYPE_SRC_PREFIX = 2,
|
||||
FLOW_TYPE_IP_PROTOCOL = 3,
|
||||
FLOW_TYPE_NEXT_HEADER = 3, /* IPv6 */
|
||||
FLOW_TYPE_PORT = 4,
|
||||
FLOW_TYPE_DST_PORT = 5,
|
||||
FLOW_TYPE_SRC_PORT = 6,
|
||||
FLOW_TYPE_ICMP_TYPE = 7,
|
||||
FLOW_TYPE_ICMP_CODE = 8,
|
||||
FLOW_TYPE_TCP_FLAGS = 9,
|
||||
FLOW_TYPE_PACKET_LENGTH = 10,
|
||||
FLOW_TYPE_DSCP = 11, /* DiffServ Code Point */
|
||||
FLOW_TYPE_FRAGMENT = 12,
|
||||
FLOW_TYPE_LABEL = 13, /* IPv6 */
|
||||
FLOW_TYPE_MAX
|
||||
};
|
||||
|
||||
const char *flow_type_str(enum flow_type type, int ipv6);
|
||||
|
||||
|
||||
/*
|
||||
* Length
|
||||
*/
|
||||
|
||||
uint flow_write_length(byte *data, u16 len);
|
||||
|
||||
static inline u16 flow_hdr_length(const byte *data)
|
||||
{ return ((*data & 0xf0) == 0xf0) ? 2 : 1; }
|
||||
|
||||
static inline u16 flow_read_length(const byte *data)
|
||||
{ return ((*data & 0xf0) == 0xf0) ? get_u16(data) & 0x0fff : *data; }
|
||||
|
||||
static inline u16 flow4_get_length(const net_addr_flow4 *f)
|
||||
{ return f->length - sizeof(net_addr_flow4); }
|
||||
|
||||
static inline u16 flow6_get_length(const net_addr_flow6 *f)
|
||||
{ return f->length - sizeof(net_addr_flow6); }
|
||||
|
||||
static inline void flow4_set_length(net_addr_flow4 *f, u16 len)
|
||||
{ f->length = sizeof(net_addr_flow4) + flow_write_length(f->data, len) + len; }
|
||||
|
||||
static inline void flow6_set_length(net_addr_flow6 *f, u16 len)
|
||||
{ f->length = sizeof(net_addr_flow6) + flow_write_length(f->data, len) + len; }
|
||||
|
||||
|
||||
/*
|
||||
* Iterators
|
||||
*/
|
||||
|
||||
const byte *flow4_first_part(const net_addr_flow4 *f);
|
||||
const byte *flow6_first_part(const net_addr_flow6 *f);
|
||||
const byte *flow4_next_part(const byte *pos, const byte *end);
|
||||
const byte *flow6_next_part(const byte *pos, const byte *end);
|
||||
const byte *flow4_get_part(const net_addr_flow4 *f, uint type);
|
||||
const byte *flow6_get_part(const net_addr_flow6 *f, uint type);
|
||||
|
||||
|
||||
/*
|
||||
* Flowspec accessors
|
||||
*/
|
||||
|
||||
ip4_addr flow_read_ip4_part(const byte *part);
|
||||
ip6_addr flow_read_ip6_part(const byte *part);
|
||||
static inline int flow_read_pxlen(const byte *part) { return part[1]; }
|
||||
|
||||
|
||||
/*
|
||||
* Flowspec Builder
|
||||
*/
|
||||
|
||||
/* A data structure for keep a state of flow builder */
|
||||
struct flow_builder {
|
||||
BUFFER_(byte) data;
|
||||
enum flow_type this_type;
|
||||
enum flow_type last_type;
|
||||
u16 last_op_offset; /* Position of last operator in data.data */
|
||||
int ipv6;
|
||||
struct {
|
||||
u16 offset; /* Beginning of a component */
|
||||
u16 length; /* Length of a component */
|
||||
} parts[FLOW_TYPE_MAX]; /* Indexing all components */
|
||||
};
|
||||
|
||||
struct flow_builder *flow_builder_init(pool *pool);
|
||||
void flow_builder_clear(struct flow_builder *fb);
|
||||
void flow_builder_set_type(struct flow_builder *fb, enum flow_type p);
|
||||
int flow_builder4_add_pfx(struct flow_builder *fb, const net_addr_ip4 *n4);
|
||||
int flow_builder6_add_pfx(struct flow_builder *fb, const net_addr_ip6 *n6, u32 offset);
|
||||
int flow_builder_add_op_val(struct flow_builder *fb, byte op, u32 value);
|
||||
int flow_builder_add_val_mask(struct flow_builder *fb, byte op, u32 value, u32 mask);
|
||||
net_addr_flow4 *flow_builder4_finalize(struct flow_builder *fb, linpool *lpool);
|
||||
net_addr_flow6 *flow_builder6_finalize(struct flow_builder *fb, linpool *lpool);
|
||||
|
||||
|
||||
/*
|
||||
* Validation
|
||||
*/
|
||||
|
||||
/* Results of validation Flow specification */
|
||||
enum flow_validated_state {
|
||||
FLOW_ST_UNKNOWN_COMPONENT,
|
||||
FLOW_ST_VALID,
|
||||
FLOW_ST_NOT_COMPLETE,
|
||||
FLOW_ST_EXCEED_MAX_PREFIX_LENGTH,
|
||||
FLOW_ST_EXCEED_MAX_PREFIX_OFFSET,
|
||||
FLOW_ST_EXCEED_MAX_VALUE_LENGTH,
|
||||
FLOW_ST_BAD_TYPE_ORDER,
|
||||
FLOW_ST_AND_BIT_SHOULD_BE_UNSET,
|
||||
FLOW_ST_ZERO_BIT_SHOULD_BE_UNSED,
|
||||
FLOW_ST_DEST_PREFIX_REQUIRED,
|
||||
FLOW_ST_INVALID_TCP_FLAGS,
|
||||
FLOW_ST_CANNOT_USE_DONT_FRAGMENT
|
||||
};
|
||||
|
||||
const char *flow_validated_state_str(enum flow_validated_state code);
|
||||
enum flow_validated_state flow4_validate(const byte *nlri, uint len);
|
||||
enum flow_validated_state flow6_validate(const byte *nlri, uint len);
|
||||
void flow_check_cf_value_length(struct flow_builder *fb, u32 expr);
|
||||
void flow_check_cf_bmk_values(struct flow_builder *fb, u8 neg, u32 val, u32 mask);
|
||||
void flow4_validate_cf(net_addr_flow4 *f);
|
||||
void flow6_validate_cf(net_addr_flow6 *f);
|
||||
|
||||
|
||||
/*
|
||||
* Net Formatting
|
||||
*/
|
||||
|
||||
uint flow4_net_format(char *buf, uint blen, const net_addr_flow4 *f);
|
||||
uint flow6_net_format(char *buf, uint blen, const net_addr_flow6 *f);
|
||||
|
||||
#endif /* _BIRD_FLOWSPEC_H_ */
|
689
lib/flowspec_test.c
Normal file
689
lib/flowspec_test.c
Normal file
@ -0,0 +1,689 @@
|
||||
/*
|
||||
* BIRD Library -- Flow specification (RFC 5575) Tests
|
||||
*
|
||||
* (c) 2016 CZ.NIC z.s.p.o.
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#include "test/birdtest.h"
|
||||
#include "lib/flowspec.h"
|
||||
|
||||
#define NET_ADDR_FLOW4_(what,prefix,pxlen,data_) \
|
||||
do \
|
||||
{ \
|
||||
what = alloca(sizeof(net_addr_flow4) + 128); \
|
||||
*what = NET_ADDR_FLOW4(prefix, pxlen, sizeof(data_)); \
|
||||
memcpy(what->data, &(data_), sizeof(data_)); \
|
||||
} while(0)
|
||||
|
||||
#define NET_ADDR_FLOW6_(what,prefix,pxlen,data_) \
|
||||
do \
|
||||
{ \
|
||||
what = alloca(sizeof(net_addr_flow6) + 128); \
|
||||
*what = NET_ADDR_FLOW6(prefix, pxlen, sizeof(data_)); \
|
||||
memcpy(what->data, &(data_), sizeof(data_)); \
|
||||
} while(0)
|
||||
|
||||
static int
|
||||
t_read_length(void)
|
||||
{
|
||||
byte data[] = { 0xcc, 0xcc, 0xcc };
|
||||
|
||||
for (uint expect = 0; expect < 0xf0; expect++)
|
||||
{
|
||||
*data = expect;
|
||||
uint get = flow_read_length(data);
|
||||
bt_assert_msg(get == expect, "Testing get length 0x%02x (get 0x%02x)", expect, get);
|
||||
}
|
||||
|
||||
for (uint expect = 0; expect <= 0xfff; expect++)
|
||||
{
|
||||
put_u16(data, expect | 0xf000);
|
||||
uint get = flow_read_length(data);
|
||||
bt_assert_msg(get == expect, "Testing get length 0x%03x (get 0x%03x)", expect, get);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_write_length(void)
|
||||
{
|
||||
byte data[] = { 0xcc, 0xcc, 0xcc };
|
||||
|
||||
for (uint expect = 0; expect <= 0xfff; expect++)
|
||||
{
|
||||
uint offset = flow_write_length(data, expect);
|
||||
|
||||
uint set = (expect < 0xf0) ? *data : (get_u16(data) & 0x0fff);
|
||||
bt_assert_msg(set == expect, "Testing set length 0x%03x (set 0x%03x)", expect, set);
|
||||
bt_assert(offset == (expect < 0xf0 ? 1 : 2));
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_first_part(void)
|
||||
{
|
||||
net_addr_flow4 *f;
|
||||
NET_ADDR_FLOW4_(f, ip4_build(10,0,0,1), 24, ((byte[]) { 0x00, 0x00, 0xab }));
|
||||
|
||||
const byte *under240 = &f->data[1];
|
||||
const byte *above240 = &f->data[2];
|
||||
|
||||
/* Case 0x00 0x00 */
|
||||
bt_assert(flow4_first_part(f) == NULL);
|
||||
|
||||
/* Case 0x01 0x00 */
|
||||
f->data[0] = 0x01;
|
||||
bt_assert(flow4_first_part(f) == under240);
|
||||
|
||||
/* Case 0xef 0x00 */
|
||||
f->data[0] = 0xef;
|
||||
bt_assert(flow4_first_part(f) == under240);
|
||||
|
||||
/* Case 0xf0 0x00 */
|
||||
f->data[0] = 0xf0;
|
||||
bt_assert(flow4_first_part(f) == NULL);
|
||||
|
||||
/* Case 0xf0 0x01 */
|
||||
f->data[1] = 0x01;
|
||||
bt_assert(flow4_first_part(f) == above240);
|
||||
|
||||
/* Case 0xff 0xff */
|
||||
f->data[0] = 0xff;
|
||||
f->data[1] = 0xff;
|
||||
bt_assert(flow4_first_part(f) == above240);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_iterators4(void)
|
||||
{
|
||||
net_addr_flow4 *f;
|
||||
NET_ADDR_FLOW4_(f, ip4_build(5,6,7,0), 24, ((byte[]) {
|
||||
25, /* Length */
|
||||
FLOW_TYPE_DST_PREFIX, 24, 5, 6, 7,
|
||||
FLOW_TYPE_SRC_PREFIX, 32, 10, 11, 12, 13,
|
||||
FLOW_TYPE_IP_PROTOCOL, 0x81, 0x06,
|
||||
FLOW_TYPE_PORT, 0x03, 0x89, 0x45, 0x8b, 0x91, 0x1f, 0x90,
|
||||
FLOW_TYPE_TCP_FLAGS, 0x80, 0x55,
|
||||
}));
|
||||
|
||||
const byte *start = f->data;
|
||||
const byte *p1_dst_pfx = &f->data[1];
|
||||
const byte *p2_src_pfx = &f->data[6];
|
||||
const byte *p3_ip_proto = &f->data[12];
|
||||
const byte *p4_port = &f->data[15];
|
||||
const byte *p5_tcp_flags = &f->data[23];
|
||||
const byte *end = &f->data[25];
|
||||
|
||||
bt_assert(flow_read_length(f->data) == (end-start));
|
||||
bt_assert(flow4_first_part(f) == p1_dst_pfx);
|
||||
|
||||
bt_assert(flow4_next_part(p1_dst_pfx, end) == p2_src_pfx);
|
||||
bt_assert(flow4_next_part(p2_src_pfx, end) == p3_ip_proto);
|
||||
bt_assert(flow4_next_part(p3_ip_proto, end) == p4_port);
|
||||
bt_assert(flow4_next_part(p4_port, end) == p5_tcp_flags);
|
||||
bt_assert(flow4_next_part(p5_tcp_flags, end) == NULL);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_iterators6(void)
|
||||
{
|
||||
net_addr_flow6 *f;
|
||||
NET_ADDR_FLOW6_(f, ip6_build(0,0,0x12345678,0x9a000000), 0x68, ((byte[]) {
|
||||
26, /* Length */
|
||||
FLOW_TYPE_DST_PREFIX, 0x68, 0x40, 0x12, 0x34, 0x56, 0x78, 0x9a,
|
||||
FLOW_TYPE_SRC_PREFIX, 0x08, 0x0, 0xc0,
|
||||
FLOW_TYPE_NEXT_HEADER, 0x81, 0x06,
|
||||
FLOW_TYPE_PORT, 0x03, 0x89, 0x45, 0x8b, 0x91, 0x1f, 0x90,
|
||||
FLOW_TYPE_LABEL, 0x80, 0x55,
|
||||
}));
|
||||
|
||||
const byte *start = f->data;
|
||||
const byte *p1_dst_pfx = &f->data[1];
|
||||
const byte *p2_src_pfx = &f->data[9];
|
||||
const byte *p3_next_header = &f->data[13];
|
||||
const byte *p4_port = &f->data[16];
|
||||
const byte *p5_label = &f->data[24];
|
||||
const byte *end = &f->data[26];
|
||||
|
||||
bt_assert(flow_read_length(f->data) == (end-start));
|
||||
bt_assert(flow6_first_part(f) == p1_dst_pfx);
|
||||
|
||||
bt_assert(flow6_next_part(p1_dst_pfx, end) == p2_src_pfx);
|
||||
bt_assert(flow6_next_part(p2_src_pfx, end) == p3_next_header);
|
||||
bt_assert(flow6_next_part(p3_next_header, end) == p4_port);
|
||||
bt_assert(flow6_next_part(p4_port, end) == p5_label);
|
||||
bt_assert(flow6_next_part(p5_label, end) == NULL);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_accessors4(void)
|
||||
{
|
||||
net_addr_flow4 *f;
|
||||
NET_ADDR_FLOW4_(f, ip4_build(5,6,7,0), 24, ((byte[]) {
|
||||
25, /* Length */
|
||||
FLOW_TYPE_DST_PREFIX, 24, 5, 6, 7,
|
||||
FLOW_TYPE_SRC_PREFIX, 32, 10, 11, 12, 13,
|
||||
FLOW_TYPE_IP_PROTOCOL, 0x81, 0x06,
|
||||
FLOW_TYPE_PORT, 0x03, 0x89, 0x45, 0x8b, 0x91, 0x1f, 0x90,
|
||||
FLOW_TYPE_TCP_FLAGS, 0x80, 0x55,
|
||||
}));
|
||||
|
||||
const byte *p1_dst_px = &f->data[1];
|
||||
const ip4_addr p1_dst_addr = ip4_build(5,6,7,0);
|
||||
|
||||
const byte *p2_src_px = &f->data[6];
|
||||
const ip4_addr p2_src_addr = ip4_build(10,11,12,13);
|
||||
|
||||
bt_assert(ip4_equal(flow_read_ip4_part(p1_dst_px), p1_dst_addr));
|
||||
bt_assert(ip4_equal(flow_read_ip4_part(p2_src_px), p2_src_addr));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_accessors6(void)
|
||||
{
|
||||
net_addr_flow6 *f;
|
||||
NET_ADDR_FLOW6_(f, ip6_build(0,0,0x12345678,0x9a000000), 0x68, ((byte[]) {
|
||||
26, /* Length */
|
||||
FLOW_TYPE_DST_PREFIX, 0x68, 0x40, 0x12, 0x34, 0x56, 0x78, 0x9a,
|
||||
FLOW_TYPE_SRC_PREFIX, 0x08, 0x0, 0xc0,
|
||||
FLOW_TYPE_NEXT_HEADER, 0x81, 0x06,
|
||||
FLOW_TYPE_PORT, 0x03, 0x89, 0x45, 0x8b, 0x91, 0x1f, 0x90,
|
||||
FLOW_TYPE_LABEL, 0x80, 0x55,
|
||||
}));
|
||||
|
||||
const byte *p1_dst_px = &f->data[1];
|
||||
const ip6_addr p1_dst_addr = ip6_build(0,0,0x12345678,0x9a000000);
|
||||
|
||||
const byte *p2_src_px = &f->data[9];
|
||||
const ip6_addr p2_src_addr = ip6_build(0xc0000000, 0, 0, 0);
|
||||
|
||||
bt_assert(ip6_equal(flow_read_ip6_part(p1_dst_px), p1_dst_addr));
|
||||
bt_assert(ip6_equal(flow_read_ip6_part(p2_src_px), p2_src_addr));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_validation4(void)
|
||||
{
|
||||
enum flow_validated_state res;
|
||||
|
||||
byte nlri1[] = {
|
||||
FLOW_TYPE_DST_PREFIX, 24, 5, 6, 7,
|
||||
FLOW_TYPE_SRC_PREFIX, 32, 10, 11, 12, 13,
|
||||
FLOW_TYPE_IP_PROTOCOL, 0x81, 0x06,
|
||||
FLOW_TYPE_PORT, 0x03, 0x89, 0x45, 0x8b, 0x91, 0x1f, 0x90,
|
||||
FLOW_TYPE_TCP_FLAGS, 0x80, 0x55,
|
||||
};
|
||||
|
||||
/* Empty NLRI */
|
||||
res = flow4_validate(nlri1, 0);
|
||||
bt_assert(res == FLOW_ST_VALID);
|
||||
|
||||
/* Valid / Not Complete testing */
|
||||
uint valid_sizes[] = {5, 11, 14, 22, 25, 0};
|
||||
uint valid_idx = 0;
|
||||
for (uint size = 1; size <= sizeof(nlri1); size++)
|
||||
{
|
||||
res = flow4_validate(nlri1, size);
|
||||
bt_debug("size %u, result: %s\n", size, flow_validated_state_str(res));
|
||||
if (size == valid_sizes[valid_idx])
|
||||
{
|
||||
valid_idx++;
|
||||
bt_assert(res == FLOW_ST_VALID);
|
||||
}
|
||||
else
|
||||
{
|
||||
bt_assert(res == FLOW_ST_NOT_COMPLETE);
|
||||
}
|
||||
}
|
||||
|
||||
/* Misc err tests */
|
||||
|
||||
struct tset {
|
||||
enum flow_validated_state expect;
|
||||
char *description;
|
||||
u16 size;
|
||||
byte *nlri;
|
||||
};
|
||||
|
||||
#define TS(type, msg, data) ((struct tset) {type, msg, sizeof(data), (data)})
|
||||
struct tset tset[] = {
|
||||
TS(
|
||||
FLOW_ST_EXCEED_MAX_PREFIX_LENGTH,
|
||||
"33-length IPv4 prefix",
|
||||
((byte []) {
|
||||
FLOW_TYPE_DST_PREFIX, 33, 5, 6, 7, 8, 9
|
||||
})
|
||||
),
|
||||
TS(
|
||||
FLOW_ST_BAD_TYPE_ORDER,
|
||||
"Bad flowspec component type order",
|
||||
((byte []) {
|
||||
FLOW_TYPE_SRC_PREFIX, 32, 10, 11, 12, 13,
|
||||
FLOW_TYPE_DST_PREFIX, 24, 5, 6, 7,
|
||||
})
|
||||
),
|
||||
TS(
|
||||
FLOW_ST_BAD_TYPE_ORDER,
|
||||
"Doubled destination prefix component",
|
||||
((byte []) {
|
||||
FLOW_TYPE_DST_PREFIX, 24, 5, 6, 7,
|
||||
FLOW_TYPE_DST_PREFIX, 24, 5, 6, 7,
|
||||
})
|
||||
),
|
||||
TS(
|
||||
FLOW_ST_AND_BIT_SHOULD_BE_UNSET,
|
||||
"The first numeric operator has set the AND bit",
|
||||
((byte []) {
|
||||
FLOW_TYPE_PORT, 0x43, 0x89, 0x45, 0x8b, 0x91, 0x1f, 0x90,
|
||||
})
|
||||
),
|
||||
TS(
|
||||
FLOW_ST_ZERO_BIT_SHOULD_BE_UNSED,
|
||||
"Set zero bit in operand to one",
|
||||
((byte []) {
|
||||
FLOW_TYPE_IP_PROTOCOL, 0x89, 0x06,
|
||||
})
|
||||
),
|
||||
TS(
|
||||
FLOW_ST_UNKNOWN_COMPONENT,
|
||||
"Unknown component of type number 13",
|
||||
((byte []) {
|
||||
FLOW_TYPE_DST_PREFIX, 24, 5, 6, 7,
|
||||
FLOW_TYPE_TCP_FLAGS, 0x80, 0x55,
|
||||
13 /*something new*/, 0x80, 0x55,
|
||||
})
|
||||
),
|
||||
};
|
||||
#undef TS
|
||||
|
||||
for (uint tcase = 0; tcase < ARRAY_SIZE(tset); tcase++)
|
||||
{
|
||||
res = flow4_validate(tset[tcase].nlri, tset[tcase].size);
|
||||
bt_assert_msg(res == tset[tcase].expect, "Assertion (%s == %s) %s", flow_validated_state_str(res), flow_validated_state_str(tset[tcase].expect), tset[tcase].description);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_validation6(void)
|
||||
{
|
||||
enum flow_validated_state res;
|
||||
|
||||
byte nlri1[] = {
|
||||
FLOW_TYPE_DST_PREFIX, 103, 61, 0x01, 0x12, 0x34, 0x56, 0x78, 0x98,
|
||||
FLOW_TYPE_SRC_PREFIX, 8, 0, 0xc0,
|
||||
FLOW_TYPE_NEXT_HEADER, 0x81, 0x06,
|
||||
FLOW_TYPE_PORT, 0x03, 0x89, 0x45, 0x8b, 0x91, 0x1f, 0x90,
|
||||
FLOW_TYPE_LABEL, 0x80, 0x55,
|
||||
};
|
||||
|
||||
/* Isn't included destination prefix */
|
||||
res = flow6_validate(nlri1, 0);
|
||||
bt_assert(res == FLOW_ST_VALID);
|
||||
|
||||
/* Valid / Not Complete testing */
|
||||
uint valid_sizes[] = {0, 9, 13, 16, 24, 27, 0};
|
||||
uint valid_idx = 0;
|
||||
for (uint size = 0; size <= sizeof(nlri1); size++)
|
||||
{
|
||||
res = flow6_validate(nlri1, size);
|
||||
bt_debug("size %u, result: %s\n", size, flow_validated_state_str(res));
|
||||
if (size == valid_sizes[valid_idx])
|
||||
{
|
||||
valid_idx++;
|
||||
bt_assert(res == FLOW_ST_VALID);
|
||||
}
|
||||
else
|
||||
{
|
||||
bt_assert(res == FLOW_ST_NOT_COMPLETE);
|
||||
}
|
||||
}
|
||||
|
||||
/* Misc err tests */
|
||||
|
||||
struct tset {
|
||||
enum flow_validated_state expect;
|
||||
char *description;
|
||||
u16 size;
|
||||
byte *nlri;
|
||||
};
|
||||
|
||||
#define TS(type, msg, data) ((struct tset) {type, msg, sizeof(data), (data)})
|
||||
struct tset tset[] = {
|
||||
TS(
|
||||
FLOW_ST_EXCEED_MAX_PREFIX_LENGTH,
|
||||
"129-length IPv6 prefix",
|
||||
((byte []) {
|
||||
FLOW_TYPE_DST_PREFIX, 129, 64, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12
|
||||
})
|
||||
),
|
||||
TS(
|
||||
FLOW_ST_EXCEED_MAX_PREFIX_OFFSET,
|
||||
"Prefix offset is higher than prefix length",
|
||||
((byte []) {
|
||||
FLOW_TYPE_DST_PREFIX, 48, 64, 0x40, 0x12, 0x34
|
||||
})
|
||||
),
|
||||
TS(
|
||||
FLOW_ST_BAD_TYPE_ORDER,
|
||||
"Bad flowspec component type order",
|
||||
((byte []) {
|
||||
FLOW_TYPE_NEXT_HEADER, 0x81, 0x06,
|
||||
FLOW_TYPE_SRC_PREFIX, 8, 0, 0xc0,
|
||||
})
|
||||
),
|
||||
TS(
|
||||
FLOW_ST_BAD_TYPE_ORDER,
|
||||
"Doubled destination prefix component",
|
||||
((byte []) {
|
||||
FLOW_TYPE_DST_PREFIX, 103, 61, 0x01, 0x12, 0x34, 0x56, 0x78, 0x98,
|
||||
FLOW_TYPE_DST_PREFIX, 103, 61, 0x01, 0x12, 0x34, 0x56, 0x78, 0x98,
|
||||
})
|
||||
),
|
||||
TS(
|
||||
FLOW_ST_AND_BIT_SHOULD_BE_UNSET,
|
||||
"The first numeric operator has set the AND bit",
|
||||
((byte []) {
|
||||
FLOW_TYPE_PORT, 0x43, 0x89, 0x45, 0x8b, 0x91, 0x1f, 0x90
|
||||
})
|
||||
),
|
||||
TS(
|
||||
FLOW_ST_ZERO_BIT_SHOULD_BE_UNSED,
|
||||
"Set zero bit in operand to one",
|
||||
((byte []) {
|
||||
FLOW_TYPE_NEXT_HEADER, 0x89, 0x06
|
||||
})
|
||||
),
|
||||
TS(
|
||||
FLOW_ST_VALID,
|
||||
"Component of type number 13 (Label) is well-known in IPv6",
|
||||
((byte []) {
|
||||
FLOW_TYPE_LABEL, 0x80, 0x55
|
||||
})
|
||||
),
|
||||
TS(
|
||||
FLOW_ST_UNKNOWN_COMPONENT,
|
||||
"Unknown component of type number 14",
|
||||
((byte []) {
|
||||
FLOW_TYPE_LABEL, 0x80, 0x55,
|
||||
14 /*something new*/, 0x80, 0x55,
|
||||
})
|
||||
)
|
||||
};
|
||||
#undef TS
|
||||
|
||||
for (uint tcase = 0; tcase < ARRAY_SIZE(tset); tcase++)
|
||||
{
|
||||
res = flow6_validate(tset[tcase].nlri, tset[tcase].size);
|
||||
bt_assert_msg(res == tset[tcase].expect, "Assertion (%s == %s) %s", flow_validated_state_str(res), flow_validated_state_str(tset[tcase].expect), tset[tcase].description);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Builder tests
|
||||
*/
|
||||
|
||||
static int
|
||||
t_builder4(void)
|
||||
{
|
||||
resource_init();
|
||||
|
||||
struct flow_builder *fb = flow_builder_init(&root_pool);
|
||||
linpool *lp = lp_new_default(&root_pool);
|
||||
|
||||
/* Expectation */
|
||||
|
||||
static byte nlri[] = {
|
||||
25,
|
||||
FLOW_TYPE_DST_PREFIX, 24, 5, 6, 7,
|
||||
FLOW_TYPE_SRC_PREFIX, 32, 10, 11, 12, 13,
|
||||
FLOW_TYPE_IP_PROTOCOL, 0x80, 0x06,
|
||||
FLOW_TYPE_PORT, 0x03, 0x89, 0x45, 0x8b, 0x91, 0x1f, 0x90,
|
||||
FLOW_TYPE_TCP_FLAGS, 0x80, 0x55
|
||||
};
|
||||
|
||||
net_addr_flow4 *expect;
|
||||
NET_ADDR_FLOW4_(expect, ip4_build(5, 6, 7, 0), 24, nlri);
|
||||
|
||||
/* Normal order */
|
||||
|
||||
net_addr_ip4 n1;
|
||||
net_fill_ip4((net_addr *) &n1, ip4_build(5,6,7,0), 24);
|
||||
flow_builder_set_type(fb, FLOW_TYPE_DST_PREFIX);
|
||||
flow_builder4_add_pfx(fb, &n1);
|
||||
|
||||
net_addr_ip4 n2;
|
||||
net_fill_ip4((net_addr *) &n2, ip4_build(10,11,12,13), 32);
|
||||
flow_builder_set_type(fb, FLOW_TYPE_SRC_PREFIX);
|
||||
flow_builder4_add_pfx(fb, &n2);
|
||||
|
||||
flow_builder_set_type(fb, FLOW_TYPE_IP_PROTOCOL);
|
||||
flow_builder_add_op_val(fb, 0, 0x06);
|
||||
|
||||
flow_builder_set_type(fb, FLOW_TYPE_PORT);
|
||||
flow_builder_add_op_val(fb, 0x03, 0x89);
|
||||
flow_builder_add_op_val(fb, 0x45, 0x8b);
|
||||
flow_builder_add_op_val(fb, 0x01, 0x1f90);
|
||||
|
||||
/* Try put a component twice time */
|
||||
flow_builder_set_type(fb, FLOW_TYPE_IP_PROTOCOL);
|
||||
flow_builder_add_op_val(fb, 0, 0x06);
|
||||
|
||||
flow_builder_set_type(fb, FLOW_TYPE_TCP_FLAGS);
|
||||
flow_builder_add_op_val(fb, 0, 0x55);
|
||||
|
||||
net_addr_flow4 *res = flow_builder4_finalize(fb, lp);
|
||||
|
||||
bt_assert(memcmp(res, expect, expect->length) == 0);
|
||||
|
||||
/* Reverse order */
|
||||
|
||||
flow_builder_clear(fb);
|
||||
|
||||
flow_builder_set_type(fb, FLOW_TYPE_TCP_FLAGS);
|
||||
flow_builder_add_op_val(fb, 0, 0x55);
|
||||
|
||||
flow_builder_set_type(fb, FLOW_TYPE_PORT);
|
||||
flow_builder_add_op_val(fb, 0x03, 0x89);
|
||||
flow_builder_add_op_val(fb, 0x45, 0x8b);
|
||||
flow_builder_add_op_val(fb, 0x01, 0x1f90);
|
||||
|
||||
flow_builder_set_type(fb, FLOW_TYPE_IP_PROTOCOL);
|
||||
flow_builder_add_op_val(fb, 0, 0x06);
|
||||
|
||||
net_fill_ip4((net_addr *) &n2, ip4_build(10,11,12,13), 32);
|
||||
flow_builder_set_type(fb, FLOW_TYPE_SRC_PREFIX);
|
||||
flow_builder4_add_pfx(fb, &n2);
|
||||
|
||||
net_fill_ip4((net_addr *) &n1, ip4_build(5,6,7,0), 24);
|
||||
flow_builder_set_type(fb, FLOW_TYPE_DST_PREFIX);
|
||||
flow_builder4_add_pfx(fb, &n1);
|
||||
|
||||
bt_assert(memcmp(res, expect, expect->length) == 0);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_builder6(void)
|
||||
{
|
||||
net_addr_ip6 ip;
|
||||
|
||||
resource_init();
|
||||
linpool *lp = lp_new_default(&root_pool);
|
||||
struct flow_builder *fb = flow_builder_init(&root_pool);
|
||||
fb->ipv6 = 1;
|
||||
|
||||
/* Expectation */
|
||||
|
||||
byte nlri[] = {
|
||||
27,
|
||||
FLOW_TYPE_DST_PREFIX, 103, 61, 0x01, 0x12, 0x34, 0x56, 0x78, 0x98,
|
||||
FLOW_TYPE_SRC_PREFIX, 8, 0, 0xc0,
|
||||
FLOW_TYPE_NEXT_HEADER, 0x80, 0x06,
|
||||
FLOW_TYPE_PORT, 0x03, 0x89, 0x45, 0x8b, 0x91, 0x1f, 0x90,
|
||||
FLOW_TYPE_LABEL, 0x80, 0x55,
|
||||
};
|
||||
|
||||
net_addr_flow6 *expect;
|
||||
NET_ADDR_FLOW6_(expect, ip6_build(0, 1, 0x12345678, 0x98000000), 103, nlri);
|
||||
|
||||
/* Normal order */
|
||||
|
||||
net_fill_ip6((net_addr *) &ip, ip6_build(0, 1, 0x12345678, 0x98000000), 103);
|
||||
flow_builder_set_type(fb, FLOW_TYPE_DST_PREFIX);
|
||||
flow_builder6_add_pfx(fb, &ip, 61);
|
||||
|
||||
/* Try put a component twice time */
|
||||
net_fill_ip6((net_addr *) &ip, ip6_build(0, 1, 0x12345678, 0x98000000), 103);
|
||||
flow_builder_set_type(fb, FLOW_TYPE_DST_PREFIX);
|
||||
bt_assert(flow_builder6_add_pfx(fb, &ip, 61) == 0);
|
||||
|
||||
net_fill_ip6((net_addr *) &ip, ip6_build(0xc0000000,0,0,0), 8);
|
||||
flow_builder_set_type(fb, FLOW_TYPE_SRC_PREFIX);
|
||||
flow_builder6_add_pfx(fb, &ip, 0);
|
||||
|
||||
flow_builder_set_type(fb, FLOW_TYPE_NEXT_HEADER);
|
||||
flow_builder_add_op_val(fb, 0, 0x06);
|
||||
|
||||
flow_builder_set_type(fb, FLOW_TYPE_PORT);
|
||||
flow_builder_add_op_val(fb, 0x03, 0x89);
|
||||
flow_builder_add_op_val(fb, 0x45, 0x8b);
|
||||
flow_builder_add_op_val(fb, 0x01, 0x1f90);
|
||||
|
||||
flow_builder_set_type(fb, FLOW_TYPE_LABEL);
|
||||
flow_builder_add_op_val(fb, 0, 0x55);
|
||||
|
||||
net_addr_flow6 *res = flow_builder6_finalize(fb, lp);
|
||||
bt_assert(memcmp(res, expect, expect->length) == 0);
|
||||
|
||||
/* Reverse order */
|
||||
|
||||
flow_builder_clear(fb);
|
||||
fb->ipv6 = 1;
|
||||
|
||||
flow_builder_set_type(fb, FLOW_TYPE_LABEL);
|
||||
flow_builder_add_op_val(fb, 0, 0x55);
|
||||
|
||||
flow_builder_set_type(fb, FLOW_TYPE_PORT);
|
||||
flow_builder_add_op_val(fb, 0x03, 0x89);
|
||||
flow_builder_add_op_val(fb, 0x45, 0x8b);
|
||||
flow_builder_add_op_val(fb, 0x01, 0x1f90);
|
||||
|
||||
flow_builder_set_type(fb, FLOW_TYPE_NEXT_HEADER);
|
||||
flow_builder_add_op_val(fb, 0, 0x06);
|
||||
|
||||
net_fill_ip6((net_addr *) &ip, ip6_build(0xc0000000,0,0,0), 8);
|
||||
flow_builder_set_type(fb, FLOW_TYPE_SRC_PREFIX);
|
||||
flow_builder6_add_pfx(fb, &ip, 0);
|
||||
|
||||
net_fill_ip6((net_addr *) &ip, ip6_build(0, 1, 0x12345678, 0x98000000), 103);
|
||||
flow_builder_set_type(fb, FLOW_TYPE_DST_PREFIX);
|
||||
flow_builder6_add_pfx(fb, &ip, 61);
|
||||
|
||||
res = flow_builder6_finalize(fb, lp);
|
||||
bt_assert(memcmp(res, expect, expect->length) == 0);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_formatting4(void)
|
||||
{
|
||||
char b[1024];
|
||||
|
||||
byte nlri[] = {
|
||||
0,
|
||||
FLOW_TYPE_DST_PREFIX, 0x08, 10,
|
||||
FLOW_TYPE_IP_PROTOCOL, 0x81, 23,
|
||||
FLOW_TYPE_DST_PORT, 0x02, 24, 0x44, 30, 0x03, 40, 0x45, 50, 0x03, 60, 0x45, 70, 0x01, 80, 0xc3, 90,
|
||||
FLOW_TYPE_SRC_PORT, 0x02, 24, 0x44, 0x1e, 0x01, 0x28, 0x01, 0x32, 0x03, 0x3c, 0x45, 0x46, 0x81, 0x50,
|
||||
FLOW_TYPE_ICMP_TYPE, 0x81, 0x50,
|
||||
FLOW_TYPE_ICMP_CODE, 0x81, 0x5a,
|
||||
FLOW_TYPE_TCP_FLAGS, 0x01, 0x03, 0xc2, 0x0c,
|
||||
FLOW_TYPE_PACKET_LENGTH, 0x03, 0, 0xd5, 0xff, 0xff,
|
||||
FLOW_TYPE_DSCP, 0x81, 63,
|
||||
FLOW_TYPE_FRAGMENT, 0x01, 0x01, 0x82, 0x02
|
||||
};
|
||||
*nlri = (u8) sizeof(nlri);
|
||||
|
||||
net_addr_flow4 *input;
|
||||
NET_ADDR_FLOW4_(input, ip4_build(5, 6, 7, 0), 24, nlri);
|
||||
|
||||
const char *expect = "flow4 { dst 10.0.0.0/8; proto 23; dport > 24 && < 30 || 40..50,60..70,80 && >= 90; sport > 24 && < 30 || 40,50,60..70,80; icmp type 80; icmp code 90; tcp flags 0x3/0x3,0x0/0xc; length 0..65535; dscp 63; fragment dont_fragment || !is_fragment; }";
|
||||
|
||||
bt_assert(flow4_net_format(b, sizeof(b), input) == strlen(expect));
|
||||
bt_debug(" expect: '%s',\n output: '%s'\n", expect, b);
|
||||
bt_assert(strcmp(b, expect) == 0);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_formatting6(void)
|
||||
{
|
||||
char b[1024];
|
||||
|
||||
byte nlri[] = {
|
||||
0,
|
||||
FLOW_TYPE_DST_PREFIX, 103, 61, 0x01, 0x12, 0x34, 0x56, 0x78, 0x98,
|
||||
FLOW_TYPE_SRC_PREFIX, 8, 0, 0xc0,
|
||||
FLOW_TYPE_NEXT_HEADER, 0x81, 0x06,
|
||||
FLOW_TYPE_PORT, 0x03, 20, 0x45, 40, 0x91, 0x01, 0x11,
|
||||
FLOW_TYPE_LABEL, 0xa0, 0x12, 0x34, 0x56, 0x78,
|
||||
};
|
||||
*nlri = (u8) sizeof(nlri);
|
||||
|
||||
net_addr_flow6 *input;
|
||||
NET_ADDR_FLOW6_(input, ip6_build(0, 1, 0x12345678, 0x98000000), 103, nlri);
|
||||
|
||||
const char *expect = "flow6 { dst ::1:1234:5678:9800:0/103 offset 61; src c000::/8; next header 6; port 20..40,273; label !0x0/0x12345678; }";
|
||||
|
||||
bt_assert(flow6_net_format(b, sizeof(b), input) == strlen(expect));
|
||||
bt_debug(" expect: '%s',\n output: '%s'\n", expect, b);
|
||||
bt_assert(strcmp(b, expect) == 0);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
bt_init(argc, argv);
|
||||
|
||||
bt_test_suite(t_read_length, "Testing get NLRI length");
|
||||
bt_test_suite(t_write_length, "Testing set NLRI length");
|
||||
bt_test_suite(t_first_part, "Searching first part in net_addr_flow");
|
||||
bt_test_suite(t_iterators4, "Testing iterators (IPv4)");
|
||||
bt_test_suite(t_iterators6, "Testing iterators (IPv6)");
|
||||
bt_test_suite(t_accessors4, "Testing accessors (IPv4)");
|
||||
bt_test_suite(t_accessors6, "Testing accessors (IPv6)");
|
||||
bt_test_suite(t_validation4, "Testing validation (IPv4)");
|
||||
bt_test_suite(t_validation6, "Testing validation (IPv6)");
|
||||
bt_test_suite(t_builder4, "Inserting components into existing Flow Specification (IPv4)");
|
||||
bt_test_suite(t_builder6, "Inserting components into existing Flow Specification (IPv6)");
|
||||
bt_test_suite(t_formatting4, "Formatting Flow Specification (IPv4) into text representation");
|
||||
bt_test_suite(t_formatting6, "Formatting Flow Specification (IPv6) into text representation");
|
||||
|
||||
return bt_exit_value();
|
||||
}
|
240
lib/hash.h
Normal file
240
lib/hash.h
Normal file
@ -0,0 +1,240 @@
|
||||
/*
|
||||
* BIRD Library -- Generic Hash Table
|
||||
*
|
||||
* (c) 2013 Ondrej Zajicek <santiago@crfreenet.org>
|
||||
* (c) 2013 CZ.NIC z.s.p.o.
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#ifndef _BIRD_HASH_H_
|
||||
#define _BIRD_HASH_H_
|
||||
|
||||
#define HASH(type) struct { type **data; uint count, order; }
|
||||
#define HASH_TYPE(v) typeof(** (v).data)
|
||||
#define HASH_SIZE(v) (1U << (v).order)
|
||||
|
||||
#define HASH_EQ(v,id,k1,k2...) (id##_EQ(k1, k2))
|
||||
#define HASH_FN(v,id,key...) ((u32) (id##_FN(key)) >> (32 - (v).order))
|
||||
|
||||
|
||||
#define HASH_INIT(v,pool,init_order) \
|
||||
({ \
|
||||
(v).count = 0; \
|
||||
(v).order = (init_order); \
|
||||
(v).data = mb_allocz(pool, HASH_SIZE(v) * sizeof(* (v).data)); \
|
||||
})
|
||||
|
||||
#define HASH_FREE(v) \
|
||||
({ \
|
||||
mb_free((v).data); \
|
||||
(v) = (typeof(v)){ }; \
|
||||
})
|
||||
|
||||
#define HASH_FIND(v,id,key...) \
|
||||
({ \
|
||||
u32 _h = HASH_FN(v, id, key); \
|
||||
HASH_TYPE(v) *_n = (v).data[_h]; \
|
||||
while (_n && !HASH_EQ(v, id, id##_KEY(_n), key)) \
|
||||
_n = id##_NEXT(_n); \
|
||||
_n; \
|
||||
})
|
||||
|
||||
#define HASH_INSERT(v,id,node) \
|
||||
({ \
|
||||
u32 _h = HASH_FN(v, id, id##_KEY((node))); \
|
||||
HASH_TYPE(v) **_nn = (v).data + _h; \
|
||||
id##_NEXT(node) = *_nn; \
|
||||
*_nn = node; \
|
||||
(v).count++; \
|
||||
})
|
||||
|
||||
#define HASH_DO_REMOVE(v,id,_nn) \
|
||||
({ \
|
||||
*_nn = id##_NEXT((*_nn)); \
|
||||
(v).count--; \
|
||||
})
|
||||
|
||||
#define HASH_DELETE(v,id,key...) \
|
||||
({ \
|
||||
u32 _h = HASH_FN(v, id, key); \
|
||||
HASH_TYPE(v) *_n, **_nn = (v).data + _h; \
|
||||
\
|
||||
while ((*_nn) && !HASH_EQ(v, id, id##_KEY((*_nn)), key)) \
|
||||
_nn = &(id##_NEXT((*_nn))); \
|
||||
\
|
||||
if (_n = *_nn) \
|
||||
HASH_DO_REMOVE(v,id,_nn); \
|
||||
_n; \
|
||||
})
|
||||
|
||||
#define HASH_REMOVE(v,id,node) \
|
||||
({ \
|
||||
u32 _h = HASH_FN(v, id, id##_KEY((node))); \
|
||||
HASH_TYPE(v) *_n, **_nn = (v).data + _h; \
|
||||
\
|
||||
while ((*_nn) && (*_nn != (node))) \
|
||||
_nn = &(id##_NEXT((*_nn))); \
|
||||
\
|
||||
if (_n = *_nn) \
|
||||
HASH_DO_REMOVE(v,id,_nn); \
|
||||
_n; \
|
||||
})
|
||||
|
||||
|
||||
#define HASH_REHASH(v,id,pool,step) \
|
||||
({ \
|
||||
HASH_TYPE(v) *_n, *_n2, **_od; \
|
||||
uint _i, _os; \
|
||||
\
|
||||
_os = HASH_SIZE(v); \
|
||||
_od = (v).data; \
|
||||
(v).count = 0; \
|
||||
(v).order += (step); \
|
||||
(v).data = mb_allocz(pool, HASH_SIZE(v) * sizeof(* (v).data)); \
|
||||
\
|
||||
for (_i = 0; _i < _os; _i++) \
|
||||
for (_n = _od[_i]; _n && (_n2 = id##_NEXT(_n), 1); _n = _n2) \
|
||||
HASH_INSERT(v, id, _n); \
|
||||
\
|
||||
mb_free(_od); \
|
||||
})
|
||||
|
||||
#define REHASH_LO_MARK(a,b,c,d,e,f) a
|
||||
#define REHASH_HI_MARK(a,b,c,d,e,f) b
|
||||
#define REHASH_LO_STEP(a,b,c,d,e,f) c
|
||||
#define REHASH_HI_STEP(a,b,c,d,e,f) d
|
||||
#define REHASH_LO_BOUND(a,b,c,d,e,f) e
|
||||
#define REHASH_HI_BOUND(a,b,c,d,e,f) f
|
||||
|
||||
#define HASH_DEFINE_REHASH_FN(id,type) \
|
||||
static void id##_REHASH(void *v, pool *p, int step) \
|
||||
{ HASH_REHASH(* (HASH(type) *) v, id, p, step); }
|
||||
|
||||
|
||||
#define HASH_MAY_STEP_UP(v,id,pool) HASH_MAY_STEP_UP_(v,pool, id##_REHASH, id##_PARAMS)
|
||||
#define HASH_MAY_STEP_DOWN(v,id,pool) HASH_MAY_STEP_DOWN_(v,pool, id##_REHASH, id##_PARAMS)
|
||||
#define HASH_MAY_RESIZE_DOWN(v,id,pool) HASH_MAY_RESIZE_DOWN_(v,pool, id##_REHASH, id##_PARAMS)
|
||||
|
||||
#define HASH_MAY_STEP_UP_(v,pool,rehash_fn,args) \
|
||||
({ \
|
||||
if (((v).count > (HASH_SIZE(v) REHASH_HI_MARK(args))) && \
|
||||
((v).order < (REHASH_HI_BOUND(args)))) \
|
||||
rehash_fn(&(v), pool, REHASH_HI_STEP(args)); \
|
||||
})
|
||||
|
||||
#define HASH_MAY_STEP_DOWN_(v,pool,rehash_fn,args) \
|
||||
({ \
|
||||
if (((v).count < (HASH_SIZE(v) REHASH_LO_MARK(args))) && \
|
||||
((v).order > (REHASH_LO_BOUND(args)))) \
|
||||
rehash_fn(&(v), pool, -(REHASH_LO_STEP(args))); \
|
||||
})
|
||||
|
||||
#define HASH_MAY_RESIZE_DOWN_(v,pool,rehash_fn,args) \
|
||||
({ \
|
||||
uint _o = (v).order; \
|
||||
while (((v).count < ((1U << _o) REHASH_LO_MARK(args))) && \
|
||||
(_o > (REHASH_LO_BOUND(args)))) \
|
||||
_o -= (REHASH_LO_STEP(args)); \
|
||||
if (_o < (v).order) \
|
||||
rehash_fn(&(v), pool, _o - (v).order); \
|
||||
})
|
||||
|
||||
|
||||
#define HASH_INSERT2(v,id,pool,node) \
|
||||
({ \
|
||||
HASH_INSERT(v, id, node); \
|
||||
HASH_MAY_STEP_UP(v, id, pool); \
|
||||
})
|
||||
|
||||
#define HASH_DELETE2(v,id,pool,key...) \
|
||||
({ \
|
||||
HASH_TYPE(v) *_n = HASH_DELETE(v, id, key); \
|
||||
if (_n) HASH_MAY_STEP_DOWN(v, id, pool); \
|
||||
_n; \
|
||||
})
|
||||
|
||||
#define HASH_REMOVE2(v,id,pool,node) \
|
||||
({ \
|
||||
HASH_TYPE(v) *_n = HASH_REMOVE(v, id, node); \
|
||||
if (_n) HASH_MAY_STEP_DOWN(v, id, pool); \
|
||||
_n; \
|
||||
})
|
||||
|
||||
|
||||
#define HASH_WALK(v,next,n) \
|
||||
do { \
|
||||
HASH_TYPE(v) *n; \
|
||||
uint _i; \
|
||||
uint _s = HASH_SIZE(v); \
|
||||
for (_i = 0; _i < _s; _i++) \
|
||||
for (n = (v).data[_i]; n; n = n->next)
|
||||
|
||||
#define HASH_WALK_END } while (0)
|
||||
|
||||
|
||||
#define HASH_WALK_DELSAFE(v,next,n) \
|
||||
do { \
|
||||
HASH_TYPE(v) *n, *_next; \
|
||||
uint _i; \
|
||||
uint _s = HASH_SIZE(v); \
|
||||
for (_i = 0; _i < _s; _i++) \
|
||||
for (n = (v).data[_i]; n && (_next = n->next, 1); n = _next)
|
||||
|
||||
#define HASH_WALK_DELSAFE_END } while (0)
|
||||
|
||||
|
||||
#define HASH_WALK_FILTER(v,next,n,nn) \
|
||||
do { \
|
||||
HASH_TYPE(v) *n, **nn; \
|
||||
uint _i; \
|
||||
uint _s = HASH_SIZE(v); \
|
||||
for (_i = 0; _i < _s; _i++) \
|
||||
for (nn = (v).data + _i; n = *nn; (*nn == n) ? (nn = &n->next) : NULL)
|
||||
|
||||
#define HASH_WALK_FILTER_END } while (0)
|
||||
|
||||
|
||||
static inline void
|
||||
mem_hash_init(u64 *h)
|
||||
{
|
||||
*h = 0x001047d54778bcafULL;
|
||||
}
|
||||
|
||||
static inline void
|
||||
mem_hash_mix(u64 *h, const void *p, uint s)
|
||||
{
|
||||
const u64 multiplier = 0xb38bc09a61202731ULL;
|
||||
const char *pp = p;
|
||||
uint i;
|
||||
|
||||
for (i=0; i<s/4; i++)
|
||||
*h = *h * multiplier + ((const u32 *)pp)[i];
|
||||
|
||||
for (i=s & ~0x3; i<s; i++)
|
||||
*h = *h * multiplier + pp[i];
|
||||
}
|
||||
|
||||
static inline uint
|
||||
mem_hash_value(u64 *h)
|
||||
{
|
||||
return ((*h >> 32) ^ (*h & 0xffffffff));
|
||||
}
|
||||
|
||||
static inline uint
|
||||
mem_hash(const void *p, uint s)
|
||||
{
|
||||
static u64 h;
|
||||
mem_hash_init(&h);
|
||||
mem_hash_mix(&h, p, s);
|
||||
return mem_hash_value(&h);
|
||||
}
|
||||
|
||||
static inline uint
|
||||
ptr_hash(void *ptr)
|
||||
{
|
||||
uintptr_t p = (uintptr_t) ptr;
|
||||
return p ^ (p << 8) ^ (p >> 16);
|
||||
}
|
||||
|
||||
#endif
|
305
lib/hash_test.c
Normal file
305
lib/hash_test.c
Normal file
@ -0,0 +1,305 @@
|
||||
/*
|
||||
* BIRD Library -- Hash Tests
|
||||
*
|
||||
* (c) 2015 CZ.NIC z.s.p.o.
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#undef LOCAL_DEBUG
|
||||
|
||||
#include "test/birdtest.h"
|
||||
|
||||
#include "lib/hash.h"
|
||||
|
||||
struct test_node {
|
||||
struct test_node *next; /* Hash chain */
|
||||
u32 key;
|
||||
};
|
||||
|
||||
#define TEST_KEY(n) n->key
|
||||
#define TEST_NEXT(n) n->next
|
||||
#define TEST_EQ(n1,n2) n1 == n2
|
||||
#define TEST_FN(n) (n) ^ u32_hash((n))
|
||||
#define TEST_ORDER 13
|
||||
#define TEST_PARAMS /TEST_ORDER, *2, 2, 2, TEST_ORDER, 20
|
||||
#define TEST_REHASH test_rehash
|
||||
|
||||
HASH_DEFINE_REHASH_FN(TEST, struct test_node);
|
||||
|
||||
HASH(struct test_node) hash;
|
||||
struct pool *my_pool;
|
||||
|
||||
#define MAX_NUM (1 << TEST_ORDER)
|
||||
|
||||
struct test_node nodes[MAX_NUM];
|
||||
|
||||
static void
|
||||
print_rate_of_fulfilment(void)
|
||||
{
|
||||
int i;
|
||||
int num_stacked_items = 0;
|
||||
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
if (!hash.data[i])
|
||||
num_stacked_items++;
|
||||
|
||||
double percent_stacked_items = ((double)num_stacked_items/(double)MAX_NUM)*100.;
|
||||
bt_debug("%d (%.2f %%) chained of %d hashes \n", num_stacked_items, percent_stacked_items, MAX_NUM);
|
||||
}
|
||||
|
||||
#ifdef LOCAL_DEBUG
|
||||
static void
|
||||
dump_nodes(void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
bt_debug("nodes[%3d] is at address %14p has .key %3d, .next %14p \n", i, &nodes[i], nodes[i].key, nodes[i].next);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
init_hash_(uint order)
|
||||
{
|
||||
resource_init();
|
||||
my_pool = rp_new(&root_pool, "Test pool");
|
||||
|
||||
HASH_INIT(hash, my_pool, order);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
{
|
||||
nodes[i].key = i;
|
||||
nodes[i].next = NULL;
|
||||
}
|
||||
|
||||
bt_debug("MAX_NUM %d \n", MAX_NUM);
|
||||
}
|
||||
|
||||
static void
|
||||
init_hash(void)
|
||||
{
|
||||
init_hash_(TEST_ORDER);
|
||||
}
|
||||
|
||||
static void
|
||||
validate_filled_hash(void)
|
||||
{
|
||||
int i;
|
||||
struct test_node *node;
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
{
|
||||
node = HASH_FIND(hash, TEST, nodes[i].key);
|
||||
bt_assert_msg(node->key == nodes[i].key, "Hash should be filled, to find (%p) the node[%d] (%p) with .key = %u, .next %p", node, i, &nodes[i], nodes[i].key, nodes[i].next);
|
||||
}
|
||||
|
||||
print_rate_of_fulfilment();
|
||||
}
|
||||
|
||||
static void
|
||||
validate_empty_hash(void)
|
||||
{
|
||||
int i;
|
||||
struct test_node *node;
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
{
|
||||
node = HASH_FIND(hash, TEST, nodes[i].key);
|
||||
bt_assert_msg(node == NULL, "Hash should be empty, to find (%p) the node[%d] (%p) with .key %u, .next %p", node, i, &nodes[i], nodes[i].key, nodes[i].next);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
fill_hash(void)
|
||||
{
|
||||
int i;
|
||||
struct test_node *node;
|
||||
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
{
|
||||
nodes[i].key = i;
|
||||
node = &nodes[i];
|
||||
HASH_INSERT(hash, TEST, node);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
t_insert_find(void)
|
||||
{
|
||||
init_hash();
|
||||
fill_hash();
|
||||
validate_filled_hash();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_insert_find_random(void)
|
||||
{
|
||||
init_hash();
|
||||
|
||||
int i;
|
||||
struct test_node *node;
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
{
|
||||
nodes[i].key = bt_random();
|
||||
node = &nodes[i];
|
||||
HASH_INSERT(hash, TEST, node);
|
||||
}
|
||||
|
||||
validate_filled_hash();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_insert2_find(void)
|
||||
{
|
||||
init_hash_(1);
|
||||
|
||||
int i;
|
||||
struct test_node *node;
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
{
|
||||
nodes[i].key = i;
|
||||
node = &nodes[i];
|
||||
HASH_INSERT2(hash, TEST, my_pool, node);
|
||||
}
|
||||
bt_assert_msg(hash.order != 1, "The hash should auto-resize from order 2^1. The order of the hash is 2^%u.", hash.order);
|
||||
|
||||
validate_filled_hash();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_walk(void)
|
||||
{
|
||||
init_hash();
|
||||
fill_hash();
|
||||
|
||||
uint i;
|
||||
uint check[MAX_NUM];
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
check[i] = 0;
|
||||
|
||||
HASH_WALK(hash, next, n)
|
||||
{
|
||||
check[n->key]++;
|
||||
}
|
||||
HASH_WALK_END;
|
||||
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
bt_assert(check[i] == 1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_walk_delsafe_delete(void)
|
||||
{
|
||||
init_hash();
|
||||
fill_hash();
|
||||
|
||||
HASH_WALK_DELSAFE(hash, next, n)
|
||||
{
|
||||
HASH_DELETE(hash, TEST, n->key);
|
||||
}
|
||||
HASH_WALK_DELSAFE_END;
|
||||
|
||||
validate_empty_hash();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_walk_delsafe_remove(void)
|
||||
{
|
||||
init_hash();
|
||||
fill_hash();
|
||||
|
||||
HASH_WALK_DELSAFE(hash, next, n)
|
||||
{
|
||||
HASH_REMOVE(hash, TEST, n);
|
||||
}
|
||||
HASH_WALK_DELSAFE_END;
|
||||
|
||||
validate_empty_hash();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_walk_delsafe_delete2(void)
|
||||
{
|
||||
init_hash();
|
||||
fill_hash();
|
||||
|
||||
HASH_WALK_DELSAFE(hash, next, n)
|
||||
{
|
||||
HASH_DELETE2(hash, TEST, my_pool, n->key);
|
||||
}
|
||||
HASH_WALK_DELSAFE_END;
|
||||
|
||||
validate_empty_hash();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_walk_delsafe_remove2(void)
|
||||
{
|
||||
init_hash();
|
||||
fill_hash();
|
||||
|
||||
HASH_WALK_DELSAFE(hash, next, n)
|
||||
{
|
||||
HASH_REMOVE2(hash, TEST, my_pool, n);
|
||||
}
|
||||
HASH_WALK_DELSAFE_END;
|
||||
|
||||
validate_empty_hash();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_walk_filter(void)
|
||||
{
|
||||
init_hash();
|
||||
fill_hash();
|
||||
|
||||
uint i;
|
||||
uint check[MAX_NUM];
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
check[i] = 0;
|
||||
|
||||
HASH_WALK_FILTER(hash, next, n, m)
|
||||
{
|
||||
bt_assert(n == *m);
|
||||
check[n->key]++;
|
||||
}
|
||||
HASH_WALK_FILTER_END;
|
||||
|
||||
for (i = 0; i < MAX_NUM; i++)
|
||||
bt_assert(check[i] == 1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
bt_init(argc, argv);
|
||||
|
||||
bt_test_suite(t_insert_find, "HASH_INSERT and HASH_FIND");
|
||||
bt_test_suite(t_insert_find_random, "HASH_INSERT pseudo-random keys and HASH_FIND");
|
||||
bt_test_suite(t_insert2_find, "HASH_INSERT2 and HASH_FIND. HASH_INSERT2 is HASH_INSERT and a smart auto-resize function");
|
||||
bt_test_suite(t_walk, "HASH_WALK");
|
||||
bt_test_suite(t_walk_delsafe_delete, "HASH_WALK_DELSAFE and HASH_DELETE");
|
||||
bt_test_suite(t_walk_delsafe_delete2, "HASH_WALK_DELSAFE and HASH_DELETE2. HASH_DELETE2 is HASH_DELETE and smart auto-resize function");
|
||||
bt_test_suite(t_walk_delsafe_remove, "HASH_WALK_DELSAFE and HASH_REMOVE");
|
||||
bt_test_suite(t_walk_delsafe_remove2, "HASH_WALK_DELSAFE and HASH_REMOVE2. HASH_REMOVE2 is HASH_REMOVE and smart auto-resize function");
|
||||
bt_test_suite(t_walk_filter, "HASH_WALK_FILTER");
|
||||
|
||||
return bt_exit_value();
|
||||
}
|
156
lib/heap.h
Normal file
156
lib/heap.h
Normal file
@ -0,0 +1,156 @@
|
||||
/*
|
||||
* UCW Library -- Universal Heap Macros
|
||||
*
|
||||
* (c) 2001 Martin Mares <mj@ucw.cz>
|
||||
* (c) 2005 Tomas Valla <tom@ucw.cz>
|
||||
*
|
||||
* This software may be freely distributed and used according to the terms
|
||||
* of the GNU Lesser General Public License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* [[intro]]
|
||||
* Introduction
|
||||
* ------------
|
||||
*
|
||||
* Binary heap is a simple data structure, which for example supports efficient insertions, deletions
|
||||
* and access to the minimal inserted item. We define several macros for such operations.
|
||||
* Note that because of simplicity of heaps, we have decided to define direct macros instead
|
||||
* of a <<generic:,macro generator>> as for several other data structures in the Libucw.
|
||||
*
|
||||
* A heap is represented by a number of elements and by an array of values. Beware that we
|
||||
* index this array from one, not from zero as do the standard C arrays.
|
||||
*
|
||||
* Most macros use these parameters:
|
||||
*
|
||||
* - @type - the type of elements
|
||||
* - @num - a variable (signed or unsigned integer) with the number of elements
|
||||
* - @heap - a C array of type @type; the heap is stored in `heap[1] .. heap[num]`; `heap[0]` is unused
|
||||
* - @less - a callback to compare two element values; `less(x, y)` shall return a non-zero value iff @x is lower than @y
|
||||
* - @swap - a callback to swap two array elements; `swap(heap, i, j, t)` must swap `heap[i]` with `heap[j]` with possible help of temporary variable @t (type @type).
|
||||
*
|
||||
* A valid heap must follow these rules:
|
||||
*
|
||||
* - `num >= 0`
|
||||
* - `heap[i] >= heap[i / 2]` for each `i` in `[2, num]`
|
||||
*
|
||||
* The first element `heap[1]` is always lower or equal to all other elements.
|
||||
*
|
||||
* [[macros]]
|
||||
* Macros
|
||||
* ------
|
||||
*/
|
||||
|
||||
/* For internal usage. */
|
||||
#define HEAP_BUBBLE_DOWN_J(heap,num,less,swap) \
|
||||
for (;;) \
|
||||
{ \
|
||||
_l = 2*_j; \
|
||||
if (_l > num) \
|
||||
break; \
|
||||
if (less(heap[_j],heap[_l]) && (_l == num || less(heap[_j],heap[_l+1]))) \
|
||||
break; \
|
||||
if (_l != num && less(heap[_l+1],heap[_l])) \
|
||||
_l++; \
|
||||
swap(heap,_j,_l,x); \
|
||||
_j = _l; \
|
||||
}
|
||||
|
||||
/* For internal usage. */
|
||||
#define HEAP_BUBBLE_UP_J(heap,num,less,swap) \
|
||||
while (_j > 1) \
|
||||
{ \
|
||||
_u = _j/2; \
|
||||
if (less(heap[_u], heap[_j])) \
|
||||
break; \
|
||||
swap(heap,_u,_j,x); \
|
||||
_j = _u; \
|
||||
}
|
||||
|
||||
/**
|
||||
* Shuffle the unordered array @heap of @num elements to become a valid heap. The time complexity is linear.
|
||||
**/
|
||||
#define HEAP_INIT(heap,num,type,less,swap) \
|
||||
do { \
|
||||
uint _i = num; \
|
||||
uint _j, _l; \
|
||||
type x; \
|
||||
while (_i >= 1) \
|
||||
{ \
|
||||
_j = _i; \
|
||||
HEAP_BUBBLE_DOWN_J(heap,num,less,swap) \
|
||||
_i--; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* Delete the minimum element `heap[1]` in `O(log(n))` time.
|
||||
* The removed value is moved just after the resulting heap (`heap[num + 1]`).
|
||||
**/
|
||||
#define HEAP_DELMIN(heap,num,type,less,swap) \
|
||||
do { \
|
||||
uint _j, _l; \
|
||||
type x; \
|
||||
swap(heap,1,num,x); \
|
||||
num--; \
|
||||
_j = 1; \
|
||||
HEAP_BUBBLE_DOWN_J(heap,num,less,swap); \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* Insert `heap[num]` in `O(log(n))` time. The value of @num must be increased before.
|
||||
**/
|
||||
#define HEAP_INSERT(heap,num,type,less,swap) \
|
||||
do { \
|
||||
uint _j, _u; \
|
||||
type x; \
|
||||
_j = num; \
|
||||
HEAP_BUBBLE_UP_J(heap,num,less,swap); \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* If you need to increase the value of `heap[pos]`, just do it and then call this macro to rebuild the heap.
|
||||
* Only `heap[pos]` can be changed, the rest of the array must form a valid heap.
|
||||
* The time complexity is `O(log(n))`.
|
||||
**/
|
||||
#define HEAP_INCREASE(heap,num,type,less,swap,pos) \
|
||||
do { \
|
||||
uint _j, _l; \
|
||||
type x; \
|
||||
_j = pos; \
|
||||
HEAP_BUBBLE_DOWN_J(heap,num,less,swap); \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* If you need to decrease the value of `heap[pos]`, just do it and then call this macro to rebuild the heap.
|
||||
* Only `heap[pos]` can be changed, the rest of the array must form a valid heap.
|
||||
* The time complexity is `O(log(n))`.
|
||||
**/
|
||||
#define HEAP_DECREASE(heap,num,type,less,swap,pos) \
|
||||
do { \
|
||||
uint _j, _u; \
|
||||
type x; \
|
||||
_j = pos; \
|
||||
HEAP_BUBBLE_UP_J(heap,num,less,swap); \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* Delete `heap[pos]` in `O(log(n))` time.
|
||||
**/
|
||||
#define HEAP_DELETE(heap,num,type,less,swap,pos) \
|
||||
do { \
|
||||
uint _j, _l, _u; \
|
||||
type x; \
|
||||
_j = pos; \
|
||||
swap(heap,_j,num,x); \
|
||||
num--; \
|
||||
if (less(heap[_j], heap[num+1])) \
|
||||
HEAP_BUBBLE_UP_J(heap,num,less,swap) \
|
||||
else \
|
||||
HEAP_BUBBLE_DOWN_J(heap,num,less,swap); \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* Default swapping macro.
|
||||
**/
|
||||
#define HEAP_SWAP(heap,a,b,t) (t=heap[a], heap[a]=heap[b], heap[b]=t)
|
186
lib/heap_test.c
Normal file
186
lib/heap_test.c
Normal file
@ -0,0 +1,186 @@
|
||||
/*
|
||||
* BIRD Library -- Universal Heap Macros Tests
|
||||
*
|
||||
* (c) 2015 CZ.NIC z.s.p.o.
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#include "test/birdtest.h"
|
||||
#include "sysdep/config.h"
|
||||
#include "lib/heap.h"
|
||||
|
||||
#define MAX_NUM 1000
|
||||
#define SPECIAL_KEY -3213
|
||||
|
||||
#define MY_CMP(x, y) ((x) < (y))
|
||||
|
||||
#define MY_HEAP_SWAP(heap,a,b,t) \
|
||||
do { \
|
||||
bt_debug("swap(%u %u) ", a, b); \
|
||||
HEAP_SWAP(heap,a,b,t); \
|
||||
} while(0)
|
||||
|
||||
static int heap[MAX_NUM+1];
|
||||
static uint num;
|
||||
|
||||
/*
|
||||
* A valid heap must follow these rules:
|
||||
* - `num >= 0`
|
||||
* - `heap[i] >= heap[i / 2]` for each `i` in `[2, num]`
|
||||
*/
|
||||
static int
|
||||
is_heap_valid(int heap[], uint num)
|
||||
{
|
||||
uint i;
|
||||
|
||||
if (num > MAX_NUM)
|
||||
return 0;
|
||||
|
||||
for (i = 2; i <= num; i++)
|
||||
if (heap[i] < heap[i / 2])
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
show_heap(void)
|
||||
{
|
||||
uint i;
|
||||
bt_debug("\n");
|
||||
bt_debug("numbers %u; ", num);
|
||||
for (i = 0; i <= num; i++)
|
||||
bt_debug("%d ", heap[i]);
|
||||
bt_debug(is_heap_valid(heap, num) ? "OK" : "NON-VALID HEAP!");
|
||||
bt_debug("\n");
|
||||
}
|
||||
|
||||
static void
|
||||
init_heap(void)
|
||||
{
|
||||
uint i;
|
||||
num = 0;
|
||||
heap[0] = SPECIAL_KEY; /* heap[0] should be unused */
|
||||
for (i = 1; i <= MAX_NUM; i++)
|
||||
heap[i] = 0;
|
||||
}
|
||||
|
||||
static int
|
||||
t_heap_insert(void)
|
||||
{
|
||||
uint i;
|
||||
|
||||
init_heap();
|
||||
|
||||
for (i = MAX_NUM; i >= 1; i--)
|
||||
{
|
||||
bt_debug("ins %u at pos %u ", i, MAX_NUM - i);
|
||||
heap[MAX_NUM - i + 1] = i;
|
||||
HEAP_INSERT(heap, ++num, int, MY_CMP, MY_HEAP_SWAP);
|
||||
show_heap();
|
||||
bt_assert(is_heap_valid(heap, num));
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_heap_increase_decrease(void)
|
||||
{
|
||||
uint i;
|
||||
|
||||
t_heap_insert();
|
||||
|
||||
for (i = 1; i <= MAX_NUM; i++)
|
||||
{
|
||||
if ((int)i > heap[i])
|
||||
{
|
||||
bt_debug("inc %u ", i);
|
||||
heap[i] = i;
|
||||
HEAP_INCREASE(heap, num, int, MY_CMP, MY_HEAP_SWAP, i);
|
||||
}
|
||||
else if ((int)i < heap[i])
|
||||
{
|
||||
bt_debug("dec %u ", i);
|
||||
heap[i] = i;
|
||||
HEAP_INCREASE(heap, num, int, MY_CMP, MY_HEAP_SWAP, i);
|
||||
}
|
||||
show_heap();
|
||||
bt_assert(is_heap_valid(heap, num));
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_heap_delete(void)
|
||||
{
|
||||
uint i;
|
||||
|
||||
t_heap_insert();
|
||||
|
||||
for (i = 1; i <= num; i++)
|
||||
{
|
||||
bt_debug("del at pos %u ", i);
|
||||
HEAP_DELETE(heap, num, int, MY_CMP, MY_HEAP_SWAP, i);
|
||||
show_heap();
|
||||
bt_assert(is_heap_valid(heap, num));
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_heap_0(void)
|
||||
{
|
||||
init_heap();
|
||||
t_heap_insert();
|
||||
t_heap_increase_decrease();
|
||||
t_heap_delete();
|
||||
|
||||
return heap[0] == SPECIAL_KEY;
|
||||
}
|
||||
|
||||
static int
|
||||
t_heap_insert_random(void)
|
||||
{
|
||||
int i, j;
|
||||
int expected[MAX_NUM+1];
|
||||
|
||||
init_heap();
|
||||
|
||||
for (i = 1; i <= MAX_NUM; i++)
|
||||
{
|
||||
heap[i] = expected[i] = bt_random();
|
||||
HEAP_INSERT(heap, ++num, int, MY_CMP, MY_HEAP_SWAP);
|
||||
show_heap();
|
||||
bt_assert(is_heap_valid(heap, num));
|
||||
}
|
||||
|
||||
for (i = 1; i <= MAX_NUM; i++)
|
||||
for (j = 1; j <= MAX_NUM; j++)
|
||||
if(expected[i] == heap[j])
|
||||
break;
|
||||
else if (j == MAX_NUM)
|
||||
{
|
||||
show_heap();
|
||||
bt_abort_msg("Did not find a number %d in heap.", expected[i]);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
bt_init(argc, argv);
|
||||
|
||||
bt_test_suite(t_heap_insert, "Inserting a descending sequence of numbers (the worst case)");
|
||||
bt_test_suite(t_heap_insert_random, "Inserting pseudo-random numbers");
|
||||
bt_test_suite(t_heap_increase_decrease, "Increasing/Decreasing");
|
||||
bt_test_suite(t_heap_delete, "Deleting");
|
||||
bt_test_suite(t_heap_0, "Is a heap[0] really unused?");
|
||||
|
||||
return bt_exit_value();
|
||||
}
|
76
lib/idm.c
Normal file
76
lib/idm.c
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* BIRD Library -- ID Map
|
||||
*
|
||||
* (c) 2013--2015 Ondrej Zajicek <santiago@crfreenet.org>
|
||||
* (c) 2013--2015 CZ.NIC z.s.p.o.
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "nest/bird.h"
|
||||
#include "lib/idm.h"
|
||||
#include "lib/resource.h"
|
||||
#include "lib/string.h"
|
||||
|
||||
|
||||
void
|
||||
idm_init(struct idm *m, pool *p, uint size)
|
||||
{
|
||||
m->pos = 0;
|
||||
m->used = 1;
|
||||
m->size = size;
|
||||
m->data = mb_allocz(p, m->size * sizeof(u32));
|
||||
|
||||
/* ID 0 is reserved */
|
||||
m->data[0] = 1;
|
||||
}
|
||||
|
||||
static inline int u32_cto(uint x) { return ffs(~x) - 1; }
|
||||
|
||||
u32
|
||||
idm_alloc(struct idm *m)
|
||||
{
|
||||
uint i, j;
|
||||
|
||||
for (i = m->pos; i < m->size; i++)
|
||||
if (m->data[i] != 0xffffffff)
|
||||
goto found;
|
||||
|
||||
/* If we are at least 7/8 full, expand */
|
||||
if (m->used > (m->size * 28))
|
||||
{
|
||||
m->size *= 2;
|
||||
m->data = mb_realloc(m->data, m->size * sizeof(u32));
|
||||
memset(m->data + i, 0, (m->size - i) * sizeof(u32));
|
||||
goto found;
|
||||
}
|
||||
|
||||
for (i = 0; i < m->pos; i++)
|
||||
if (m->data[i] != 0xffffffff)
|
||||
goto found;
|
||||
|
||||
ASSERT(0);
|
||||
|
||||
found:
|
||||
ASSERT(i < 0x8000000);
|
||||
|
||||
m->pos = i;
|
||||
j = u32_cto(m->data[i]);
|
||||
|
||||
m->data[i] |= (1 << j);
|
||||
m->used++;
|
||||
return 32 * i + j;
|
||||
}
|
||||
|
||||
void
|
||||
idm_free(struct idm *m, u32 id)
|
||||
{
|
||||
uint i = id / 32;
|
||||
uint j = id % 32;
|
||||
|
||||
ASSERT((i < m->size) && (m->data[i] & (1 << j)));
|
||||
m->data[i] &= ~(1 << j);
|
||||
m->used--;
|
||||
}
|
25
lib/idm.h
Normal file
25
lib/idm.h
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* BIRD Library -- ID Map
|
||||
*
|
||||
* (c) 2013--2015 Ondrej Zajicek <santiago@crfreenet.org>
|
||||
* (c) 2013--2015 CZ.NIC z.s.p.o.
|
||||
*
|
||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||
*/
|
||||
|
||||
#ifndef _BIRD_IDM_H_
|
||||
#define _BIRD_IDM_H_
|
||||
|
||||
struct idm
|
||||
{
|
||||
u32 *data;
|
||||
u32 pos;
|
||||
u32 used;
|
||||
u32 size;
|
||||
};
|
||||
|
||||
void idm_init(struct idm *m, pool *p, uint size);
|
||||
u32 idm_alloc(struct idm *m);
|
||||
void idm_free(struct idm *m, u32 id);
|
||||
|
||||
#endif
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user