Compare commits
398 Commits
v2.0.3
...
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 |
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
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,4 @@
|
||||
/autom4te.cache/
|
||||
/doc/*.html
|
||||
/obj/
|
||||
/Makefile
|
||||
/bird
|
||||
|
472
.gitlab-ci.yml
472
.gitlab-ci.yml
@ -4,10 +4,12 @@ variables:
|
||||
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
|
||||
@ -34,36 +36,46 @@ docker_debian-7-amd64:
|
||||
IMG_NAME: "debian-7-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
docker_debian-8-amd64:
|
||||
variables:
|
||||
IMG_NAME: "debian-8-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
docker_debian-9-amd64:
|
||||
variables:
|
||||
IMG_NAME: "debian-9-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
docker_debian-testing-amd64:
|
||||
variables:
|
||||
IMG_NAME: "debian-testing-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"
|
||||
@ -79,9 +91,29 @@ docker_fedora-26-amd64:
|
||||
IMG_NAME: "fedora-26-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
docker_centos-6-amd64:
|
||||
docker_fedora-27-amd64:
|
||||
variables:
|
||||
IMG_NAME: "centos-6-amd64"
|
||||
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:
|
||||
@ -89,127 +121,43 @@ docker_centos-7-amd64:
|
||||
IMG_NAME: "centos-7-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
docker_opensuse-42_3-amd64:
|
||||
docker_centos-8-amd64:
|
||||
variables:
|
||||
IMG_NAME: "opensuse-42.3-amd64"
|
||||
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
|
||||
|
||||
.debian-7-i386: &debian-7-i386_env
|
||||
image: registry.labs.nic.cz/labs/bird:debian-7-i386
|
||||
tags:
|
||||
- docker
|
||||
- linux
|
||||
- amd64
|
||||
docker_opensuse-15.0-amd64:
|
||||
variables:
|
||||
IMG_NAME: "opensuse-15.0-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
.debian-8-i386: &debian-8-i386_env
|
||||
image: registry.labs.nic.cz/labs/bird:debian-8-i386
|
||||
tags:
|
||||
- docker
|
||||
- linux
|
||||
- amd64
|
||||
docker_opensuse-15.1-amd64:
|
||||
variables:
|
||||
IMG_NAME: "opensuse-15.1-amd64"
|
||||
<<: *docker_build
|
||||
|
||||
.debian-9-i386: &debian-9-i386_env
|
||||
image: registry.labs.nic.cz/labs/bird:debian-9-i386
|
||||
tags:
|
||||
- docker
|
||||
- linux
|
||||
- amd64
|
||||
|
||||
.debian-testing-i386: &debian-testing-i386_env
|
||||
image: registry.labs.nic.cz/labs/bird:debian-testing-i386
|
||||
tags:
|
||||
- docker
|
||||
- linux
|
||||
- amd64
|
||||
|
||||
.debian-7-amd64: &debian-7-amd64_env
|
||||
image: registry.labs.nic.cz/labs/bird:debian-7-amd64
|
||||
tags:
|
||||
- docker
|
||||
- linux
|
||||
- amd64
|
||||
|
||||
.debian-8-amd64: &debian-8-amd64_env
|
||||
image: registry.labs.nic.cz/labs/bird:debian-8-amd64
|
||||
tags:
|
||||
- docker
|
||||
- linux
|
||||
- amd64
|
||||
|
||||
.debian-9-amd64: &debian-9-amd64_env
|
||||
image: registry.labs.nic.cz/labs/bird:debian-9-amd64
|
||||
tags:
|
||||
- docker
|
||||
- linux
|
||||
- amd64
|
||||
|
||||
.debian-testing-amd64: &debian-testing-amd64_env
|
||||
image: registry.labs.nic.cz/labs/bird:debian-testing-amd64
|
||||
tags:
|
||||
- docker
|
||||
- linux
|
||||
- amd64
|
||||
|
||||
.fedora-25-amd64: &fedora-25-amd64_env
|
||||
image: registry.labs.nic.cz/labs/bird:fedora-25-amd64
|
||||
tags:
|
||||
- docker
|
||||
- linux
|
||||
- amd64
|
||||
|
||||
.fedora-26-amd64: &fedora-26-amd64_env
|
||||
image: registry.labs.nic.cz/labs/bird:fedora-26-amd64
|
||||
tags:
|
||||
- docker
|
||||
- linux
|
||||
- amd64
|
||||
|
||||
.centos-6-amd64: ¢os-6-amd64_env
|
||||
image: registry.labs.nic.cz/labs/bird:centos-6-amd64
|
||||
tags:
|
||||
- docker
|
||||
- linux
|
||||
- amd64
|
||||
|
||||
.centos-7-amd64: ¢os-7-amd64_env
|
||||
image: registry.labs.nic.cz/labs/bird:centos-7-amd64
|
||||
tags:
|
||||
- docker
|
||||
- linux
|
||||
- amd64
|
||||
|
||||
.opensuse-42_3-amd64: &opensuse-42_3-amd64_env
|
||||
image: registry.labs.nic.cz/labs/bird:opensuse-42.3-amd64
|
||||
tags:
|
||||
- docker
|
||||
- linux
|
||||
- amd64
|
||||
|
||||
.ubuntu-14_04-amd64: &ubuntu-14_04-amd64_env
|
||||
image: registry.labs.nic.cz/labs/bird:ubuntu-14.04-amd64
|
||||
tags:
|
||||
- docker
|
||||
- linux
|
||||
- amd64
|
||||
|
||||
.ubuntu-16_04-amd64: &ubuntu-16_04-amd64_env
|
||||
image: registry.labs.nic.cz/labs/bird:ubuntu-16.04-amd64
|
||||
tags:
|
||||
- docker
|
||||
- linux
|
||||
- amd64
|
||||
|
||||
# TODO We want to copy these BSDs to our own virtual machines, to make sure someone doesn't update them by accident.
|
||||
# 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
|
||||
@ -223,12 +171,8 @@ docker_ubuntu-16_04-amd64:
|
||||
tags:
|
||||
- freebsd
|
||||
- amd64
|
||||
#only:
|
||||
#- master
|
||||
#- triggers
|
||||
#- tags
|
||||
|
||||
.build: &build_job
|
||||
.build: &build-base
|
||||
stage: build
|
||||
script:
|
||||
- autoreconf
|
||||
@ -240,70 +184,232 @@ docker_ubuntu-16_04-amd64:
|
||||
# Run tests if they are available
|
||||
- $MAKE check
|
||||
|
||||
.build-linux: &build-linux
|
||||
<<: *build-base
|
||||
tags:
|
||||
- docker
|
||||
- linux
|
||||
- amd64
|
||||
|
||||
build-debian-7-amd64:
|
||||
<<: *debian-7-amd64_env
|
||||
<<: *build_job
|
||||
|
||||
build-debian-8-amd64:
|
||||
<<: *debian-8-amd64_env
|
||||
<<: *build_job
|
||||
|
||||
build-debian-9-amd64:
|
||||
<<: *debian-9-amd64_env
|
||||
<<: *build_job
|
||||
|
||||
build-debian-testing-amd64:
|
||||
<<: *debian-testing-amd64_env
|
||||
<<: *build_job
|
||||
|
||||
build-fedora-25-amd64:
|
||||
<<: *fedora-25-amd64_env
|
||||
<<: *build_job
|
||||
|
||||
build-fedora-26-amd64:
|
||||
<<: *fedora-26-amd64_env
|
||||
<<: *build_job
|
||||
|
||||
build-centos-6-amd64:
|
||||
<<: *centos-6-amd64_env
|
||||
<<: *build_job
|
||||
|
||||
build-centos-7-amd64:
|
||||
<<: *centos-7-amd64_env
|
||||
<<: *build_job
|
||||
|
||||
build-opensuse-42_3-amd64:
|
||||
<<: *opensuse-42_3-amd64_env
|
||||
<<: *build_job
|
||||
|
||||
build-ubuntu-14_04-amd64:
|
||||
<<: *ubuntu-14_04-amd64_env
|
||||
<<: *build_job
|
||||
|
||||
build-ubuntu-16_04-amd64:
|
||||
<<: *ubuntu-16_04-amd64_env
|
||||
<<: *build_job
|
||||
<<: *build-linux
|
||||
image: registry.labs.nic.cz/labs/bird:debian-7-amd64
|
||||
|
||||
build-debian-7-i386:
|
||||
<<: *debian-7-i386_env
|
||||
<<: *build_job
|
||||
<<: *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:
|
||||
<<: *debian-8-i386_env
|
||||
<<: *build_job
|
||||
<<: *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:
|
||||
<<: *debian-9-i386_env
|
||||
<<: *build_job
|
||||
<<: *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:
|
||||
<<: *debian-testing-i386_env
|
||||
<<: *build_job
|
||||
<<: *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:
|
||||
<<: *freebsd-11-amd64_env
|
||||
<<: *build_job
|
||||
<<: *build-base
|
||||
tags:
|
||||
- freebsd
|
||||
- amd64
|
||||
|
||||
build-freebsd-11-i386:
|
||||
<<: *freebsd-11-i386_env
|
||||
<<: *build_job
|
||||
<<: *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
|
||||
|
5
INSTALL
5
INSTALL
@ -41,8 +41,3 @@ For compiling BIRD documentation you also need:
|
||||
|
||||
- Linuxdoc-Tools
|
||||
- LaTeX
|
||||
|
||||
Note that build scripts for BIRD documentation expects 'nsgmls' from
|
||||
James Clark's SP suite, while modern distributions use 'onsgmls' from
|
||||
OpenSP suite. It is possible to build BIRD documentation with OpenSP
|
||||
tools, but it requires manually tweaking paths in doc/sgml2* scripts.
|
||||
|
56
Makefile.in
56
Makefile.in
@ -65,7 +65,8 @@ endif
|
||||
docgoals := docs userdocs progdocs
|
||||
testgoals := check test tests tests_run
|
||||
cleangoals := clean distclean testsclean
|
||||
.PHONY: all daemon cli $(docgoals) $(testgoals) $(cleangoals) tags cscope
|
||||
.PHONY: all daemon cli $(docgoals) $(testgoals) $(cleangoals) tags cscope prepare
|
||||
|
||||
all: daemon cli
|
||||
|
||||
daemon: $(daemon)
|
||||
@ -76,6 +77,8 @@ $(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
|
||||
|
||||
@ -99,39 +102,55 @@ 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 $(objdir)/.dir-stamp $(objdir)/sysdep/paths.h
|
||||
$(objdir)/%.o: $(srcdir)/%.c | prepare
|
||||
$(E)echo CC -o $@ -c $<
|
||||
$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -c $<
|
||||
|
||||
$(objdir)/%.o: $(objdir)/%.c $(objdir)/.dir-stamp $(objdir)/sysdep/paths.h
|
||||
$(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 $(objdir)/.dir-stamp $(objdir)/sysdep/paths.h
|
||||
$(objdir)/%.E: $(srcdir)/%.c | prepare
|
||||
$(E)echo CC -o $@ -E $<
|
||||
$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -E $<
|
||||
|
||||
$(objdir)/%.E: $(objdir)/%.c $(objdir)/.dir-stamp $(objdir)/sysdep/paths.h
|
||||
$(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 $(objdir)/.dir-stamp $(objdir)/sysdep/paths.h
|
||||
$(objdir)/%.S: $(srcdir)/%.c | prepare
|
||||
$(E)echo CC -o $@ -S $<
|
||||
$(Q)$(CC) $(CFLAGS) -MMD -MP -o $@ -S $<
|
||||
|
||||
$(objdir)/%.S: $(objdir)/%.c $(objdir)/.dir-stamp $(objdir)/sysdep/paths.h
|
||||
$(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
|
||||
|
||||
$(objdir)/.dir-stamp:
|
||||
# ## 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 $@
|
||||
@ -150,7 +169,7 @@ $(objdir)/sysdep/paths.h: Makefile
|
||||
|
||||
tests_targets_ok = $(addsuffix .ok,$(tests_targets))
|
||||
|
||||
$(tests_targets): %: %.o $(tests_objs)
|
||||
$(tests_targets): %: %.o $(tests_objs) | prepare
|
||||
$(E)echo LD $(LDFLAGS) -o $@ $< "..." $(LIBS)
|
||||
$(Q)$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
|
||||
|
||||
@ -165,21 +184,20 @@ check: tests tests_run
|
||||
tests: $(tests_targets)
|
||||
tests_run: $(tests_targets_ok)
|
||||
|
||||
# Finally include the computed dependencies
|
||||
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))
|
||||
|
||||
ifneq ($(filter-out $(cleangoals),$(MAKECMDGOALS)),)
|
||||
-include $(shell find $(objdir) -name "*.d")
|
||||
endif
|
||||
|
||||
ifeq ($(MAKECMDGOALS),)
|
||||
-include $(shell find $(objdir) -name "*.d")
|
||||
endif
|
||||
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]`
|
||||
cd $(srcdir) ; etags -lc `find $(dirs) -name '*.[chY]'`
|
||||
|
||||
cscope:
|
||||
cd $(srcdir) ; find $(dirs) -name *.[chY] > cscope.files ; cscope -b
|
||||
cd $(srcdir) ; find $(dirs) -name '*.[chY]' > cscope.files ; cscope -b
|
||||
|
||||
# Install
|
||||
|
||||
|
79
NEWS
79
NEWS
@ -1,3 +1,82 @@
|
||||
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
|
||||
|
43
aclocal.m4
vendored
43
aclocal.m4
vendored
@ -1,6 +1,25 @@
|
||||
dnl ** Additional Autoconf tests for BIRD configure script
|
||||
dnl ** (c) 1999 Martin Mares <mj@ucw.cz>
|
||||
|
||||
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]
|
||||
)
|
||||
)
|
||||
])
|
||||
|
||||
AC_DEFUN([BIRD_CHECK_PTHREADS],
|
||||
[
|
||||
bird_tmp_cflags="$CFLAGS"
|
||||
@ -131,6 +150,30 @@ AC_DEFUN([BIRD_CHECK_ANDROID_LOG],
|
||||
)
|
||||
])
|
||||
|
||||
AC_DEFUN([BIRD_CHECK_LTO],
|
||||
[
|
||||
bird_tmp_cflags="$CFLAGS"
|
||||
bird_tmp_ldflags="$LDFLAGS"
|
||||
CFLAGS="-flto"
|
||||
LDFLAGS="-flto=4"
|
||||
|
||||
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"
|
||||
|
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.")
|
@ -2,8 +2,7 @@ src := commands.c util.c client.c
|
||||
obj := $(src-o-files)
|
||||
|
||||
$(all-client)
|
||||
|
||||
$(o)commands.o: $(objdir)/conf/commands.h
|
||||
$(conf-y-targets): $(s)cmds.Y
|
||||
|
||||
$(exedir)/birdc: $(o)birdc.o
|
||||
$(exedir)/birdc: LIBS += $(CLIENT_LIBS)
|
||||
|
@ -10,12 +10,12 @@ BISON_DEBUG=-t
|
||||
#FLEX_DEBUG=-d
|
||||
endif
|
||||
|
||||
$(conf-y-targets): $(s)confbase.Y $(s)flowspec.Y
|
||||
$(M4) $(M4FLAGS) -P $| $^ >$@
|
||||
$(o)cf-parse.y: $(s)gen_parser.m4
|
||||
$(o)keywords.h: $(s)gen_keywords.m4
|
||||
$(o)commands.h: $(s)gen_commands.m4
|
||||
|
||||
$(o)cf-parse.y: | $(s)gen_parser.m4
|
||||
$(o)keywords.h: | $(s)gen_keywords.m4
|
||||
$(o)commands.h: | $(s)gen_commands.m4 $(srcdir)/client/cmds.m4
|
||||
$(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,$^) >$@
|
||||
|
||||
$(o)cf-parse.tab.h: $(o)cf-parse.tab.c
|
||||
|
||||
@ -23,11 +23,12 @@ $(o)cf-parse.tab.c: $(o)cf-parse.y
|
||||
$(BISON) $(BISON_DEBUG) $(BISONFLAGS) -dv -pcf_ -b $(@:.tab.c=) $<
|
||||
|
||||
$(o)cf-lex.c: $(s)cf-lex.l
|
||||
$(FLEX) $(FLEX_DEBUG) -s -B -8 -Pcf_ -o$@ $<
|
||||
$(FLEX) $(FLEX_DEBUG) -f -s -B -8 -Pcf_ -o$@ $<
|
||||
|
||||
$(o)cf-lex.o: $(o)cf-parse.tab.h $(o)keywords.h
|
||||
$(o)cf-lex.o: CFLAGS+=-Wno-sign-compare -Wno-unused-function
|
||||
|
||||
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)
|
||||
|
222
conf/cf-lex.l
222
conf/cf-lex.l
@ -45,6 +45,7 @@
|
||||
#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"
|
||||
@ -64,7 +65,7 @@ struct keyword {
|
||||
#endif
|
||||
|
||||
|
||||
static uint cf_hash(byte *c);
|
||||
static uint cf_hash(const byte *c);
|
||||
|
||||
#define KW_KEY(n) n->name
|
||||
#define KW_NEXT(n) n->next
|
||||
@ -87,7 +88,7 @@ HASH_DEFINE_REHASH_FN(SYM, struct symbol)
|
||||
HASH(struct keyword) kw_hash;
|
||||
|
||||
|
||||
static struct sym_scope *conf_this_scope;
|
||||
struct sym_scope *conf_this_scope;
|
||||
|
||||
linpool *cfg_mem;
|
||||
|
||||
@ -95,6 +96,15 @@ int (*cf_read_hook)(byte *buf, unsigned int max, int fd);
|
||||
struct include_file_stack *ifs;
|
||||
static struct include_file_stack *ifs_head;
|
||||
|
||||
#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);
|
||||
@ -105,6 +115,8 @@ static struct include_file_stack *ifs_head;
|
||||
static void cf_include(char *arg, int alen);
|
||||
static int check_eof(void);
|
||||
|
||||
static enum yytokentype cf_lex_symbol(const char *data);
|
||||
|
||||
%}
|
||||
|
||||
%option noyywrap
|
||||
@ -112,24 +124,26 @@ static int check_eof(void);
|
||||
%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} {
|
||||
char *start, *end;
|
||||
|
||||
^{WHITE}*include{WHITE}*\" {
|
||||
if (!ifs->depth)
|
||||
cf_error("Include not allowed in CLI");
|
||||
|
||||
start = strchr(yytext, '"');
|
||||
start++;
|
||||
BEGIN(INCLUDE);
|
||||
}
|
||||
|
||||
<INCLUDE>[^"\n]+["]{WHITE}*; {
|
||||
char *start, *end;
|
||||
|
||||
start = yytext;
|
||||
|
||||
end = strchr(start, '"');
|
||||
*end = 0;
|
||||
@ -138,16 +152,24 @@ include ^{WHITE}*include{WHITE}*\".*\"{WHITE}*;
|
||||
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 = strtoul(yytext, &e, 10);
|
||||
if (e && (*e != ':') || (errno == ERANGE) || (l >> 32))
|
||||
l = bstrtoul10(yytext, &e);
|
||||
if (!e || (*e != ':') || (errno == ERANGE) || (l >> 32))
|
||||
cf_error("ASN out of range");
|
||||
|
||||
if (l >> 16)
|
||||
@ -164,8 +186,8 @@ include ^{WHITE}*include{WHITE}*\".*\"{WHITE}*;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
l = strtoul(e+1, &e, 10);
|
||||
if (e && *e || (errno == ERANGE) || (l >> len2))
|
||||
l = bstrtoul10(e+1, &e);
|
||||
if (!e || *e || (errno == ERANGE) || (l >> len2))
|
||||
cf_error("Number out of range");
|
||||
cf_lval.i64 |= l;
|
||||
|
||||
@ -191,14 +213,14 @@ include ^{WHITE}*include{WHITE}*\".*\"{WHITE}*;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
l = strtoul(yytext+2, &e, 10);
|
||||
if (e && (*e != ':') || (errno == ERANGE) || (l >> len1))
|
||||
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 = strtoul(e+1, &e, 10);
|
||||
if (e && *e || (errno == ERANGE) || (l >> len2))
|
||||
l = bstrtoul10(e+1, &e);
|
||||
if (!e || *e || (errno == ERANGE) || (l >> len2))
|
||||
cf_error("Number out of range");
|
||||
cf_lval.i64 |= l;
|
||||
|
||||
@ -219,8 +241,8 @@ include ^{WHITE}*include{WHITE}*\".*\"{WHITE}*;
|
||||
cf_lval.i64 |= ((u64) ip4_to_u32(ip4)) << 16;
|
||||
|
||||
errno = 0;
|
||||
l = strtoul(e, &e, 10);
|
||||
if (e && *e || (errno == ERANGE) || (l >> 16))
|
||||
l = bstrtoul10(e, &e);
|
||||
if (!e || *e || (errno == ERANGE) || (l >> 16))
|
||||
cf_error("Number out of range");
|
||||
cf_lval.i64 |= l;
|
||||
|
||||
@ -243,8 +265,8 @@ include ^{WHITE}*include{WHITE}*\".*\"{WHITE}*;
|
||||
char *e;
|
||||
unsigned long int l;
|
||||
errno = 0;
|
||||
l = strtoul(yytext+2, &e, 16);
|
||||
if (e && *e || errno == ERANGE || (unsigned long int)(unsigned 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;
|
||||
@ -254,8 +276,8 @@ include ^{WHITE}*include{WHITE}*\".*\"{WHITE}*;
|
||||
char *e;
|
||||
unsigned long int l;
|
||||
errno = 0;
|
||||
l = strtoul(yytext, &e, 10);
|
||||
if (e && *e || errno == ERANGE || (unsigned long int)(unsigned 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;
|
||||
@ -266,26 +288,23 @@ else: {
|
||||
return ELSECOL;
|
||||
}
|
||||
|
||||
({ALPHA}{ALNUM}*|[']({ALNUM}|[-]|[\.]|[:])*[']) {
|
||||
if(*yytext == '\'') {
|
||||
yytext[yyleng-1] = 0;
|
||||
yytext++;
|
||||
}
|
||||
['] {
|
||||
BEGIN(APOSTROPHED);
|
||||
quoted_buffer_init();
|
||||
}
|
||||
|
||||
struct keyword *k = HASH_FIND(kw_hash, KW, yytext);
|
||||
if (k)
|
||||
{
|
||||
if (k->value > 0)
|
||||
return k->value;
|
||||
else
|
||||
{
|
||||
cf_lval.i = -k->value;
|
||||
return ENUM;
|
||||
}
|
||||
}
|
||||
<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");
|
||||
|
||||
cf_lval.s = cf_get_symbol(yytext);
|
||||
return SYM;
|
||||
({ALPHA}{ALNUM}*) {
|
||||
return cf_lex_symbol(yytext);
|
||||
}
|
||||
|
||||
<CLI>(.|\n) {
|
||||
@ -301,14 +320,21 @@ else: {
|
||||
return yytext[0];
|
||||
}
|
||||
|
||||
["][^"\n]*["] {
|
||||
yytext[yyleng-1] = 0;
|
||||
cf_lval.t = cfg_strdup(yytext+1);
|
||||
yytext[yyleng-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; }
|
||||
|
||||
@ -349,7 +375,7 @@ else: {
|
||||
%%
|
||||
|
||||
static uint
|
||||
cf_hash(byte *c)
|
||||
cf_hash(const byte *c)
|
||||
{
|
||||
uint h = 13 << 24;
|
||||
|
||||
@ -358,7 +384,6 @@ cf_hash(byte *c)
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* IFS stack - it contains structures needed for recursive processing
|
||||
* of include in config files. On the top of the stack is a structure
|
||||
@ -519,7 +544,7 @@ check_eof(void)
|
||||
}
|
||||
|
||||
static struct symbol *
|
||||
cf_new_symbol(byte *c)
|
||||
cf_new_symbol(const byte *c)
|
||||
{
|
||||
struct symbol *s;
|
||||
|
||||
@ -527,11 +552,8 @@ cf_new_symbol(byte *c)
|
||||
if (l > SYM_MAX_LEN)
|
||||
cf_error("Symbol too long");
|
||||
|
||||
s = cfg_alloc(sizeof(struct symbol) + l);
|
||||
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)
|
||||
@ -539,6 +561,8 @@ cf_new_symbol(byte *c)
|
||||
|
||||
HASH_INSERT2(new_config->sym_hash, SYM, new_config->pool, s);
|
||||
|
||||
add_tail(&(new_config->symbols), &(s->n));
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
@ -554,7 +578,7 @@ cf_new_symbol(byte *c)
|
||||
* signify no match.
|
||||
*/
|
||||
struct symbol *
|
||||
cf_find_symbol(struct config *cfg, byte *c)
|
||||
cf_find_symbol(const struct config *cfg, const byte *c)
|
||||
{
|
||||
struct symbol *s;
|
||||
|
||||
@ -562,6 +586,7 @@ cf_find_symbol(struct config *cfg, byte *c)
|
||||
(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)))
|
||||
@ -580,11 +605,33 @@ cf_find_symbol(struct config *cfg, byte *c)
|
||||
* existing symbol is found.
|
||||
*/
|
||||
struct symbol *
|
||||
cf_get_symbol(byte *c)
|
||||
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)
|
||||
{
|
||||
@ -604,33 +651,32 @@ 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_symbol(sym->name);
|
||||
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
|
||||
@ -673,7 +719,8 @@ cf_lex_init(int is_cli, struct config *c)
|
||||
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;
|
||||
}
|
||||
|
||||
@ -690,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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -710,6 +758,7 @@ cf_pop_scope(void)
|
||||
{
|
||||
conf_this_scope->active = 0;
|
||||
conf_this_scope = conf_this_scope->next;
|
||||
|
||||
ASSERT(conf_this_scope);
|
||||
}
|
||||
|
||||
@ -723,9 +772,6 @@ cf_pop_scope(void)
|
||||
char *
|
||||
cf_symbol_class_name(struct symbol *sym)
|
||||
{
|
||||
if (cf_symbol_is_constant(sym))
|
||||
return "constant";
|
||||
|
||||
switch (sym->class)
|
||||
{
|
||||
case SYM_VOID:
|
||||
@ -740,6 +786,12 @@ cf_symbol_class_name(struct symbol *sym)
|
||||
return "filter";
|
||||
case SYM_TABLE:
|
||||
return "routing table";
|
||||
case SYM_ATTRIBUTE:
|
||||
return "custom attribute";
|
||||
case SYM_CONSTANT_RANGE:
|
||||
return "constant";
|
||||
case SYM_VARIABLE_RANGE:
|
||||
return "variable";
|
||||
default:
|
||||
return "unknown type";
|
||||
}
|
||||
|
40
conf/conf.c
40
conf/conf.c
@ -55,6 +55,7 @@
|
||||
#include "lib/timer.h"
|
||||
#include "conf/conf.h"
|
||||
#include "filter/filter.h"
|
||||
#include "sysdep/unix/unix.h"
|
||||
|
||||
|
||||
static jmp_buf conf_jmpbuf;
|
||||
@ -98,6 +99,7 @@ config_alloc(const char *name)
|
||||
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;
|
||||
c->mem = l;
|
||||
@ -216,6 +218,14 @@ config_del_obstacle(struct config *c)
|
||||
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;
|
||||
|
||||
@ -258,6 +268,8 @@ config_do_commit(struct config *c, int type)
|
||||
if (old_config)
|
||||
old_config->obstacle_count++;
|
||||
|
||||
DBG("filter_commit\n");
|
||||
filter_commit(c, old_config);
|
||||
DBG("sysdep_commit\n");
|
||||
int force_restart = sysdep_commit(c, old_config);
|
||||
DBG("global_commit\n");
|
||||
@ -444,6 +456,24 @@ config_undo(void)
|
||||
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
|
||||
@ -474,19 +504,24 @@ config_init(void)
|
||||
* 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;
|
||||
@ -547,6 +582,7 @@ cfg_copy_list(list *dest, list *src, unsigned node_size)
|
||||
{
|
||||
dn = cfg_alloc(node_size);
|
||||
memcpy(dn, sn, node_size);
|
||||
memset(dn, 0, sizeof(node));
|
||||
add_tail(dest, dn);
|
||||
}
|
||||
}
|
||||
|
77
conf/conf.h
77
conf/conf.h
@ -24,20 +24,23 @@ struct config {
|
||||
list tables; /* Configured routing tables (struct rtable_config) */
|
||||
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) */
|
||||
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 */
|
||||
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 */
|
||||
@ -52,8 +55,10 @@ struct config {
|
||||
int file_fd; /* File descriptor of main configuration file */
|
||||
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 */
|
||||
int gr_down; /* This is a pseudo-config for graceful restart */
|
||||
btime load_time; /* When we've got this configuration */
|
||||
};
|
||||
|
||||
@ -68,11 +73,13 @@ void config_free(struct config *);
|
||||
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
|
||||
@ -103,18 +110,29 @@ void cfg_copy_list(list *dest, list *src, unsigned node_size);
|
||||
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 */
|
||||
};
|
||||
|
||||
@ -134,8 +152,11 @@ struct sym_scope {
|
||||
#define SYM_CONSTANT 0x200 /* 0x200-0x2ff are variable types */
|
||||
#define SYM_CONSTANT_RANGE SYM_CONSTANT ... (SYM_CONSTANT | 0xff)
|
||||
|
||||
#define SYM_TYPE(s) (((struct f_val *) (s)->def)->type)
|
||||
#define SYM_VAL(s) (((struct f_val *) (s)->def)->val)
|
||||
#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 *buffer; /* Internal lexer state */
|
||||
@ -152,23 +173,43 @@ struct include_file_stack {
|
||||
|
||||
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);
|
||||
void cf_lex_unwind(void);
|
||||
|
||||
struct symbol *cf_find_symbol(struct config *cfg, byte *c);
|
||||
struct symbol *cf_find_symbol(const struct config *cfg, const byte *c);
|
||||
|
||||
struct symbol *cf_get_symbol(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);
|
||||
char *cf_symbol_class_name(struct symbol *sym);
|
||||
|
||||
static inline int cf_symbol_is_constant(struct symbol *sym)
|
||||
{ return (sym->class & 0xff00) == SYM_CONSTANT; }
|
||||
|
||||
|
||||
/* Parser */
|
||||
|
||||
extern char *cf_text;
|
||||
|
@ -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"
|
||||
|
||||
@ -33,6 +34,21 @@ check_u16(uint 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 {
|
||||
@ -45,17 +61,24 @@ CF_DECLS
|
||||
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 {
|
||||
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 filter *f;
|
||||
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;
|
||||
@ -78,7 +101,7 @@ CF_DECLS
|
||||
%token <ip4> IP4
|
||||
%token <ip6> IP6
|
||||
%token <i64> VPN_RD
|
||||
%token <s> SYM
|
||||
%token <s> CF_SYM_KNOWN CF_SYM_UNDEFINED
|
||||
%token <t> TEXT
|
||||
%type <iface> ipa_scope
|
||||
|
||||
@ -90,6 +113,7 @@ CF_DECLS
|
||||
%type <mls> label_stack_start label_stack
|
||||
|
||||
%type <t> text opttext
|
||||
%type <s> symbol
|
||||
|
||||
%nonassoc PREFIX_DUMMY
|
||||
%left AND OR
|
||||
@ -99,6 +123,8 @@ CF_DECLS
|
||||
%left '!'
|
||||
%nonassoc '.'
|
||||
|
||||
%start config
|
||||
|
||||
CF_KEYWORDS(DEFINE, ON, OFF, YES, NO, S, MS, US, PORT, VPN, MPLS, FROM)
|
||||
|
||||
CF_GRAMMAR
|
||||
@ -122,29 +148,29 @@ conf: ';' ;
|
||||
conf: definition ;
|
||||
|
||||
definition:
|
||||
DEFINE SYM '=' term ';' {
|
||||
struct f_val *val = cfg_alloc(sizeof(struct f_val));
|
||||
*val = f_eval($4, cfg_mem);
|
||||
if (val->type == T_RETURN) cf_error("Runtime error");
|
||||
cf_define_symbol($2, SYM_CONSTANT | val->type, val);
|
||||
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_CONSTANT | T_INT)) cf_error("Number expected");
|
||||
| '(' 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_us:
|
||||
expr S { $$ = $1 S_; }
|
||||
| expr MS { $$ = $1 MS_; }
|
||||
| expr US { $$ = $1 US_; }
|
||||
;
|
||||
|
||||
symbol: CF_SYM_UNDEFINED | CF_SYM_KNOWN ;
|
||||
|
||||
/* Switches */
|
||||
|
||||
bool:
|
||||
@ -162,15 +188,15 @@ bool:
|
||||
ipa:
|
||||
IP4 { $$ = ipa_from_ip4($1); }
|
||||
| IP6 { $$ = ipa_from_ip6($1); }
|
||||
| SYM {
|
||||
if ($1->class != (SYM_CONSTANT | T_IP)) cf_error("IP address expected");
|
||||
| CF_SYM_KNOWN {
|
||||
if ($1->class != (SYM_CONSTANT | T_IP)) cf_error("IP address constant expected");
|
||||
$$ = SYM_VAL($1).ip;
|
||||
}
|
||||
;
|
||||
|
||||
ipa_scope:
|
||||
/* empty */ { $$ = NULL; }
|
||||
| '%' SYM { $$ = if_get_by_name($2->name); }
|
||||
| '%' symbol { $$ = if_get_by_name($2->name); }
|
||||
;
|
||||
|
||||
|
||||
@ -277,27 +303,27 @@ net_:
|
||||
|
||||
net_ip6:
|
||||
net_ip6_
|
||||
| SYM {
|
||||
| CF_SYM_KNOWN {
|
||||
if (($1->class != (SYM_CONSTANT | T_NET)) || (SYM_VAL($1).net->type != NET_IP6))
|
||||
cf_error("IPv6 network expected");
|
||||
cf_error("IPv6 network constant expected");
|
||||
$$ = * SYM_VAL($1).net;
|
||||
}
|
||||
;
|
||||
|
||||
net_ip:
|
||||
net_ip_
|
||||
| SYM {
|
||||
| CF_SYM_KNOWN {
|
||||
if (($1->class != (SYM_CONSTANT | T_NET)) || !net_is_ip(SYM_VAL($1).net))
|
||||
cf_error("IP network expected");
|
||||
cf_error("IP network constant expected");
|
||||
$$ = * SYM_VAL($1).net;
|
||||
}
|
||||
;
|
||||
|
||||
net_any:
|
||||
net_
|
||||
| SYM {
|
||||
| CF_SYM_KNOWN {
|
||||
if ($1->class != (SYM_CONSTANT | T_NET))
|
||||
cf_error("Network expected");
|
||||
cf_error("Network constant expected");
|
||||
$$ = (net_addr *) SYM_VAL($1).net; /* Avoid const warning */
|
||||
}
|
||||
;
|
||||
@ -307,13 +333,13 @@ net_or_ipa:
|
||||
| net_ip6_
|
||||
| IP4 { net_fill_ip4(&($$), $1, IP4_MAX_PREFIX_LENGTH); }
|
||||
| IP6 { net_fill_ip6(&($$), $1, IP6_MAX_PREFIX_LENGTH); }
|
||||
| SYM {
|
||||
| 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 expected");
|
||||
cf_error("IP address or network constant expected");
|
||||
}
|
||||
;
|
||||
|
||||
@ -344,8 +370,8 @@ time:
|
||||
|
||||
text:
|
||||
TEXT
|
||||
| SYM {
|
||||
if ($1->class != (SYM_CONSTANT | T_STRING)) cf_error("String expected");
|
||||
| CF_SYM_KNOWN {
|
||||
if ($1->class != (SYM_CONSTANT | T_STRING)) cf_error("String constant expected");
|
||||
$$ = SYM_VAL($1).s;
|
||||
}
|
||||
;
|
||||
|
@ -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(`
|
||||
|
@ -44,6 +44,7 @@ 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(`
|
||||
|
54
configure.ac
54
configure.ac
@ -18,6 +18,18 @@ AC_ARG_ENABLE([debug],
|
||||
[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@:>@])],
|
||||
[],
|
||||
@ -31,7 +43,7 @@ AC_ARG_ENABLE([pthreads],
|
||||
)
|
||||
|
||||
AC_ARG_ENABLE([libssh],
|
||||
[AS_HELP_STRING([--enable-libssh], [enable LibSSH support together with RPKI @<:@try@:>@])],
|
||||
[AS_HELP_STRING([--enable-libssh], [enable LibSSH support in RPKI @<:@try@:>@])],
|
||||
[],
|
||||
[enable_libssh=try]
|
||||
)
|
||||
@ -66,6 +78,9 @@ 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
|
||||
@ -109,6 +124,11 @@ 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
|
||||
|
||||
@ -126,21 +146,35 @@ if test "$enable_pthreads" != no ; then
|
||||
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])
|
||||
BIRD_CHECK_GCC_OPTION([bird_cv_c_option_fno_strict_aliasing], [-fno-strict-aliasing])
|
||||
BIRD_CHECK_GCC_OPTION([bird_cv_c_option_fno_strict_overflow], [-fno-strict-overflow])
|
||||
|
||||
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])
|
||||
BIRD_ADD_GCC_OPTION([bird_cv_c_option_fno_strict_aliasing], [-fno-strict-aliasing])
|
||||
BIRD_ADD_GCC_OPTION([bird_cv_c_option_fno_strict_overflow], [-fno-strict-overflow])
|
||||
fi
|
||||
|
||||
|
||||
AC_MSG_CHECKING([CFLAGS])
|
||||
AC_MSG_RESULT([$CFLAGS])
|
||||
|
||||
AC_MSG_CHECKING([LDFLAGS])
|
||||
AC_MSG_RESULT([$LDFLAGS])
|
||||
|
||||
AC_PROG_CPP
|
||||
AC_PROG_INSTALL
|
||||
@ -156,7 +190,7 @@ 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; then
|
||||
if test "$bird_bison_synclines" = yes && test "$enable_debug_generated" = no; then
|
||||
M4FLAGS="$M4FLAGS -s"
|
||||
fi
|
||||
|
||||
@ -246,7 +280,6 @@ if test "$enable_libssh" != no ; then
|
||||
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"
|
||||
proto_rpki=rpki
|
||||
enable_libssh=yes
|
||||
else
|
||||
if test "$enable_libssh" = yes ; then
|
||||
@ -271,7 +304,7 @@ if test "$enable_mpls_kernel" != no ; then
|
||||
fi
|
||||
fi
|
||||
|
||||
all_protocols="$proto_bfd babel bgp mrt ospf perf pipe radv rip $proto_rpki static"
|
||||
all_protocols="$proto_bfd babel bgp mrt ospf perf pipe radv rip rpki static"
|
||||
|
||||
all_protocols=`echo $all_protocols | sed 's/ /,/g'`
|
||||
|
||||
@ -364,6 +397,10 @@ if test "$enable_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
|
||||
@ -428,6 +465,7 @@ 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])
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* This is an example configuration file for MB-BGP setting
|
||||
* This is an example configuration file for MP-BGP setting
|
||||
*/
|
||||
|
||||
|
||||
|
599
doc/bird.sgml
599
doc/bird.sgml
File diff suppressed because it is too large
Load Diff
@ -33,6 +33,7 @@ Reply codes of BIRD command-line interface
|
||||
0022 Undo scheduled
|
||||
0023 Evaluation of expression
|
||||
0024 Graceful restart status report
|
||||
0025 Graceful restart ordered
|
||||
|
||||
1000 BIRD version
|
||||
1001 Interface list
|
||||
|
@ -34,6 +34,10 @@ $progs = {
|
||||
"GROFFMACRO" => "-ms",
|
||||
"AWK" => "/usr/share/linuxdoc-tools/awkwhich"
|
||||
};
|
||||
|
||||
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}" : "");
|
||||
|
||||
|
@ -34,6 +34,10 @@ $progs = {
|
||||
"GROFFMACRO" => "-ms",
|
||||
"AWK" => "/usr/share/linuxdoc-tools/awkwhich"
|
||||
};
|
||||
|
||||
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}" : "");
|
||||
|
||||
|
@ -34,6 +34,10 @@ $progs = {
|
||||
"GROFFMACRO" => "-ms",
|
||||
"AWK" => "/usr/share/linuxdoc-tools/awkwhich"
|
||||
};
|
||||
|
||||
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}" : "");
|
||||
|
||||
|
@ -1,8 +1,24 @@
|
||||
src := filter.c f-util.c tree.c trie.c
|
||||
src := filter.c data.c f-util.c tree.c trie.c inst-gen.c
|
||||
obj := $(src-o-files)
|
||||
$(all-daemon)
|
||||
$(cf-local)
|
||||
|
||||
#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)
|
||||
|
823
filter/config.Y
823
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
|
@ -10,103 +10,35 @@
|
||||
#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(enum f_instruction_code fi_code)
|
||||
{
|
||||
struct f_inst * ret;
|
||||
ret = cfg_allocz(sizeof(struct f_inst));
|
||||
ret->fi_code = fi_code;
|
||||
ret->lineno = ifs->lino;
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct f_inst *
|
||||
f_new_inst_da(enum f_instruction_code fi_code, struct f_dynamic_attr da)
|
||||
{
|
||||
struct f_inst *ret = f_new_inst(fi_code);
|
||||
ret->aux = (da.f_type << 8) | da.type;
|
||||
ret->a2.i = da.ea_code;
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct f_inst *
|
||||
f_new_inst_sa(enum f_instruction_code fi_code, struct f_static_attr sa)
|
||||
{
|
||||
struct f_inst *ret = f_new_inst(fi_code);
|
||||
ret->aux = sa.f_type;
|
||||
ret->a2.i = sa.sa_code;
|
||||
ret->a1.i = sa.readonly;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate set_dynamic( operation( get_dynamic(), argument ) )
|
||||
*/
|
||||
struct f_inst *
|
||||
f_generate_complex(int operation, int operation_aux, struct f_dynamic_attr da, struct f_inst *argument)
|
||||
{
|
||||
struct f_inst *set_dyn = f_new_inst_da(FI_EA_SET, da),
|
||||
*oper = f_new_inst(operation),
|
||||
*get_dyn = f_new_inst_da(FI_EA_GET, da);
|
||||
|
||||
oper->aux = operation_aux;
|
||||
oper->a1.p = get_dyn;
|
||||
oper->a2.p = argument;
|
||||
|
||||
set_dyn->a1.p = oper;
|
||||
return set_dyn;
|
||||
}
|
||||
|
||||
struct f_inst *
|
||||
f_generate_roa_check(struct rtable_config *table, struct f_inst *prefix, struct f_inst *asn)
|
||||
{
|
||||
struct f_inst_roa_check *ret = cfg_allocz(sizeof(struct f_inst_roa_check));
|
||||
ret->i.fi_code = FI_ROA_CHECK;
|
||||
ret->i.lineno = ifs->lino;
|
||||
ret->i.arg1 = prefix;
|
||||
ret->i.arg2 = asn;
|
||||
/* prefix == NULL <-> asn == NULL */
|
||||
|
||||
if (table->addr_type != NET_ROA4 && table->addr_type != NET_ROA6)
|
||||
cf_error("%s is not a ROA table", table->name);
|
||||
ret->rtc = table;
|
||||
|
||||
return &ret->i;
|
||||
}
|
||||
|
||||
static const char * const f_instruction_name_str[] = {
|
||||
#define F(c,a,b) \
|
||||
[c] = #c,
|
||||
FI__LIST
|
||||
#undef F
|
||||
};
|
||||
|
||||
const char *
|
||||
f_instruction_name(enum f_instruction_code fi)
|
||||
{
|
||||
if (fi < FI__MAX)
|
||||
return f_instruction_name_str[fi];
|
||||
else
|
||||
bug("Got unknown instruction code: %d", fi);
|
||||
}
|
||||
|
||||
char *
|
||||
filter_name(struct filter *filter)
|
||||
filter_name(const struct filter *filter)
|
||||
{
|
||||
if (!filter)
|
||||
return "ACCEPT";
|
||||
else if (filter == FILTER_REJECT)
|
||||
return "REJECT";
|
||||
else if (!filter->name)
|
||||
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
|
||||
|
2003
filter/filter.c
2003
filter/filter.c
File diff suppressed because it is too large
Load Diff
306
filter/filter.h
306
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,279 +12,61 @@
|
||||
|
||||
#include "lib/resource.h"
|
||||
#include "lib/ip.h"
|
||||
#include "lib/macro.h"
|
||||
#include "nest/route.h"
|
||||
#include "nest/attrs.h"
|
||||
|
||||
/* Filter instruction types */
|
||||
|
||||
#define FI__TWOCHAR(a,b) ((a<<8) | b)
|
||||
#define FI__LIST \
|
||||
F(FI_ADD, 0, '+') \
|
||||
F(FI_SUBTRACT, 0, '-') \
|
||||
F(FI_MULTIPLY, 0, '*') \
|
||||
F(FI_DIVIDE, 0, '/') \
|
||||
F(FI_AND, 0, '&') \
|
||||
F(FI_OR, 0, '|') \
|
||||
F(FI_PAIR_CONSTRUCT, 'm', 'p') \
|
||||
F(FI_EC_CONSTRUCT, 'm', 'c') \
|
||||
F(FI_LC_CONSTRUCT, 'm', 'l') \
|
||||
F(FI_PATHMASK_CONSTRUCT, 'm', 'P') \
|
||||
F(FI_NEQ, '!', '=') \
|
||||
F(FI_EQ, '=', '=') \
|
||||
F(FI_LT, 0, '<') \
|
||||
F(FI_LTE, '<', '=') \
|
||||
F(FI_NOT, 0, '!') \
|
||||
F(FI_MATCH, 0, '~') \
|
||||
F(FI_NOT_MATCH, '!', '~') \
|
||||
F(FI_DEFINED, 'd', 'e') \
|
||||
F(FI_TYPE, 0, 'T') \
|
||||
F(FI_IS_V4, 'I', 'i') \
|
||||
F(FI_SET, 0, 's') \
|
||||
F(FI_CONSTANT, 0, 'c') \
|
||||
F(FI_VARIABLE, 0, 'V') \
|
||||
F(FI_CONSTANT_INDIRECT, 0, 'C') \
|
||||
F(FI_PRINT, 0, 'p') \
|
||||
F(FI_CONDITION, 0, '?') \
|
||||
F(FI_NOP, 0, '0') \
|
||||
F(FI_PRINT_AND_DIE, 'p', ',') \
|
||||
F(FI_RTA_GET, 0, 'a') \
|
||||
F(FI_RTA_SET, 'a', 'S') \
|
||||
F(FI_EA_GET, 'e', 'a') \
|
||||
F(FI_EA_SET, 'e', 'S') \
|
||||
F(FI_PREF_GET, 0, 'P') \
|
||||
F(FI_PREF_SET, 'P', 'S') \
|
||||
F(FI_LENGTH, 0, 'L') \
|
||||
F(FI_ROA_MAXLEN, 'R', 'M') \
|
||||
F(FI_ROA_ASN, 'R', 'A') \
|
||||
F(FI_SADR_SRC, 'n', 's') \
|
||||
F(FI_IP, 'c', 'p') \
|
||||
F(FI_ROUTE_DISTINGUISHER, 'R', 'D') \
|
||||
F(FI_AS_PATH_FIRST, 'a', 'f') \
|
||||
F(FI_AS_PATH_LAST, 'a', 'l') \
|
||||
F(FI_AS_PATH_LAST_NAG, 'a', 'L') \
|
||||
F(FI_RETURN, 0, 'r') \
|
||||
F(FI_CALL, 'c', 'a') \
|
||||
F(FI_CLEAR_LOCAL_VARS, 'c', 'V') \
|
||||
F(FI_SWITCH, 'S', 'W') \
|
||||
F(FI_IP_MASK, 'i', 'M') \
|
||||
F(FI_EMPTY, 0, 'E') \
|
||||
F(FI_PATH_PREPEND, 'A', 'p') \
|
||||
F(FI_CLIST_ADD_DEL, 'C', 'a') \
|
||||
F(FI_ROA_CHECK, 'R', 'C') \
|
||||
F(FI_FORMAT, 0, 'F') \
|
||||
F(FI_ASSERT, 'a', 's')
|
||||
|
||||
enum f_instruction_code {
|
||||
#define F(c,a,b) \
|
||||
c,
|
||||
FI__LIST
|
||||
#undef F
|
||||
FI__MAX,
|
||||
} PACKED;
|
||||
|
||||
const char *f_instruction_name(enum f_instruction_code fi);
|
||||
|
||||
struct f_inst { /* Instruction */
|
||||
struct f_inst *next; /* Structure is 16 bytes, anyway */
|
||||
enum f_instruction_code fi_code;
|
||||
u16 aux; /* Extension to instruction code, T_*, EA_*, EAF_* */
|
||||
union {
|
||||
uint i;
|
||||
void *p;
|
||||
} a1; /* The first argument */
|
||||
union {
|
||||
uint i;
|
||||
void *p;
|
||||
} a2; /* The second argument */
|
||||
union {
|
||||
int i;
|
||||
void *p;
|
||||
} a3; /* The third argument */
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
/* Not enough fields in f_inst for three args used by roa_check() */
|
||||
struct f_inst_roa_check {
|
||||
struct f_inst i;
|
||||
struct rtable_config *rtc;
|
||||
};
|
||||
|
||||
struct f_prefix {
|
||||
net_addr net;
|
||||
u8 lo, hi;
|
||||
};
|
||||
|
||||
struct f_val {
|
||||
int type; /* T_* */
|
||||
union {
|
||||
uint i;
|
||||
u64 ec;
|
||||
lcomm lc;
|
||||
ip_addr ip;
|
||||
const net_addr *net;
|
||||
char *s;
|
||||
struct f_tree *t;
|
||||
struct f_trie *ti;
|
||||
struct adata *ad;
|
||||
struct f_path_mask *path_mask;
|
||||
} val;
|
||||
};
|
||||
|
||||
struct f_dynamic_attr {
|
||||
int type;
|
||||
int f_type;
|
||||
int ea_code;
|
||||
};
|
||||
|
||||
struct f_static_attr {
|
||||
int f_type;
|
||||
int sa_code;
|
||||
int readonly;
|
||||
};
|
||||
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(enum f_instruction_code fi_code);
|
||||
struct f_inst *f_new_inst_da(enum f_instruction_code fi_code, struct f_dynamic_attr da);
|
||||
struct f_inst *f_new_inst_sa(enum f_instruction_code fi_code, struct f_static_attr sa);
|
||||
static inline struct f_dynamic_attr 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 */
|
||||
{ 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_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_tree *f_new_tree(void);
|
||||
struct f_inst *f_generate_complex(int operation, int operation_aux, 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);
|
||||
|
||||
|
||||
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);
|
||||
void tree_format(struct f_tree *t, buffer *buf);
|
||||
|
||||
struct f_trie *f_new_trie(linpool *lp, uint node_size);
|
||||
void *trie_add_prefix(struct f_trie *t, const net_addr *n, uint l, uint h);
|
||||
int trie_match_net(struct f_trie *t, const net_addr *n);
|
||||
int trie_same(struct f_trie *t1, struct f_trie *t2);
|
||||
void trie_format(struct f_trie *t, buffer *buf);
|
||||
|
||||
struct ea_list;
|
||||
struct rte;
|
||||
|
||||
int f_run(struct filter *filter, struct rte **rte, struct linpool *tmp_pool, int flags);
|
||||
struct f_val f_eval_rte(struct f_inst *expr, struct rte **rte, struct linpool *tmp_pool);
|
||||
struct f_val f_eval(struct f_inst *expr, struct linpool *tmp_pool);
|
||||
uint f_eval_int(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 val_same(struct f_val v1, struct f_val v2);
|
||||
|
||||
void val_format(struct f_val v, buffer *buf);
|
||||
|
||||
|
||||
#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_UNDEF ((void *) 2) /* Used in BGP */
|
||||
|
||||
/* Type numbers must be in 0..0xff range */
|
||||
#define T_MASK 0xff
|
||||
|
||||
/* 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
|
||||
#define T_ENUM_ROA 0x35
|
||||
#define T_ENUM_NETTYPE 0x36
|
||||
#define T_ENUM_RA_PREFERENCE 0x37
|
||||
|
||||
/* 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_NET 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_EC 0x26 /* Extended community value, u64 */
|
||||
#define T_ECLIST 0x27 /* Extended community list */
|
||||
#define T_LC 0x28 /* Large community value, lcomm */
|
||||
#define T_LCLIST 0x29 /* Large community list */
|
||||
#define T_RD 0x2a /* Route distinguisher for VPN addresses */
|
||||
|
||||
#define T_RETURN 0x40
|
||||
#define T_SET 0x80
|
||||
#define T_PREFIX_SET 0x81
|
||||
|
||||
|
||||
#define SA_FROM 1
|
||||
#define SA_GW 2
|
||||
#define SA_NET 3
|
||||
#define SA_PROTO 4
|
||||
#define SA_SOURCE 5
|
||||
#define SA_SCOPE 6
|
||||
#define SA_DEST 7
|
||||
#define SA_IFNAME 8
|
||||
#define SA_IFINDEX 9
|
||||
|
||||
|
||||
struct f_tree {
|
||||
struct f_tree *left, *right;
|
||||
struct f_val from, to;
|
||||
void *data;
|
||||
};
|
||||
|
||||
struct f_trie_node
|
||||
{
|
||||
ip_addr addr, mask, accept;
|
||||
uint plen;
|
||||
struct f_trie_node *c[2];
|
||||
};
|
||||
|
||||
struct f_trie
|
||||
{
|
||||
linpool *lp;
|
||||
int zero;
|
||||
uint node_size;
|
||||
struct f_trie_node root[0]; /* Root trie node follows */
|
||||
};
|
||||
|
||||
#define NEW_F_VAL struct f_val * val; val = cfg_alloc(sizeof(struct f_val));
|
||||
#define FILTER_REJECT ((struct filter *) 1)
|
||||
#define FILTER_UNDEF ((struct filter *) 2) /* Used in BGP */
|
||||
|
||||
#define FF_SILENT 2 /* Silent filter execution */
|
||||
|
||||
@ -296,15 +79,4 @@ struct custom_attribute {
|
||||
|
||||
struct custom_attribute *ca_lookup(pool *p, const char *name, int ea_type);
|
||||
|
||||
/* Bird Tests */
|
||||
struct f_bt_test_suite {
|
||||
node n; /* Node in config->tests */
|
||||
struct f_inst *fn; /* Root of function */
|
||||
const char *fn_name; /* Name of test */
|
||||
const char *dsc; /* Description */
|
||||
};
|
||||
|
||||
/* Hook for call bt_assert() function in configuration */
|
||||
extern void (*bt_assert_hook)(int result, struct f_inst *assert);
|
||||
|
||||
#endif
|
||||
|
@ -17,44 +17,44 @@
|
||||
#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 struct config *
|
||||
parse_config_file(const void *filename_void)
|
||||
{
|
||||
bt_bird_init();
|
||||
|
||||
size_t fn_size = strlen((const char *) filename_void) + 1;
|
||||
char *filename = alloca(fn_size);
|
||||
strncpy(filename, filename_void, fn_size);
|
||||
|
||||
struct config *c = bt_config_file_parse(filename);
|
||||
bt_bird_cleanup();
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
static int
|
||||
run_function(const void *parsed_fn_def)
|
||||
t_reconfig(void)
|
||||
{
|
||||
/* XXX: const -> non-const */
|
||||
struct f_inst *f = (struct f_inst *) parsed_fn_def;
|
||||
|
||||
linpool *tmp = lp_new_default(&root_pool);
|
||||
struct f_val res = f_eval(f, tmp);
|
||||
rfree(tmp);
|
||||
|
||||
if (res.type == T_RETURN && res.val.i >= F_REJECT)
|
||||
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, struct f_inst *assert)
|
||||
bt_assert_filter(int result, const struct f_line_item *assert)
|
||||
{
|
||||
int bt_suit_case_result = 1;
|
||||
if (!result)
|
||||
@ -64,24 +64,28 @@ bt_assert_filter(int result, struct f_inst *assert)
|
||||
bt_suit_case_result = 0;
|
||||
}
|
||||
|
||||
bt_log_suite_case_result(bt_suit_case_result, "Assertion at line %d (%s)", assert->lineno, (char *) assert->a2.p);
|
||||
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();
|
||||
|
||||
struct config *c = parse_config_file(BT_CONFIG_FILE);
|
||||
bt_assert_hook = bt_assert_filter;
|
||||
|
||||
if (c)
|
||||
{
|
||||
bt_assert_hook = bt_assert_filter;
|
||||
/* Initial test.conf parsing, must be done here */
|
||||
if (!bt_config_file_parse(BT_CONFIG_FILE))
|
||||
abort();
|
||||
|
||||
struct f_bt_test_suite *t;
|
||||
WALK_LIST(t, c->tests)
|
||||
bt_test_suite_base(run_function, t->fn_name, t->fn, BT_FORKING, BT_TIMEOUT, "%s", t->dsc);
|
||||
}
|
||||
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;
|
||||
}
|
110
filter/test.conf
110
filter/test.conf
@ -7,8 +7,7 @@
|
||||
router id 62.168.0.1;
|
||||
|
||||
/* We have to setup any protocol */
|
||||
protocol static { ipv4; }
|
||||
|
||||
protocol device { }
|
||||
|
||||
|
||||
|
||||
@ -25,8 +24,19 @@ function onef(int a)
|
||||
return 1;
|
||||
}
|
||||
|
||||
function twof(int a)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
function oneg(int a)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
bt_test_same(onef, onef, 1);
|
||||
bt_test_same(onef, oneg, 1);
|
||||
bt_test_same(onef, twof, 0);
|
||||
|
||||
/*
|
||||
* Testing boolean expressions
|
||||
@ -53,8 +63,8 @@ bool b;
|
||||
bt_assert(! false && ! false && true);
|
||||
bt_assert(1 < 2 && 1 != 3);
|
||||
bt_assert(true && true && ! false);
|
||||
bt_assert(true || 1+"a");
|
||||
bt_assert(!(false && 1+"a"));
|
||||
# bt_assert(true || 1+"a");
|
||||
# bt_assert(!(false && 1+"a"));
|
||||
bt_assert(!(true && false));
|
||||
}
|
||||
|
||||
@ -62,7 +72,6 @@ bt_test_suite(t_bool, "Testing boolean expressions");
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Testing integers
|
||||
* ----------------
|
||||
@ -126,6 +135,7 @@ int set is;
|
||||
bt_assert(2 ~ [ 1, 2, 3 ]);
|
||||
bt_assert(5 ~ [ 4 .. 7 ]);
|
||||
bt_assert(1 !~ [ 2, 3, 4 ]);
|
||||
bt_assert(999 !~ [ 666, 333 ]);
|
||||
|
||||
is = [ 2, 3, 4, 7..11 ];
|
||||
bt_assert(10 ~ is);
|
||||
@ -370,6 +380,9 @@ function t_enum()
|
||||
{
|
||||
bt_assert(format(RTS_DUMMY) = "(enum 30)0");
|
||||
bt_assert(format(RTS_STATIC) = "(enum 30)1");
|
||||
bt_assert(format(NET_IP4) = "(enum 36)1");
|
||||
bt_assert(format(NET_VPN6) = "(enum 36)4");
|
||||
|
||||
bt_assert(RTS_STATIC ~ [RTS_STATIC, RTS_DEVICE]);
|
||||
bt_assert(RTS_BGP !~ [RTS_STATIC, RTS_DEVICE]);
|
||||
}
|
||||
@ -448,7 +461,8 @@ function t_prefix_set()
|
||||
prefix set pxs;
|
||||
{
|
||||
pxs = [ 1.2.0.0/16, 1.4.0.0/16+, 44.66.88.64/30{24,28}, 12.34.56.0/24{8,16} ];
|
||||
bt_assert(format(pxs) = "[1.2.0.0/112{::0.1.0.0}, 1.4.0.0/112{::0.1.255.255}, 12.34.0.0/112{::1.255.0.0}, 44.66.88.64/124{::1f0}]");
|
||||
bt_assert(format(pxs) = "[1.2.0.0/16{0.1.0.0}, 1.4.0.0/16{0.1.255.255}, 12.34.0.0/16{1.255.0.0}, 44.66.88.64/28{0.0.1.240}]");
|
||||
|
||||
bt_assert(1.2.0.0/16 ~ pxs);
|
||||
bt_assert(1.4.0.0/16 ~ pxs);
|
||||
bt_assert(1.4.0.0/18 ~ pxs);
|
||||
@ -587,11 +601,15 @@ function mkpath(int a; int b)
|
||||
return [= a b 3 2 1 =];
|
||||
}
|
||||
|
||||
define set35 = [3 .. 5];
|
||||
|
||||
function t_path()
|
||||
bgpmask pm1;
|
||||
bgppath p2;
|
||||
int set set12;
|
||||
{
|
||||
pm1 = [= 4 3 2 1 =];
|
||||
set12 = [1, 2];
|
||||
|
||||
bt_assert(format(pm1) = "[= 4 3 2 1 =]");
|
||||
|
||||
@ -616,6 +634,8 @@ bgppath p2;
|
||||
bt_assert(p2 !~ [8, ten..(2*ten)]);
|
||||
bt_assert(p2 ~ [= * 4 3 * 1 =]);
|
||||
bt_assert(p2 ~ [= (3+2) (2*2) 3 2 1 =]);
|
||||
bt_assert(p2 ~ [= 5 [2, 4, 6] 3 [1..2] 1 =]);
|
||||
bt_assert(p2 ~ [= 5 set35 3 set12 set12 =]);
|
||||
bt_assert(p2 ~ mkpath(5, 4));
|
||||
|
||||
bt_assert(p2.len = 5);
|
||||
@ -626,7 +646,6 @@ bgppath p2;
|
||||
bt_assert(delete(p2, 3) = prepend(prepend(prepend(prepend(+empty+, 1), 2), 4), 5));
|
||||
bt_assert(filter(p2, [1..3]) = prepend(prepend(prepend(+empty+, 1), 2), 3));
|
||||
|
||||
pm1 = [= 1 2 * 3 4 5 =];
|
||||
p2 = prepend( + empty +, 5 );
|
||||
p2 = prepend( p2, 4 );
|
||||
p2 = prepend( p2, 3 );
|
||||
@ -634,9 +653,17 @@ bgppath p2;
|
||||
p2 = prepend( p2, 2 );
|
||||
p2 = prepend( p2, 1 );
|
||||
|
||||
bt_assert(p2 ~ pm1);
|
||||
bt_assert(p2 !~ [= 1 2 3 4 5 =]);
|
||||
bt_assert(p2 ~ [= 1 2 * 4 5 =]);
|
||||
bt_assert(p2 ~ [= 1 2 * 3 4 5 =]);
|
||||
bt_assert(p2 ~ [= 1 2 3+ 4 5 =]);
|
||||
bt_assert(p2 ~ [= 1 2 3+ 4+ 5 =]);
|
||||
bt_assert(p2 !~ [= 1 2 3+ 5+ 4 5 =]);
|
||||
bt_assert(p2 !~ [= 1 2 3 3 5+ 4 5 =]);
|
||||
bt_assert(delete(p2, 3) = prepend(prepend(prepend(prepend(+empty+, 5), 4), 2), 1));
|
||||
bt_assert(delete(p2, [4..5]) = prepend(prepend(prepend(prepend(+empty+, 3), 3), 2), 1));
|
||||
|
||||
bt_assert(format([= 1 2+ 3 =]) = "[= 1 2 + 3 =]");
|
||||
}
|
||||
|
||||
bt_test_suite(t_path, "Testing paths");
|
||||
@ -1022,6 +1049,7 @@ rd x;
|
||||
bt_assert(x != 2:12345:20000);
|
||||
bt_assert(!(x > 12345:200010));
|
||||
|
||||
bt_assert(format(0:1:2) = "1:2");
|
||||
bt_assert(format(10.0.0.1:1000) = "10.0.0.1:1000");
|
||||
bt_assert(format(100000:20000) = "100000:20000");
|
||||
bt_assert(format(2:100000:20000) = "100000:20000");
|
||||
@ -1107,6 +1135,11 @@ int i;
|
||||
return 0;
|
||||
}
|
||||
|
||||
function callmeagain(int a; int b; int c)
|
||||
{
|
||||
return a + b + c;
|
||||
}
|
||||
|
||||
function fifteen()
|
||||
{
|
||||
return 15;
|
||||
@ -1123,6 +1156,7 @@ function t_call_function()
|
||||
bt_assert(callme(3, 2) = 6);
|
||||
bt_assert(callme(4, 4) = 16);
|
||||
bt_assert(callme(7, 2) = 14);
|
||||
bt_assert(callmeagain(1, 2, 3) = 6);
|
||||
}
|
||||
|
||||
bt_test_suite(t_call_function, "Testing calling functions");
|
||||
@ -1156,6 +1190,10 @@ bt_test_suite(t_include, "Testing including another config file");
|
||||
function t_if_else()
|
||||
int i;
|
||||
{
|
||||
/* Empty blocks regression test */
|
||||
if true then {}
|
||||
else {}
|
||||
|
||||
if true then
|
||||
bt_assert(true);
|
||||
|
||||
@ -1165,6 +1203,10 @@ int i;
|
||||
bt_assert(true);
|
||||
else
|
||||
bt_assert(false);
|
||||
|
||||
/* Empty blocks regression test */
|
||||
if true then {}
|
||||
else {}
|
||||
}
|
||||
|
||||
bt_test_suite(t_if_else, "Testing if-else statement");
|
||||
@ -1217,7 +1259,7 @@ int j;
|
||||
|
||||
filter roa_filter
|
||||
{
|
||||
if net ~ [ 10.0.0.0/8{16,24}, 2000::/3{16,96} ] then {
|
||||
if net ~ [ 10.0.0.0/8{16,24} ] || net ~ [ 2000::/3{16,96} ] then {
|
||||
accept;
|
||||
}
|
||||
reject;
|
||||
@ -1241,10 +1283,9 @@ protocol static
|
||||
route 2001:0db8:85a3:8a2e::/64 max 96 as 1000;
|
||||
}
|
||||
|
||||
function test_roa_check()
|
||||
function t_roa_check()
|
||||
prefix pfx;
|
||||
{
|
||||
# cannot be tested in __startup(), sorry
|
||||
bt_assert(roa_check(r4, 10.10.0.0/16, 1000) = ROA_UNKNOWN);
|
||||
bt_assert(roa_check(r4, 10.0.0.0/8, 1000) = ROA_UNKNOWN);
|
||||
bt_assert(roa_check(r4, 10.110.0.0/16, 1000) = ROA_VALID);
|
||||
@ -1299,44 +1340,14 @@ prefix pfx;
|
||||
bt_assert(pfx.asn = 1234);
|
||||
}
|
||||
|
||||
bt_test_suite(test_roa_check, "Testing ROA");
|
||||
bt_test_suite(t_roa_check, "Testing ROA");
|
||||
|
||||
/*
|
||||
* Testing Mixed Net Types
|
||||
* -----------------------
|
||||
*/
|
||||
|
||||
function t_mixed_prefix()
|
||||
prefix set pxs;
|
||||
prefix set pxt;
|
||||
{
|
||||
pxs = [ 98.45.0.0/16, 128.128.0.0/12+, 2200::/42-, ::ffff:d000:0/100{98,102}];
|
||||
bt_assert(format(pxs) = "[::/0, ::/2{c000::}, 98.45.0.0/112{::0.1.0.0}, 128.128.0.0/108{::0.31.255.255}, 208.0.0.0/100{::124.0.0.0}, 2200::/42{ffff:ffff:ffc0::}]");
|
||||
bt_assert(::fe00:0:0/88 !~ pxs);
|
||||
bt_assert(::fffe:0:0/95 !~ pxs);
|
||||
bt_assert(::ffff:d800:0/101 ~ pxs);
|
||||
bt_assert(216.0.0.0/5 ~ pxs);
|
||||
bt_assert(212.0.0.0/6 ~ pxs);
|
||||
bt_assert(212.0.0.0/7 !~ pxs);
|
||||
bt_assert(::ffff:8080:8080/121 ~ pxs);
|
||||
bt_assert(::/0 ~ pxs);
|
||||
bt_assert(0.0.0.0/0 !~ pxs);
|
||||
bt_assert(128.135.64.17/32 ~ pxs);
|
||||
|
||||
# pxt = [ 0:1:2 10.1.10.0/24, 0:5:10000 10.1.10.0/24 ];
|
||||
# print pxt;
|
||||
|
||||
bt_assert(format(NET_IP4) = "(enum 36)1"); ## if (net.type = NET_IP4) ...
|
||||
bt_assert(format(NET_VPN6) = "(enum 36)4");
|
||||
bt_assert(format(0:1:2) = "1:2");
|
||||
}
|
||||
|
||||
bt_test_suite(t_mixed_prefix, "Testing mixed net types");
|
||||
|
||||
|
||||
filter vpn_filter
|
||||
{
|
||||
bt_assert(format(net) = "0:1:2 10.1.10.0/24");
|
||||
bt_assert(format(net) = "1:2 10.1.10.0/24");
|
||||
bt_assert(net.type = NET_VPN4);
|
||||
bt_assert(net.type != NET_IP4);
|
||||
bt_assert(net.type != NET_IP6);
|
||||
@ -1347,6 +1358,13 @@ filter vpn_filter
|
||||
NET_IP6: print "IPV6";
|
||||
}
|
||||
|
||||
bt_check_assign(from, 10.20.30.40);
|
||||
bt_check_assign(gw, 55.55.55.44);
|
||||
|
||||
bgp_community.add((3,5));
|
||||
bgp_ext_community.add((ro, 135, 999));
|
||||
bgp_large_community.add((6464156, 89646354, 8675643));
|
||||
|
||||
accept;
|
||||
}
|
||||
|
||||
@ -1358,3 +1376,9 @@ protocol static
|
||||
vpn4 { table v4; import filter vpn_filter; };
|
||||
route 0:1:2 10.1.10.0/24 unreachable;
|
||||
}
|
||||
|
||||
protocol static
|
||||
{
|
||||
ipv6 { import where false; };
|
||||
route fd01::/48 unreachable;
|
||||
}
|
||||
|
@ -43,7 +43,6 @@ protocol static {
|
||||
print scope;
|
||||
if !(scope ~ [ SCOPE_HOST, SCOPE_SITE ]) then {
|
||||
print "Failed in test";
|
||||
quitbird;
|
||||
}
|
||||
|
||||
preference = 15;
|
||||
|
@ -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);
|
||||
@ -56,7 +57,7 @@ build_tree_rec(struct f_tree **buf, int l, int h)
|
||||
static int
|
||||
tree_compare(const void *p1, const void *p2)
|
||||
{
|
||||
return val_compare((* (struct f_tree **) p1)->from, (* (struct f_tree **) p2)->from);
|
||||
return val_compare(&((* (struct f_tree **) p1)->from), &((* (struct f_tree **) p2)->from));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -102,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;
|
||||
}
|
||||
|
||||
@ -119,39 +115,39 @@ 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(struct f_tree *t, buffer *buf)
|
||||
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)
|
||||
val_format(&(t->from), buf);
|
||||
if (val_compare(&(t->from), &(t->to)) != 0)
|
||||
{
|
||||
buffer_puts(buf, "..");
|
||||
val_format(t->to, buf);
|
||||
val_format(&(t->to), buf);
|
||||
}
|
||||
buffer_puts(buf, ", ");
|
||||
|
||||
@ -159,7 +155,7 @@ tree_node_format(struct f_tree *t, buffer *buf)
|
||||
}
|
||||
|
||||
void
|
||||
tree_format(struct f_tree *t, buffer *buf)
|
||||
tree_format(const struct f_tree *t, buffer *buf)
|
||||
{
|
||||
buffer_puts(buf, "[");
|
||||
|
||||
@ -174,3 +170,14 @@ tree_format(struct f_tree *t, buffer *buf)
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "test/bt-utils.h"
|
||||
|
||||
#include "filter/filter.h"
|
||||
#include "filter/data.h"
|
||||
#include "conf/conf.h"
|
||||
|
||||
#define MAX_TREE_HEIGHT 13
|
||||
@ -226,8 +227,8 @@ t_find(void)
|
||||
};
|
||||
for(looking_up_value.val.i = 0; looking_up_value.val.i < nodes_count; looking_up_value.val.i++)
|
||||
{
|
||||
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));
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@ -278,11 +279,11 @@ t_find_ranges(void)
|
||||
|
||||
for(*i = 0; *i <= max_value; *i += (uint)bt_random()/nodes_count)
|
||||
{
|
||||
struct f_tree *found_tree = find_tree(tree, needle);
|
||||
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))
|
||||
(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))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
300
filter/trie.c
300
filter/trie.c
@ -73,12 +73,14 @@
|
||||
#include "lib/string.h"
|
||||
#include "conf/conf.h"
|
||||
#include "filter/filter.h"
|
||||
#include "filter/data.h"
|
||||
|
||||
|
||||
/*
|
||||
* In the trie code, the prefix length is internally treated as for the whole
|
||||
* ip_addr, regardless whether it contains an IPv4 or IPv6 address. Therefore,
|
||||
* remaining definitions make sense.
|
||||
* 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)
|
||||
@ -86,26 +88,30 @@
|
||||
#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
|
||||
* @lp: linear pool to allocate items from
|
||||
* @node_size: node size to be used (&f_trie_node and user data)
|
||||
* @data_size: user data attached to node
|
||||
*/
|
||||
struct f_trie *
|
||||
f_new_trie(linpool *lp, uint node_size)
|
||||
f_new_trie(linpool *lp, uint data_size)
|
||||
{
|
||||
struct f_trie * ret;
|
||||
ret = lp_allocz(lp, sizeof(struct f_trie) + node_size);
|
||||
ret = lp_allocz(lp, sizeof(struct f_trie) + data_size);
|
||||
ret->lp = lp;
|
||||
ret->node_size = node_size;
|
||||
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, t->node_size);
|
||||
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;
|
||||
@ -113,12 +119,51 @@ 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
|
||||
@ -132,21 +177,30 @@ attach_node(struct f_trie_node *parent, struct f_trie_node *child)
|
||||
*
|
||||
* 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.
|
||||
* 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, const net_addr *net, uint l, uint h)
|
||||
{
|
||||
ip_addr px = net_prefix(net);
|
||||
uint plen = net_pxlen(net);
|
||||
ip_addr px;
|
||||
int v4;
|
||||
|
||||
if (net->type == NET_IP4)
|
||||
switch (net->type)
|
||||
{
|
||||
const uint delta = IP6_MAX_PREFIX_LENGTH - IP4_MAX_PREFIX_LENGTH;
|
||||
plen += delta;
|
||||
l += delta;
|
||||
h += delta;
|
||||
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)
|
||||
@ -161,95 +215,136 @@ trie_add_prefix(struct f_trie *t, const net_addr *net, uint l, uint h)
|
||||
ip_addr pmask = ipa_mkmask(plen);
|
||||
ip_addr paddr = ipa_and(px, pmask);
|
||||
struct f_trie_node *o = NULL;
|
||||
struct f_trie_node *n = t->root;
|
||||
struct f_trie_node *n = &t->root;
|
||||
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
static int
|
||||
trie_match_prefix(struct f_trie *t, ip_addr px, uint plen)
|
||||
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_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;
|
||||
}
|
||||
@ -264,22 +359,27 @@ trie_match_prefix(struct f_trie *t, ip_addr px, uint plen)
|
||||
* is such prefix pattern in the trie.
|
||||
*/
|
||||
int
|
||||
trie_match_net(struct f_trie *t, const net_addr *n)
|
||||
trie_match_net(const struct f_trie *t, const net_addr *n)
|
||||
{
|
||||
uint add = 0;
|
||||
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;
|
||||
|
||||
switch (n->type) {
|
||||
case NET_IP4:
|
||||
case NET_VPN4:
|
||||
case NET_ROA4:
|
||||
add = IP6_MAX_PREFIX_LENGTH - IP4_MAX_PREFIX_LENGTH;
|
||||
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;
|
||||
}
|
||||
|
||||
return trie_match_prefix(t, net_prefix(n), net_pxlen(n) + add);
|
||||
}
|
||||
|
||||
static int
|
||||
trie_node_same(struct f_trie_node *t1, struct f_trie_node *t2)
|
||||
trie_node_same4(const struct f_trie_node4 *t1, const struct f_trie_node4 *t2)
|
||||
{
|
||||
if ((t1 == NULL) && (t2 == NULL))
|
||||
return 1;
|
||||
@ -288,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]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -303,22 +420,41 @@ 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_format(struct f_trie_node *t, buffer *buf)
|
||||
trie_node_format4(const struct f_trie_node4 *t, buffer *buf)
|
||||
{
|
||||
if (t == NULL)
|
||||
return;
|
||||
|
||||
if (ipa_nonzero(t->accept))
|
||||
buffer_print(buf, "%I/%d{%I}, ", t->addr, t->plen, t->accept);
|
||||
if (ip4_nonzero(t->accept))
|
||||
buffer_print(buf, "%I4/%d{%I4}, ", t->addr, t->plen, t->accept);
|
||||
|
||||
trie_node_format(t->c[0], buf);
|
||||
trie_node_format(t->c[1], buf);
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -329,13 +465,17 @@ trie_node_format(struct f_trie_node *t, buffer *buf)
|
||||
* Prints the trie to the supplied buffer.
|
||||
*/
|
||||
void
|
||||
trie_format(struct f_trie *t, buffer *buf)
|
||||
trie_format(const struct f_trie *t, buffer *buf)
|
||||
{
|
||||
buffer_puts(buf, "[");
|
||||
|
||||
if (t->zero)
|
||||
buffer_print(buf, "%I/%d, ", IPA_NONE, 0);
|
||||
trie_node_format(t->root, buf);
|
||||
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;
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "test/bt-utils.h"
|
||||
|
||||
#include "filter/filter.h"
|
||||
#include "filter/data.h"
|
||||
#include "conf/conf.h"
|
||||
|
||||
#define TESTS_NUM 10
|
||||
@ -102,7 +103,7 @@ t_match_net(void)
|
||||
{
|
||||
list prefixes; /* of structs f_extended_prefix */
|
||||
init_list(&prefixes);
|
||||
struct f_trie *trie = f_new_trie(config->mem, sizeof(struct f_trie_node));
|
||||
struct f_trie *trie = f_new_trie(config->mem, 0);
|
||||
|
||||
generate_random_ipv6_prefixes(&prefixes);
|
||||
struct f_prefix_node *n;
|
||||
@ -142,8 +143,8 @@ t_trie_same(void)
|
||||
int round;
|
||||
for (round = 0; round < TESTS_NUM*4; round++)
|
||||
{
|
||||
struct f_trie * trie1 = f_new_trie(config->mem, sizeof(struct f_trie_node));
|
||||
struct f_trie * trie2 = f_new_trie(config->mem, sizeof(struct f_trie_node));
|
||||
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);
|
||||
|
@ -1,7 +1,7 @@
|
||||
src := 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 tbf.c timer.c xmalloc.c
|
||||
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 := 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_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)
|
||||
|
@ -38,7 +38,7 @@ struct align_probe { char x; long int y; };
|
||||
#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; })
|
||||
#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); }
|
||||
@ -56,6 +56,13 @@ static inline int u64_cmp(u64 i1, u64 i2)
|
||||
#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)
|
||||
#endif
|
||||
@ -65,6 +72,11 @@ static inline int u64_cmp(u64 i1, u64 i2)
|
||||
#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 */
|
||||
|
||||
@ -151,10 +163,30 @@ void debug(const 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 { 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();
|
||||
}
|
@ -29,4 +29,9 @@ 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
|
||||
|
@ -50,6 +50,8 @@
|
||||
|
||||
#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++)
|
||||
|
||||
|
56
lib/event.c
56
lib/event.c
@ -23,6 +23,7 @@
|
||||
#include "lib/event.h"
|
||||
|
||||
event_list global_event_list;
|
||||
event_list global_work_list;
|
||||
|
||||
inline void
|
||||
ev_postpone(event *e)
|
||||
@ -114,6 +115,22 @@ 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);
|
||||
|
||||
/**
|
||||
@ -136,10 +153,47 @@ ev_run_list(event_list *l)
|
||||
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)
|
||||
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);
|
||||
}
|
||||
|
@ -21,14 +21,17 @@ 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)
|
||||
|
@ -24,24 +24,33 @@ straightforward_fletcher16_compute(const char *data)
|
||||
sum2 = (sum2 + sum1) % 255;
|
||||
}
|
||||
|
||||
return (sum2 << 8) | sum1;
|
||||
sum2 = (sum2 + sum1) % 255;
|
||||
sum2 = (sum2 + sum1) % 255;
|
||||
|
||||
return (sum1 << 8) | sum2;
|
||||
}
|
||||
|
||||
static u16
|
||||
straightforward_fletcher16_checksum(const char *data)
|
||||
{
|
||||
u16 csum;
|
||||
u8 c0,c1,f0,f1;
|
||||
u16 c0,c1,x,y;
|
||||
|
||||
csum = straightforward_fletcher16_compute(data);
|
||||
f0 = csum & 0xff;
|
||||
f1 = (csum >> 8) & 0xff;
|
||||
c0 = 0xff - ((f0 + f1) % 0xff);
|
||||
c1 = 0xff - ((f0 + c0) % 0xff);
|
||||
c0 = (csum >> 8) & 0xff;
|
||||
c1 = csum & 0xff;
|
||||
|
||||
return (c1 << 8) | c0;
|
||||
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_)
|
||||
{
|
||||
@ -53,7 +62,8 @@ test_fletcher16(void *out_, const void *in_, const void *expected_out_)
|
||||
|
||||
fletcher16_init(&ctxt);
|
||||
fletcher16_update(&ctxt, in, strlen(in));
|
||||
put_u16(out, fletcher16_compute(&ctxt));
|
||||
fletcher16_update(&ctxt, zero16, 2);
|
||||
*out = fletcher16_compute(&ctxt);
|
||||
|
||||
return *out == *expected_out;
|
||||
}
|
||||
@ -70,7 +80,8 @@ test_fletcher16_checksum(void *out_, const void *in_, const void *expected_out_)
|
||||
|
||||
fletcher16_init(&ctxt);
|
||||
fletcher16_update(&ctxt, in, len);
|
||||
put_u16(out, fletcher16_final(&ctxt, len, len));
|
||||
fletcher16_update(&ctxt, zero16, 2);
|
||||
*out = fletcher16_final(&ctxt, len+2, len);
|
||||
|
||||
return *out == *expected_out;
|
||||
}
|
||||
@ -81,7 +92,7 @@ t_fletcher16_compute(void)
|
||||
struct bt_pair test_vectors[] = {
|
||||
{
|
||||
.in = "\001\002",
|
||||
.out = & (const u16) { 0x0403 },
|
||||
.out = & ((const u16) { straightforward_fletcher16_compute("\001\002") }),
|
||||
},
|
||||
{
|
||||
.in = "",
|
||||
|
113
lib/flowspec.c
113
lib/flowspec.c
@ -112,7 +112,6 @@ get_value_length(const byte *op)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Flowspec iterators
|
||||
*/
|
||||
@ -244,6 +243,69 @@ flow6_next_part(const byte *pos, const byte *end)
|
||||
return flow_next_part(pos, end, 1);
|
||||
}
|
||||
|
||||
static const byte *
|
||||
flow_get_part(const byte *data, uint dlen, uint type, int ipv6)
|
||||
{
|
||||
const byte *part;
|
||||
|
||||
for (part = flow_first_part(data);
|
||||
part && (part[0] <= type);
|
||||
part = flow_next_part(part, data+dlen, ipv6))
|
||||
if (part[0] == type)
|
||||
return part;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const byte *
|
||||
flow4_get_part(const net_addr_flow4 *f, uint type)
|
||||
{
|
||||
return flow_get_part(f->data, f->length - sizeof(net_addr_flow4), type, 0);
|
||||
}
|
||||
|
||||
const byte *
|
||||
flow6_get_part(const net_addr_flow6 *f, uint type)
|
||||
{
|
||||
return flow_get_part(f->data, f->length - sizeof(net_addr_flow6), type, 1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Flowspec accessors
|
||||
*/
|
||||
|
||||
static inline ip4_addr
|
||||
flow_read_ip4(const byte *px, uint pxlen)
|
||||
{
|
||||
ip4_addr ip = IP4_NONE;
|
||||
memcpy(&ip, px, BYTES(pxlen));
|
||||
return ip4_ntoh(ip);
|
||||
}
|
||||
|
||||
ip4_addr
|
||||
flow_read_ip4_part(const byte *part)
|
||||
{
|
||||
return flow_read_ip4(part + 2, part[1]);
|
||||
}
|
||||
|
||||
static inline ip6_addr
|
||||
flow_read_ip6(const byte *px, uint pxlen, uint pxoffset)
|
||||
{
|
||||
uint floor_offset = BYTES(pxoffset - (pxoffset % 8));
|
||||
uint ceil_len = BYTES(pxlen);
|
||||
ip6_addr ip = IP6_NONE;
|
||||
|
||||
memcpy(((byte *) &ip) + floor_offset, px, ceil_len - floor_offset);
|
||||
|
||||
return ip6_ntoh(ip);
|
||||
}
|
||||
|
||||
ip6_addr
|
||||
flow_read_ip6_part(const byte *part)
|
||||
{
|
||||
return flow_read_ip6(part + 3, part[1], part[2]);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Flowspec validation
|
||||
@ -374,7 +436,6 @@ flow_validate(const byte *nlri, uint len, int ipv6)
|
||||
enum flow_type type = 0;
|
||||
const byte *pos = nlri;
|
||||
const byte *end = nlri + len;
|
||||
int met_dst_pfx = 0;
|
||||
|
||||
while (pos < end)
|
||||
{
|
||||
@ -386,8 +447,6 @@ flow_validate(const byte *nlri, uint len, int ipv6)
|
||||
switch (type)
|
||||
{
|
||||
case FLOW_TYPE_DST_PREFIX:
|
||||
met_dst_pfx = 1;
|
||||
/* Fall through */
|
||||
case FLOW_TYPE_SRC_PREFIX:
|
||||
{
|
||||
uint pxlen = *pos++;
|
||||
@ -494,9 +553,6 @@ flow_validate(const byte *nlri, uint len, int ipv6)
|
||||
if (pos != end)
|
||||
return FLOW_ST_NOT_COMPLETE;
|
||||
|
||||
if (!ipv6 && !met_dst_pfx)
|
||||
return FLOW_ST_DEST_PREFIX_REQUIRED;
|
||||
|
||||
return FLOW_ST_VALID;
|
||||
}
|
||||
|
||||
@ -779,26 +835,6 @@ flow_builder_set_type(struct flow_builder *fb, enum flow_type type)
|
||||
fb->this_type = type;
|
||||
}
|
||||
|
||||
static ip4_addr
|
||||
flow_read_ip4(const byte *px, uint pxlen)
|
||||
{
|
||||
ip4_addr ip = IP4_NONE;
|
||||
memcpy(&ip, px, BYTES(pxlen));
|
||||
return ip4_ntoh(ip);
|
||||
}
|
||||
|
||||
static ip6_addr
|
||||
flow_read_ip6(const byte *px, uint pxlen, uint pxoffset)
|
||||
{
|
||||
uint floor_offset = BYTES(pxoffset - (pxoffset % 8));
|
||||
uint ceil_len = BYTES(pxlen);
|
||||
ip6_addr ip = IP6_NONE;
|
||||
|
||||
memcpy(((byte *) &ip) + floor_offset, px, ceil_len - floor_offset);
|
||||
|
||||
return ip6_ntoh(ip);
|
||||
}
|
||||
|
||||
static void
|
||||
builder_write_parts(struct flow_builder *fb, byte *buf)
|
||||
{
|
||||
@ -831,9 +867,9 @@ flow_builder4_finalize(struct flow_builder *fb, linpool *lpool)
|
||||
|
||||
if (fb->parts[FLOW_TYPE_DST_PREFIX].length)
|
||||
{
|
||||
byte *p = fb->data.data + fb->parts[FLOW_TYPE_DST_PREFIX].offset + 1;
|
||||
pxlen = *p++;
|
||||
prefix = flow_read_ip4(p, pxlen);
|
||||
byte *part = fb->data.data + fb->parts[FLOW_TYPE_DST_PREFIX].offset;
|
||||
prefix = flow_read_ip4_part(part);
|
||||
pxlen = flow_read_pxlen(part);
|
||||
}
|
||||
*f = NET_ADDR_FLOW4(prefix, pxlen, data_len);
|
||||
|
||||
@ -861,10 +897,9 @@ flow_builder6_finalize(struct flow_builder *fb, linpool *lpool)
|
||||
|
||||
if (fb->parts[FLOW_TYPE_DST_PREFIX].length)
|
||||
{
|
||||
byte *p = fb->data.data + fb->parts[FLOW_TYPE_DST_PREFIX].offset + 1;
|
||||
pxlen = *p++;
|
||||
uint pxoffset = *p++;
|
||||
prefix = flow_read_ip6(p, pxlen, pxoffset);
|
||||
byte *part = fb->data.data + fb->parts[FLOW_TYPE_DST_PREFIX].offset;
|
||||
prefix = flow_read_ip6_part(part);
|
||||
pxlen = flow_read_pxlen(part);
|
||||
}
|
||||
*n = NET_ADDR_FLOW6(prefix, pxlen, data_len);
|
||||
|
||||
@ -947,18 +982,18 @@ fragment_val_str(u8 val)
|
||||
static void
|
||||
net_format_flow_ip(buffer *b, const byte *part, int ipv6)
|
||||
{
|
||||
uint pxlen = *(part+1);
|
||||
uint pxlen = part[1];
|
||||
if (ipv6)
|
||||
{
|
||||
uint pxoffset = *(part+2);
|
||||
uint pxoffset = part[2];
|
||||
if (pxoffset)
|
||||
buffer_print(b, "%I6/%u offset %u; ", flow_read_ip6(part+3,pxlen,pxoffset), pxlen, pxoffset);
|
||||
buffer_print(b, "%I6/%u offset %u; ", flow_read_ip6_part(part), pxlen, pxoffset);
|
||||
else
|
||||
buffer_print(b, "%I6/%u; ", flow_read_ip6(part+3,pxlen,0), pxlen);
|
||||
buffer_print(b, "%I6/%u; ", flow_read_ip6_part(part), pxlen);
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer_print(b, "%I4/%u; ", flow_read_ip4(part+2,pxlen), pxlen);
|
||||
buffer_print(b, "%I4/%u; ", flow_read_ip4_part(part), pxlen);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,6 +83,17 @@ 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]; }
|
||||
|
||||
|
||||
/*
|
||||
|
@ -137,7 +137,7 @@ static int
|
||||
t_iterators6(void)
|
||||
{
|
||||
net_addr_flow6 *f;
|
||||
NET_ADDR_FLOW6_(f, ip6_build(0,0,0x12345678,0x9a000000), 64, ((byte[]) {
|
||||
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,
|
||||
@ -166,6 +166,56 @@ t_iterators6(void)
|
||||
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)
|
||||
{
|
||||
@ -179,11 +229,9 @@ t_validation4(void)
|
||||
FLOW_TYPE_TCP_FLAGS, 0x80, 0x55,
|
||||
};
|
||||
|
||||
/* Isn't included destination prefix */
|
||||
/* Empty NLRI */
|
||||
res = flow4_validate(nlri1, 0);
|
||||
bt_assert(res == FLOW_ST_DEST_PREFIX_REQUIRED);
|
||||
res = flow4_validate(&nlri1[5], sizeof(nlri1)-5);
|
||||
bt_assert(res == FLOW_ST_DEST_PREFIX_REQUIRED);
|
||||
bt_assert(res == FLOW_ST_VALID);
|
||||
|
||||
/* Valid / Not Complete testing */
|
||||
uint valid_sizes[] = {5, 11, 14, 22, 25, 0};
|
||||
@ -628,6 +676,8 @@ main(int argc, char *argv[])
|
||||
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)");
|
||||
|
7
lib/ip.c
7
lib/ip.c
@ -245,7 +245,7 @@ ip4_pton(const char *a, ip4_addr *o)
|
||||
char *d, *c = strchr(a, '.');
|
||||
if (!c != !i)
|
||||
return 0;
|
||||
l = strtoul(a, &d, 10);
|
||||
l = bstrtoul10(a, &d);
|
||||
if (((d != c) && *d) || (l > 255))
|
||||
return 0;
|
||||
ia = (ia << 8) | l;
|
||||
@ -264,6 +264,9 @@ ip6_pton(const char *a, ip6_addr *o)
|
||||
int i, j, k, l, hfil;
|
||||
const char *start;
|
||||
|
||||
if (!a[0]) /* Empty string check */
|
||||
return 0;
|
||||
|
||||
if (a[0] == ':') /* Leading :: */
|
||||
{
|
||||
if (a[1] != ':')
|
||||
@ -333,6 +336,8 @@ ip6_pton(const char *a, ip6_addr *o)
|
||||
for (; i>=hfil; i--)
|
||||
words[i] = 0;
|
||||
}
|
||||
else if (i != 8) /* Incomplete address */
|
||||
return 0;
|
||||
|
||||
/* Convert the address to ip6_addr format */
|
||||
for (i=0; i<4; i++)
|
||||
|
11
lib/ip.h
11
lib/ip.h
@ -48,6 +48,13 @@
|
||||
#define UDP_HEADER_LENGTH 8
|
||||
|
||||
|
||||
/* IANA Address Family Numbers */
|
||||
/* https://www.iana.org/assignments/address-family-numbers/address-family-numbers.xhtml */
|
||||
/* Would use AF_ prefix, but that collides with POSIX address family numbers */
|
||||
#define AFI_IPV4 1
|
||||
#define AFI_IPV6 2
|
||||
|
||||
|
||||
#ifdef DEBUGGING
|
||||
|
||||
typedef struct ip4_addr {
|
||||
@ -354,12 +361,12 @@ mpls_put(char *buf, int len, u32 *stack)
|
||||
* Unaligned data access (in network order)
|
||||
*/
|
||||
|
||||
static inline ip4_addr get_ip4(void *buf)
|
||||
static inline ip4_addr get_ip4(const void *buf)
|
||||
{
|
||||
return _MI4(get_u32(buf));
|
||||
}
|
||||
|
||||
static inline ip6_addr get_ip6(void *buf)
|
||||
static inline ip6_addr get_ip6(const void *buf)
|
||||
{
|
||||
ip6_addr a;
|
||||
memcpy(&a, buf, 16);
|
||||
|
@ -13,25 +13,38 @@
|
||||
#define IP4_MAX_LEN 16
|
||||
|
||||
static int
|
||||
test_ipa_pton(void *out_, const void *in_, const void *expected_out_)
|
||||
test_ip4_pton(void *out_, const void *in_, const void *expected_out_)
|
||||
{
|
||||
ip_addr *out = out_;
|
||||
const char *in = in_;
|
||||
const ip_addr *expected_out = expected_out_;
|
||||
ip4_addr ip4;
|
||||
|
||||
if (expected_out)
|
||||
{
|
||||
bt_assert(ip4_pton(in, &ip4));
|
||||
*out = ipa_from_ip4(ip4);
|
||||
return ipa_equal(*out, *expected_out);
|
||||
}
|
||||
else
|
||||
return !ip4_pton(in, &ip4);
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
test_ip6_pton(void *out_, const void *in_, const void *expected_out_)
|
||||
{
|
||||
ip_addr *out = out_;
|
||||
const char *in = in_;
|
||||
const ip_addr *expected_out = expected_out_;
|
||||
|
||||
if (ipa_is_ip4(*expected_out))
|
||||
{
|
||||
ip4_addr ip4;
|
||||
bt_assert(ip4_pton(in, &ip4));
|
||||
*out = ipa_from_ip4(ip4);
|
||||
}
|
||||
else
|
||||
if (expected_out)
|
||||
{
|
||||
bt_assert(ip6_pton(in, out));
|
||||
/* ip_addr == ip6_addr */
|
||||
return ipa_equal(*out, *expected_out);
|
||||
}
|
||||
|
||||
return ipa_equal(*out, *expected_out);
|
||||
else
|
||||
return !ip6_pton(in, out);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -52,7 +65,7 @@ t_ip4_pton(void)
|
||||
},
|
||||
};
|
||||
|
||||
return bt_assert_batch(test_vectors, test_ipa_pton, bt_fmt_str, bt_fmt_ipa);
|
||||
return bt_assert_batch(test_vectors, test_ip4_pton, bt_fmt_str, bt_fmt_ipa);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -87,9 +100,17 @@ t_ip6_pton(void)
|
||||
.in = "2605:2700:0:3::4713:93e3",
|
||||
.out = & ipa_build6(0x26052700, 0x00000003, 0x00000000, 0x471393E3),
|
||||
},
|
||||
{
|
||||
.in = "2605:2700:0:3:4713:93e3",
|
||||
.out = NULL,
|
||||
},
|
||||
{
|
||||
.in = "2",
|
||||
.out = NULL,
|
||||
},
|
||||
};
|
||||
|
||||
return bt_assert_batch(test_vectors, test_ipa_pton, bt_fmt_str, bt_fmt_ipa);
|
||||
return bt_assert_batch(test_vectors, test_ip6_pton, bt_fmt_str, bt_fmt_ipa);
|
||||
}
|
||||
|
||||
static int
|
||||
|
79
lib/lists.c
79
lib/lists.c
@ -29,6 +29,42 @@
|
||||
#include "nest/bird.h"
|
||||
#include "lib/lists.h"
|
||||
|
||||
LIST_INLINE int
|
||||
check_list(list *l, node *n)
|
||||
{
|
||||
if (!l)
|
||||
{
|
||||
ASSERT_DIE(n);
|
||||
ASSERT_DIE(n->prev);
|
||||
|
||||
do { n = n->prev; } while (n->prev);
|
||||
|
||||
l = SKIP_BACK(list, head_node, n);
|
||||
}
|
||||
|
||||
int seen = 0;
|
||||
|
||||
ASSERT_DIE(l->null == NULL);
|
||||
ASSERT_DIE(l->head != NULL);
|
||||
ASSERT_DIE(l->tail != NULL);
|
||||
|
||||
node *prev = &l->head_node, *cur = l->head, *next = l->head->next;
|
||||
while (next)
|
||||
{
|
||||
if (cur == n)
|
||||
seen++;
|
||||
ASSERT_DIE(cur->prev == prev);
|
||||
prev = cur;
|
||||
cur = next;
|
||||
next = next->next;
|
||||
}
|
||||
|
||||
ASSERT_DIE(cur == &(l->tail_node));
|
||||
ASSERT_DIE(!n || (seen == 1));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* add_tail - append a node to a list
|
||||
* @l: linked list
|
||||
@ -39,6 +75,10 @@
|
||||
LIST_INLINE void
|
||||
add_tail(list *l, node *n)
|
||||
{
|
||||
EXPENSIVE_CHECK(check_list(l, NULL));
|
||||
ASSUME(n->prev == NULL);
|
||||
ASSUME(n->next == NULL);
|
||||
|
||||
node *z = l->tail;
|
||||
|
||||
n->next = &l->tail_node;
|
||||
@ -57,6 +97,10 @@ add_tail(list *l, node *n)
|
||||
LIST_INLINE void
|
||||
add_head(list *l, node *n)
|
||||
{
|
||||
EXPENSIVE_CHECK(check_list(l, NULL));
|
||||
ASSUME(n->prev == NULL);
|
||||
ASSUME(n->next == NULL);
|
||||
|
||||
node *z = l->head;
|
||||
|
||||
n->next = z;
|
||||
@ -76,6 +120,10 @@ add_head(list *l, node *n)
|
||||
LIST_INLINE void
|
||||
insert_node(node *n, node *after)
|
||||
{
|
||||
EXPENSIVE_CHECK(check_list(l, after));
|
||||
ASSUME(n->prev == NULL);
|
||||
ASSUME(n->next == NULL);
|
||||
|
||||
node *z = after->next;
|
||||
|
||||
n->next = z;
|
||||
@ -93,6 +141,8 @@ insert_node(node *n, node *after)
|
||||
LIST_INLINE void
|
||||
rem_node(node *n)
|
||||
{
|
||||
EXPENSIVE_CHECK(check_list(NULL, n));
|
||||
|
||||
node *z = n->prev;
|
||||
node *x = n->next;
|
||||
|
||||
@ -103,24 +153,20 @@ rem_node(node *n)
|
||||
}
|
||||
|
||||
/**
|
||||
* replace_node - replace a node in a list with another one
|
||||
* @old: node to be removed
|
||||
* @new: node to be inserted
|
||||
* update_node - update node after calling realloc on it
|
||||
* @n: node to be updated
|
||||
*
|
||||
* Replaces node @old in the list it's linked in with node @new. Node
|
||||
* @old may be a copy of the original node, which is not accessed
|
||||
* through the list. The function could be called with @old == @new,
|
||||
* which just fixes neighbors' pointers in the case that the node
|
||||
* was reallocated.
|
||||
* Fixes neighbor pointers.
|
||||
*/
|
||||
LIST_INLINE void
|
||||
replace_node(node *old, node *new)
|
||||
update_node(node *n)
|
||||
{
|
||||
old->next->prev = new;
|
||||
old->prev->next = new;
|
||||
ASSUME(n->next->prev == n->prev->next);
|
||||
|
||||
new->prev = old->prev;
|
||||
new->next = old->next;
|
||||
n->next->prev = n;
|
||||
n->prev->next = n;
|
||||
|
||||
EXPENSIVE_CHECK(check_list(NULL, n));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -149,6 +195,9 @@ init_list(list *l)
|
||||
LIST_INLINE void
|
||||
add_tail_list(list *to, list *l)
|
||||
{
|
||||
EXPENSIVE_CHECK(check_list(to, NULL));
|
||||
EXPENSIVE_CHECK(check_list(l, NULL));
|
||||
|
||||
node *p = to->tail;
|
||||
node *q = l->head;
|
||||
|
||||
@ -157,6 +206,8 @@ add_tail_list(list *to, list *l)
|
||||
q = l->tail;
|
||||
q->next = &to->tail_node;
|
||||
to->tail = q;
|
||||
|
||||
EXPENSIVE_CHECK(check_list(to, NULL));
|
||||
}
|
||||
|
||||
LIST_INLINE uint
|
||||
@ -165,6 +216,8 @@ list_length(list *l)
|
||||
uint len = 0;
|
||||
node *n;
|
||||
|
||||
EXPENSIVE_CHECK(check_list(l, NULL));
|
||||
|
||||
WALK_LIST(n, *l)
|
||||
len++;
|
||||
|
||||
|
@ -222,26 +222,29 @@ t_remove_node(void)
|
||||
}
|
||||
|
||||
static int
|
||||
t_replace_node(void)
|
||||
t_update_node(void)
|
||||
{
|
||||
node head, inside, tail;
|
||||
|
||||
init_list_();
|
||||
fill_list();
|
||||
|
||||
replace_node(&nodes[0], &head);
|
||||
head = nodes[0];
|
||||
update_node(&head);
|
||||
bt_assert(l.head == &head);
|
||||
bt_assert(head.prev == NODE &l.head);
|
||||
bt_assert(head.next == &nodes[1]);
|
||||
bt_assert(nodes[1].prev == &head);
|
||||
|
||||
replace_node(&nodes[MAX_NUM/2], &inside);
|
||||
inside = nodes[MAX_NUM/2];
|
||||
update_node(&inside);
|
||||
bt_assert(nodes[MAX_NUM/2-1].next == &inside);
|
||||
bt_assert(nodes[MAX_NUM/2+1].prev == &inside);
|
||||
bt_assert(inside.prev == &nodes[MAX_NUM/2-1]);
|
||||
bt_assert(inside.next == &nodes[MAX_NUM/2+1]);
|
||||
|
||||
replace_node(&nodes[MAX_NUM-1], &tail);
|
||||
tail = nodes[MAX_NUM-1];
|
||||
update_node(&tail);
|
||||
bt_assert(l.tail == &tail);
|
||||
bt_assert(tail.prev == &nodes[MAX_NUM-2]);
|
||||
bt_assert(tail.next == NODE &l.null);
|
||||
@ -280,7 +283,7 @@ main(int argc, char *argv[])
|
||||
bt_test_suite(t_add_head, "Adding nodes to head of list");
|
||||
bt_test_suite(t_insert_node, "Inserting nodes to list");
|
||||
bt_test_suite(t_remove_node, "Removing nodes from list");
|
||||
bt_test_suite(t_replace_node, "Replacing nodes in list");
|
||||
bt_test_suite(t_update_node, "Updating nodes in list");
|
||||
bt_test_suite(t_add_tail_list, "At the tail of a list adding the another list");
|
||||
|
||||
return bt_exit_value();
|
||||
|
@ -174,10 +174,10 @@ extern const u16 net_max_text_length[];
|
||||
((net_addr_roa6) { NET_ROA6, pxlen, sizeof(net_addr_roa6), prefix, max_pxlen, asn })
|
||||
|
||||
#define NET_ADDR_FLOW4(prefix,pxlen,dlen) \
|
||||
((net_addr_flow4) { NET_FLOW4, pxlen, sizeof(net_addr_ip4) + dlen, prefix })
|
||||
((net_addr_flow4) { NET_FLOW4, pxlen, sizeof(net_addr_flow4) + dlen, prefix })
|
||||
|
||||
#define NET_ADDR_FLOW6(prefix,pxlen,dlen) \
|
||||
((net_addr_flow6) { NET_FLOW6, pxlen, sizeof(net_addr_ip6) + dlen, prefix })
|
||||
((net_addr_flow6) { NET_FLOW6, pxlen, sizeof(net_addr_flow6) + dlen, prefix })
|
||||
|
||||
#define NET_ADDR_IP6_SADR(dst_prefix,dst_pxlen,src_prefix,src_pxlen) \
|
||||
((net_addr_ip6_sadr) { NET_IP6_SADR, dst_pxlen, sizeof(net_addr_ip6_sadr), dst_prefix, src_pxlen, src_prefix })
|
||||
|
81
lib/printf.c
81
lib/printf.c
@ -34,13 +34,7 @@ static int skip_atoi(const char **s)
|
||||
#define SPECIAL 32 /* 0x */
|
||||
#define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */
|
||||
|
||||
#define do_div(n,base) ({ \
|
||||
int __res; \
|
||||
__res = ((unsigned long) n) % (unsigned) base; \
|
||||
n = ((unsigned long) n) / (unsigned) base; \
|
||||
__res; })
|
||||
|
||||
static char * number(char * str, long num, int base, int size, int precision,
|
||||
static char * number(char * str, u64 num, uint base, int size, int precision,
|
||||
int type, int remains)
|
||||
{
|
||||
char c,sign,tmp[66];
|
||||
@ -58,7 +52,7 @@ static char * number(char * str, long num, int base, int size, int precision,
|
||||
c = (type & ZEROPAD) ? '0' : ' ';
|
||||
sign = 0;
|
||||
if (type & SIGN) {
|
||||
if (num < 0) {
|
||||
if (num > (u64) INT64_MAX) {
|
||||
sign = '-';
|
||||
num = -num;
|
||||
size--;
|
||||
@ -79,8 +73,11 @@ static char * number(char * str, long num, int base, int size, int precision,
|
||||
i = 0;
|
||||
if (num == 0)
|
||||
tmp[i++]='0';
|
||||
else while (num != 0)
|
||||
tmp[i++] = digits[do_div(num,base)];
|
||||
else while (num != 0) {
|
||||
uint res = num % base;
|
||||
num = num / base;
|
||||
tmp[i++] = digits[res];
|
||||
}
|
||||
if (i > precision)
|
||||
precision = i;
|
||||
size -= precision;
|
||||
@ -128,16 +125,17 @@ static char * number(char * str, long num, int base, int size, int precision,
|
||||
* value printed as eight :-separated octets), |%t| for time values (btime) with
|
||||
* specified subsecond precision, and |%m| resp. |%M| for error messages (uses
|
||||
* strerror() to translate @errno code to message text). On the other hand, it
|
||||
* doesn't support floating point numbers.
|
||||
* doesn't support floating point numbers. The bvsnprintf() supports |%h| and
|
||||
* |%l| qualifiers, but |%l| is used for s64/u64 instead of long/ulong.
|
||||
*
|
||||
* Result: number of characters of the output string or -1 if
|
||||
* the buffer space was insufficient.
|
||||
*/
|
||||
int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
|
||||
{
|
||||
int len;
|
||||
unsigned long num;
|
||||
int i, base;
|
||||
int len, i;
|
||||
u64 num;
|
||||
uint base;
|
||||
u32 x;
|
||||
u64 X;
|
||||
btime t;
|
||||
@ -152,7 +150,7 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
|
||||
int field_width; /* width of output field */
|
||||
int precision; /* min. # of digits for integers; max
|
||||
number of chars for from string */
|
||||
int qualifier; /* 'h', 'l', or 'L' for integer fields */
|
||||
int qualifier; /* 'h' or 'l' for integer fields */
|
||||
|
||||
for (start=str=buf ; *fmt ; ++fmt, size-=(str-start), start=str) {
|
||||
if (*fmt != '%') {
|
||||
@ -286,16 +284,15 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
|
||||
field_width = 2*sizeof(void *);
|
||||
flags |= ZEROPAD;
|
||||
}
|
||||
str = number(str,
|
||||
(unsigned long) va_arg(args, void *), 16,
|
||||
field_width, precision, flags, size);
|
||||
str = number(str, (uintptr_t) va_arg(args, void *), 16,
|
||||
field_width, precision, flags, size);
|
||||
if (!str)
|
||||
return -1;
|
||||
continue;
|
||||
|
||||
case 'n':
|
||||
if (qualifier == 'l') {
|
||||
long * ip = va_arg(args, long *);
|
||||
s64 * ip = va_arg(args, s64 *);
|
||||
*ip = (str - buf);
|
||||
} else {
|
||||
int * ip = va_arg(args, int *);
|
||||
@ -356,14 +353,14 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
|
||||
if (qualifier == 'l') {
|
||||
X = va_arg(args, u64);
|
||||
bsprintf(ipbuf, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
((X >> 56) & 0xff),
|
||||
((X >> 48) & 0xff),
|
||||
((X >> 40) & 0xff),
|
||||
((X >> 32) & 0xff),
|
||||
((X >> 24) & 0xff),
|
||||
((X >> 16) & 0xff),
|
||||
((X >> 8) & 0xff),
|
||||
(X & 0xff));
|
||||
(uint) ((X >> 56) & 0xff),
|
||||
(uint) ((X >> 48) & 0xff),
|
||||
(uint) ((X >> 40) & 0xff),
|
||||
(uint) ((X >> 32) & 0xff),
|
||||
(uint) ((X >> 24) & 0xff),
|
||||
(uint) ((X >> 16) & 0xff),
|
||||
(uint) ((X >> 8) & 0xff),
|
||||
(uint) (X & 0xff));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -393,7 +390,7 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
|
||||
|
||||
/* Print seconds */
|
||||
flags |= SIGN;
|
||||
str = number(str, t1, 10, field_width, 0, flags, size);
|
||||
str = number(str, (u64) t1, 10, field_width, 0, flags, size);
|
||||
if (!str)
|
||||
return -1;
|
||||
|
||||
@ -411,7 +408,7 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
|
||||
|
||||
/* Print sub-seconds */
|
||||
*str++ = '.';
|
||||
str = number(str, t2, 10, precision, 0, ZEROPAD, size - 1);
|
||||
str = number(str, (u64) t2, 10, precision, 0, ZEROPAD, size - 1);
|
||||
if (!str)
|
||||
return -1;
|
||||
}
|
||||
@ -446,16 +443,22 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
|
||||
--fmt;
|
||||
continue;
|
||||
}
|
||||
if (qualifier == 'l')
|
||||
num = va_arg(args, unsigned long);
|
||||
else if (qualifier == 'h') {
|
||||
num = (unsigned short) va_arg(args, int);
|
||||
if (flags & SIGN)
|
||||
num = (short) num;
|
||||
} else if (flags & SIGN)
|
||||
num = va_arg(args, int);
|
||||
else
|
||||
num = va_arg(args, uint);
|
||||
if (flags & SIGN) {
|
||||
/* Conversions valid per ISO C99 6.3.1.3 (2) */
|
||||
if (qualifier == 'l')
|
||||
num = (u64) va_arg(args, s64);
|
||||
else if (qualifier == 'h')
|
||||
num = (u64) (short) va_arg(args, int);
|
||||
else
|
||||
num = (u64) va_arg(args, int);
|
||||
} else {
|
||||
if (qualifier == 'l')
|
||||
num = va_arg(args, u64);
|
||||
else if (qualifier == 'h')
|
||||
num = (unsigned short) va_arg(args, int);
|
||||
else
|
||||
num = va_arg(args, uint);
|
||||
}
|
||||
str = number(str, num, base, field_width, precision, flags, size);
|
||||
if (!str)
|
||||
return -1;
|
||||
|
@ -45,7 +45,7 @@ t_simple(void)
|
||||
else
|
||||
BSPRINTF(16, "00000fee1a15600d", buf, "%p", (void *) 0xfee1a15600d);
|
||||
|
||||
long ln = 0;
|
||||
s64 ln = 0;
|
||||
BSPRINTF(10, "TeStStRiNg", buf, "TeStS%lntRiNg", &ln);
|
||||
bt_assert_msg(ln == 5, "fmt=\"TeStS%%lntRiNg\", &ln makes ln=%ld, want 5", ln);
|
||||
|
||||
@ -54,7 +54,40 @@ t_simple(void)
|
||||
BSPRINTF(2, "+1", buf, "%+d", 1);
|
||||
BSPRINTF(2, " 1", buf, "% d", 1);
|
||||
BSPRINTF(2, "-1", buf, "%d", -1);
|
||||
BSPRINTF(11, "-2147483648", buf, "%d", -2147483648);
|
||||
BSPRINTF(11, "-2147483648", buf, "%d", INT32_MIN);
|
||||
BSPRINTF(10, "2147483647", buf, "%d", INT32_MAX);
|
||||
|
||||
BSPRINTF(1, "0", buf, "%u", 0x0);
|
||||
BSPRINTF(10, "4294967295", buf, "%u", 0xFFFFFFFF);
|
||||
|
||||
BSPRINTF(4, "-100", buf, "%ld", (s64) -100);
|
||||
BSPRINTF(3, "100", buf, "%ld", (s64) 100);
|
||||
BSPRINTF(20, "-9223372036854775808", buf, "%ld", INT64_MIN);
|
||||
BSPRINTF(19, "9223372036854775807", buf, "%ld", INT64_MAX);
|
||||
|
||||
BSPRINTF(3, "0 8", buf, "%lu %lu", U64(0), U64(8));
|
||||
BSPRINTF(20, "18446744073709551615", buf, "%lu", UINT64_MAX);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_router_id(void)
|
||||
{
|
||||
char buf[256];
|
||||
|
||||
BSPRINTF(7, "1.2.3.4", buf, "%R", (u32) 0x01020304);
|
||||
BSPRINTF(15, "240.224.208.192", buf, "%R", (u32) 0xF0E0D0C0);
|
||||
BSPRINTF(23, "01:02:03:04:05:06:07:08", buf, "%lR", (u64) 0x0102030405060708);
|
||||
BSPRINTF(23, "f0:e0:d0:c0:b0:a0:90:80", buf, "%lR", (u64) 0xF0E0D0C0B0A09080);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_time(void)
|
||||
{
|
||||
char buf[256];
|
||||
|
||||
BSPRINTF(7, "123.456", buf, "%t", (btime) 123456789);
|
||||
BSPRINTF(7, "123.456", buf, "%2t", (btime) 123456789);
|
||||
@ -68,12 +101,28 @@ t_simple(void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
t_bstrcmp(void)
|
||||
{
|
||||
bt_assert(bstrcmp("aa", "aa") == 0);
|
||||
bt_assert(bstrcmp("aa", "bb") == -1);
|
||||
bt_assert(bstrcmp("bb", "aa") == 1);
|
||||
bt_assert(bstrcmp(NULL, NULL) == 0);
|
||||
bt_assert(bstrcmp(NULL, "bb") == -1);
|
||||
bt_assert(bstrcmp("bb", NULL) == 1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
bt_init(argc, argv);
|
||||
|
||||
bt_test_suite(t_simple, "printf without varargs");
|
||||
bt_test_suite(t_router_id, "print router id");
|
||||
bt_test_suite(t_time, "print time");
|
||||
bt_test_suite(t_bstrcmp, "bstrcmp");
|
||||
|
||||
return bt_exit_value();
|
||||
}
|
||||
|
@ -340,6 +340,7 @@ mb_alloc(pool *p, unsigned size)
|
||||
struct mblock *b = xmalloc(sizeof(struct mblock) + size);
|
||||
|
||||
b->r.class = &mb_class;
|
||||
b->r.n = (node) {};
|
||||
add_tail(&p->inside, &b->r.n);
|
||||
b->size = size;
|
||||
return b->data;
|
||||
@ -387,7 +388,7 @@ mb_realloc(void *m, unsigned size)
|
||||
struct mblock *b = SKIP_BACK(struct mblock, data, m);
|
||||
|
||||
b = xrealloc(b, sizeof(struct mblock) + size);
|
||||
replace_node(&b->r.n, &b->r.n);
|
||||
update_node(&b->r.n);
|
||||
b->size = size;
|
||||
return b->data;
|
||||
}
|
||||
|
@ -83,6 +83,7 @@ typedef struct slab slab;
|
||||
|
||||
slab *sl_new(pool *, unsigned size);
|
||||
void *sl_alloc(slab *);
|
||||
void *sl_allocz(slab *);
|
||||
void sl_free(slab *, void *);
|
||||
|
||||
/*
|
||||
@ -101,9 +102,13 @@ void buffer_realloc(void **buf, unsigned *size, unsigned need, unsigned item_siz
|
||||
*/
|
||||
#define DMALLOC_DISABLE
|
||||
#include <dmalloc.h>
|
||||
#define xmalloc(size) _xmalloc_leap(__FILE__, __LINE__, size)
|
||||
#define xrealloc(size) _xrealloc_leap(__FILE__, __LINE__, size)
|
||||
#define xfree(ptr) _xfree_leap(__FILE__, __LINE__, ptr)
|
||||
#define xmalloc(size) \
|
||||
dmalloc_malloc(__FILE__, __LINE__, (size), DMALLOC_FUNC_MALLOC, 0, 1)
|
||||
#define xrealloc(ptr, size) \
|
||||
dmalloc_realloc(__FILE__, __LINE__, (ptr), (size), DMALLOC_FUNC_REALLOC, 1)
|
||||
#define xfree(ptr) \
|
||||
dmalloc_free(__FILE__, __LINE__, (ptr), DMALLOC_FUNC_FREE)
|
||||
|
||||
#else
|
||||
/*
|
||||
* Unfortunately, several libraries we might want to link to define
|
||||
|
31
lib/slab.c
31
lib/slab.c
@ -88,6 +88,14 @@ sl_alloc(slab *s)
|
||||
return o->data;
|
||||
}
|
||||
|
||||
void *
|
||||
sl_allocz(slab *s)
|
||||
{
|
||||
void *obj = sl_alloc(s);
|
||||
memset(obj, 0, s->size);
|
||||
return obj;
|
||||
}
|
||||
|
||||
void
|
||||
sl_free(slab *s, void *oo)
|
||||
{
|
||||
@ -216,8 +224,11 @@ sl_new_head(slab *s)
|
||||
struct sl_obj *no;
|
||||
uint n = s->objs_per_slab;
|
||||
|
||||
h->first_free = o;
|
||||
h->num_full = 0;
|
||||
*h = (struct sl_head) {
|
||||
.first_free = o,
|
||||
.num_full = 0,
|
||||
};
|
||||
|
||||
while (n--)
|
||||
{
|
||||
o->slab = h;
|
||||
@ -275,6 +286,22 @@ no_partial:
|
||||
goto okay;
|
||||
}
|
||||
|
||||
/**
|
||||
* sl_allocz - allocate an object from Slab and zero it
|
||||
* @s: slab
|
||||
*
|
||||
* sl_allocz() allocates space for a single object from the
|
||||
* Slab and returns a pointer to the object after zeroing out
|
||||
* the object memory.
|
||||
*/
|
||||
void *
|
||||
sl_allocz(slab *s)
|
||||
{
|
||||
void *obj = sl_alloc(s);
|
||||
memset(obj, 0, s->data_size);
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* sl_free - return a free object back to a Slab
|
||||
* @s: slab
|
||||
|
@ -76,7 +76,7 @@ typedef struct birdsock {
|
||||
int rcv_ttl; /* TTL of last received datagram */
|
||||
node n;
|
||||
void *rbuf_alloc, *tbuf_alloc;
|
||||
char *password; /* Password for MD5 authentication */
|
||||
const char *password; /* Password for MD5 authentication */
|
||||
const char *err; /* Error message */
|
||||
struct ssh_sock *ssh; /* Used in SK_SSH */
|
||||
} sock;
|
||||
@ -97,7 +97,7 @@ void sk_dump_all(void);
|
||||
int sk_is_ipv4(sock *s); /* True if socket is IPv4 */
|
||||
int sk_is_ipv6(sock *s); /* True if socket is IPv6 */
|
||||
|
||||
static inline int sk_send_buffer_empty(sock *sk)
|
||||
static inline int sk_tx_buffer_empty(sock *sk)
|
||||
{ return sk->tbuf == sk->tpos; }
|
||||
|
||||
int sk_setup_multicast(sock *s); /* Prepare UDP or IP socket for multicasting */
|
||||
@ -106,7 +106,7 @@ int sk_leave_group(sock *s, ip_addr maddr); /* Leave multicast group on sk iface
|
||||
int sk_setup_broadcast(sock *s);
|
||||
int sk_set_ttl(sock *s, int ttl); /* Set transmit TTL for given socket */
|
||||
int sk_set_min_ttl(sock *s, int ttl); /* Set minimal accepted TTL for given socket */
|
||||
int sk_set_md5_auth(sock *s, ip_addr local, ip_addr remote, struct iface *ifa, char *passwd, int setkey);
|
||||
int sk_set_md5_auth(sock *s, ip_addr local, ip_addr remote, int pxlen, struct iface *ifa, const char *passwd, int setkey);
|
||||
int sk_set_ipv6_checksum(sock *s, int offset);
|
||||
int sk_set_icmp6_filter(sock *s, int p1, int p2);
|
||||
void sk_log_error(sock *s, const char *p);
|
||||
|
21
lib/string.h
21
lib/string.h
@ -24,6 +24,9 @@ int buffer_vprint(buffer *buf, const char *fmt, va_list args);
|
||||
int buffer_print(buffer *buf, const char *fmt, ...);
|
||||
void buffer_puts(buffer *buf, const char *str);
|
||||
|
||||
u64 bstrtoul10(const char *str, char **end);
|
||||
u64 bstrtoul16(const char *str, char **end);
|
||||
|
||||
int patmatch(const byte *pat, const byte *str);
|
||||
|
||||
static inline char *xbasename(const char *str)
|
||||
@ -60,6 +63,24 @@ memset32(void *D, u32 val, uint n)
|
||||
dst[i] = val;
|
||||
}
|
||||
|
||||
static inline int
|
||||
bstrcmp(const char *s1, const char *s2)
|
||||
{
|
||||
if (s1 && s2)
|
||||
return strcmp(s1, s2);
|
||||
else
|
||||
return !s2 - !s1;
|
||||
}
|
||||
|
||||
static inline void *
|
||||
bmemcpy(void *dest, const void *src, size_t n)
|
||||
{
|
||||
if (n)
|
||||
return memcpy(dest, src, n);
|
||||
else
|
||||
return dest;
|
||||
}
|
||||
|
||||
#define ROUTER_ID_64_LENGTH 23
|
||||
|
||||
#endif
|
||||
|
61
lib/strtoul.c
Normal file
61
lib/strtoul.c
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* BIRD Library -- Parse numbers
|
||||
*
|
||||
* (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/string.h"
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#define ULI_MAX_DIV10 (UINT64_MAX / 10)
|
||||
#define ULI_MAX_MOD10 (UINT64_MAX % 10)
|
||||
|
||||
u64
|
||||
bstrtoul10(const char *str, char **end)
|
||||
{
|
||||
u64 out = 0;
|
||||
for (*end = (char *) str; (**end >= '0') && (**end <= '9'); (*end)++) {
|
||||
u64 digit = **end - '0';
|
||||
if ((out > ULI_MAX_DIV10) ||
|
||||
(out == ULI_MAX_DIV10) && (digit > ULI_MAX_MOD10)) {
|
||||
errno = ERANGE;
|
||||
return UINT64_MAX;
|
||||
}
|
||||
|
||||
out *= 10;
|
||||
out += (**end) - '0';
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
u64
|
||||
bstrtoul16(const char *str, char **end)
|
||||
{
|
||||
u64 out = 0;
|
||||
for (int i=0; i<=(64/4); i++) {
|
||||
switch (str[i]) {
|
||||
case '0' ... '9':
|
||||
out *= 16;
|
||||
out += str[i] - '0';
|
||||
break;
|
||||
case 'a' ... 'f':
|
||||
out *= 16;
|
||||
out += str[i] + 10 - 'a';
|
||||
break;
|
||||
case 'A' ... 'F':
|
||||
out *= 16;
|
||||
out += str[i] + 10 - 'A';
|
||||
break;
|
||||
default:
|
||||
*end = (char *) &(str[i]);
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
errno = ERANGE;
|
||||
return UINT64_MAX;
|
||||
}
|
@ -253,9 +253,9 @@ timer_init(void)
|
||||
* type &btime.
|
||||
*/
|
||||
btime
|
||||
tm_parse_time(char *x)
|
||||
tm_parse_time(const char *x)
|
||||
{
|
||||
struct tm tm;
|
||||
struct tm tm = {};
|
||||
int usec, n1, n2, n3, r;
|
||||
|
||||
r = sscanf(x, "%d-%d-%d%n %d:%d:%d%n.%d%n",
|
||||
|
@ -106,7 +106,7 @@ void timer_init(void);
|
||||
|
||||
|
||||
struct timeformat {
|
||||
char *fmt1, *fmt2;
|
||||
const char *fmt1, *fmt2;
|
||||
btime limit;
|
||||
};
|
||||
|
||||
@ -120,7 +120,7 @@ struct timeformat {
|
||||
|
||||
#define TM_DATETIME_BUFFER_SIZE 32 /* Buffer size required by tm_format_time() */
|
||||
|
||||
btime tm_parse_time(char *x);
|
||||
btime tm_parse_time(const char *x);
|
||||
void tm_format_time(char *x, struct timeformat *fmt, btime t);
|
||||
int tm_format_real_time(char *x, size_t max, const char *fmt, btime t);
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
Summary: BIRD Internet Routing Daemon
|
||||
Name: bird
|
||||
Version: 2.0.3
|
||||
Version: 2.0.8
|
||||
Release: 1
|
||||
Copyright: GPL
|
||||
Group: Networking/Daemons
|
||||
|
11
misc/docker/centos-8-amd64/Dockerfile
Normal file
11
misc/docker/centos-8-amd64/Dockerfile
Normal file
@ -0,0 +1,11 @@
|
||||
FROM centos:8
|
||||
RUN yum -y upgrade
|
||||
RUN yum -y install \
|
||||
autoconf \
|
||||
flex \
|
||||
bison \
|
||||
pkgconfig \
|
||||
'readline-devel' \
|
||||
'pkgconfig(ncurses)' \
|
||||
gcc \
|
||||
make
|
12
misc/docker/debian-10-amd64/Dockerfile
Normal file
12
misc/docker/debian-10-amd64/Dockerfile
Normal file
@ -0,0 +1,12 @@
|
||||
FROM debian:buster-slim
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
RUN sed -i 's/deb.debian.org/ftp.cz.debian.org/' /etc/apt/sources.list
|
||||
RUN apt-get -y update
|
||||
RUN apt-get -y upgrade
|
||||
RUN apt-get -y install \
|
||||
autoconf \
|
||||
build-essential \
|
||||
flex \
|
||||
bison \
|
||||
ncurses-dev \
|
||||
libreadline-dev
|
12
misc/docker/debian-10-i386/Dockerfile
Normal file
12
misc/docker/debian-10-i386/Dockerfile
Normal file
@ -0,0 +1,12 @@
|
||||
FROM i386/debian:stretch-slim
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
RUN sed -i 's/deb.debian.org/ftp.cz.debian.org/' /etc/apt/sources.list
|
||||
RUN apt-get -y update
|
||||
RUN apt-get -y upgrade
|
||||
RUN apt-get -y install \
|
||||
autoconf \
|
||||
build-essential \
|
||||
flex \
|
||||
bison \
|
||||
ncurses-dev \
|
||||
libreadline-dev
|
@ -1,7 +1,8 @@
|
||||
FROM debian:wheezy-slim
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
RUN sed -i 's/deb.debian.org/ftp.cz.debian.org/' /etc/apt/sources.list
|
||||
RUN apt-get -y update
|
||||
RUN echo 'deb http://archive.debian.org/debian/ wheezy main' > /etc/apt/sources.list
|
||||
RUN echo 'deb http://archive.debian.org/debian-security/ wheezy/updates main' >> /etc/apt/sources.list
|
||||
RUN apt-get -y update -o Acquire::Check-Valid-Until=false
|
||||
RUN apt-get -y upgrade
|
||||
RUN apt-get -y install \
|
||||
autoconf \
|
||||
|
@ -1,7 +1,8 @@
|
||||
FROM i386/debian:wheezy-slim
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
RUN sed -i 's/deb.debian.org/ftp.cz.debian.org/' /etc/apt/sources.list
|
||||
RUN apt-get -y update
|
||||
RUN echo 'deb http://archive.debian.org/debian/ wheezy main' > /etc/apt/sources.list
|
||||
RUN echo 'deb http://archive.debian.org/debian-security/ wheezy/updates main' >> /etc/apt/sources.list
|
||||
RUN apt-get -y update -o Acquire::Check-Valid-Until=false
|
||||
RUN apt-get -y upgrade
|
||||
RUN apt-get -y install \
|
||||
autoconf \
|
||||
|
@ -1,6 +1,7 @@
|
||||
FROM fedora:25
|
||||
RUN dnf -y upgrade
|
||||
RUN dnf -y install \
|
||||
make \
|
||||
autoconf \
|
||||
flex \
|
||||
bison \
|
||||
|
@ -1,6 +1,7 @@
|
||||
FROM fedora:26
|
||||
RUN dnf -y upgrade
|
||||
RUN dnf -y install \
|
||||
make \
|
||||
autoconf \
|
||||
flex \
|
||||
bison \
|
||||
|
11
misc/docker/fedora-27-amd64/Dockerfile
Normal file
11
misc/docker/fedora-27-amd64/Dockerfile
Normal file
@ -0,0 +1,11 @@
|
||||
FROM fedora:27
|
||||
RUN dnf -y upgrade
|
||||
RUN dnf -y install \
|
||||
make \
|
||||
autoconf \
|
||||
flex \
|
||||
bison \
|
||||
pkgconfig \
|
||||
'readline-devel' \
|
||||
'pkgconfig(ncurses)' \
|
||||
gcc
|
11
misc/docker/fedora-28-amd64/Dockerfile
Normal file
11
misc/docker/fedora-28-amd64/Dockerfile
Normal file
@ -0,0 +1,11 @@
|
||||
FROM fedora:28
|
||||
RUN dnf -y upgrade
|
||||
RUN dnf -y install \
|
||||
make \
|
||||
autoconf \
|
||||
flex \
|
||||
bison \
|
||||
pkgconfig \
|
||||
'readline-devel' \
|
||||
'pkgconfig(ncurses)' \
|
||||
gcc
|
11
misc/docker/fedora-29-amd64/Dockerfile
Normal file
11
misc/docker/fedora-29-amd64/Dockerfile
Normal file
@ -0,0 +1,11 @@
|
||||
FROM fedora:29
|
||||
RUN dnf -y upgrade
|
||||
RUN dnf -y install \
|
||||
make \
|
||||
autoconf \
|
||||
flex \
|
||||
bison \
|
||||
pkgconfig \
|
||||
'readline-devel' \
|
||||
'pkgconfig(ncurses)' \
|
||||
gcc
|
11
misc/docker/fedora-30-amd64/Dockerfile
Normal file
11
misc/docker/fedora-30-amd64/Dockerfile
Normal file
@ -0,0 +1,11 @@
|
||||
FROM fedora:30
|
||||
RUN dnf -y upgrade
|
||||
RUN dnf -y install \
|
||||
make \
|
||||
autoconf \
|
||||
flex \
|
||||
bison \
|
||||
pkgconfig \
|
||||
'readline-devel' \
|
||||
'pkgconfig(ncurses)' \
|
||||
gcc
|
11
misc/docker/fedora-31-amd64/Dockerfile
Normal file
11
misc/docker/fedora-31-amd64/Dockerfile
Normal file
@ -0,0 +1,11 @@
|
||||
FROM fedora:31
|
||||
RUN dnf -y upgrade
|
||||
RUN dnf -y install \
|
||||
make \
|
||||
autoconf \
|
||||
flex \
|
||||
bison \
|
||||
pkgconfig \
|
||||
'readline-devel' \
|
||||
'pkgconfig(ncurses)' \
|
||||
gcc
|
@ -1,4 +1,4 @@
|
||||
FROM opensuse:42.3
|
||||
FROM opensuse/leap:15.0
|
||||
RUN zypper -n up
|
||||
RUN zypper -n install \
|
||||
autoconf \
|
11
misc/docker/opensuse-15.1-amd64/Dockerfile
Normal file
11
misc/docker/opensuse-15.1-amd64/Dockerfile
Normal file
@ -0,0 +1,11 @@
|
||||
FROM opensuse/leap:15.1
|
||||
RUN zypper -n up
|
||||
RUN zypper -n install \
|
||||
autoconf \
|
||||
flex \
|
||||
bison \
|
||||
pkgconfig \
|
||||
readline-devel \
|
||||
ncurses-devel \
|
||||
gcc \
|
||||
gmake
|
12
misc/docker/ubuntu-18.04-amd64/Dockerfile
Normal file
12
misc/docker/ubuntu-18.04-amd64/Dockerfile
Normal file
@ -0,0 +1,12 @@
|
||||
FROM ubuntu:18.04
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
RUN sed -i 's/deb.debian.org/ftp.cz.debian.org/' /etc/apt/sources.list
|
||||
RUN apt-get -y update
|
||||
RUN apt-get -y upgrade
|
||||
RUN apt-get -y install \
|
||||
autoconf \
|
||||
build-essential \
|
||||
flex \
|
||||
bison \
|
||||
ncurses-dev \
|
||||
libreadline-dev
|
12
misc/docker/ubuntu-19.10-amd64/Dockerfile
Normal file
12
misc/docker/ubuntu-19.10-amd64/Dockerfile
Normal file
@ -0,0 +1,12 @@
|
||||
FROM ubuntu:19.10
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
RUN sed -i 's/deb.debian.org/ftp.cz.debian.org/' /etc/apt/sources.list
|
||||
RUN apt-get -y update
|
||||
RUN apt-get -y upgrade
|
||||
RUN apt-get -y install \
|
||||
autoconf \
|
||||
build-essential \
|
||||
flex \
|
||||
bison \
|
||||
ncurses-dev \
|
||||
libreadline-dev
|
169
nest/a-path.c
169
nest/a-path.c
@ -13,7 +13,7 @@
|
||||
#include "lib/resource.h"
|
||||
#include "lib/unaligned.h"
|
||||
#include "lib/string.h"
|
||||
#include "filter/filter.h"
|
||||
#include "filter/data.h"
|
||||
|
||||
// static inline void put_as(byte *data, u32 as) { put_u32(data, as); }
|
||||
// static inline u32 get_as(byte *data) { return get_u32(data); }
|
||||
@ -25,7 +25,7 @@
|
||||
#define BAD(DSC, VAL) ({ err_dsc = DSC; err_val = VAL; goto bad; })
|
||||
|
||||
int
|
||||
as_path_valid(byte *data, uint len, int bs, int confed, char *err, uint elen)
|
||||
as_path_valid(byte *data, uint len, int bs, int sets, int confed, char *err, uint elen)
|
||||
{
|
||||
byte *pos = data;
|
||||
char *err_dsc = NULL;
|
||||
@ -46,13 +46,21 @@ as_path_valid(byte *data, uint len, int bs, int confed, char *err, uint elen)
|
||||
switch (type)
|
||||
{
|
||||
case AS_PATH_SET:
|
||||
if (!sets)
|
||||
BAD("AS_SET segment", type);
|
||||
break;
|
||||
|
||||
case AS_PATH_SEQUENCE:
|
||||
break;
|
||||
|
||||
case AS_PATH_CONFED_SEQUENCE:
|
||||
case AS_PATH_CONFED_SET:
|
||||
if (!confed)
|
||||
BAD("AS_CONFED* segment", type);
|
||||
BAD("AS_CONFED_SEQUENCE segment", type);
|
||||
break;
|
||||
|
||||
case AS_PATH_CONFED_SET:
|
||||
if (!sets || !confed)
|
||||
BAD("AS_CONFED_SET segment", type);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -77,10 +85,10 @@ bad:
|
||||
}
|
||||
|
||||
int
|
||||
as_path_16to32(byte *dst, byte *src, uint len)
|
||||
as_path_16to32(byte *dst, const byte *src, uint len)
|
||||
{
|
||||
byte *dst0 = dst;
|
||||
byte *end = src + len;
|
||||
const byte *end = src + len;
|
||||
uint i, n;
|
||||
|
||||
while (src < end)
|
||||
@ -101,10 +109,10 @@ as_path_16to32(byte *dst, byte *src, uint len)
|
||||
}
|
||||
|
||||
int
|
||||
as_path_32to16(byte *dst, byte *src, uint len)
|
||||
as_path_32to16(byte *dst, const byte *src, uint len)
|
||||
{
|
||||
byte *dst0 = dst;
|
||||
byte *end = src + len;
|
||||
const byte *end = src + len;
|
||||
uint i, n;
|
||||
|
||||
while (src < end)
|
||||
@ -271,13 +279,12 @@ as_path_to_old(struct linpool *pool, const struct adata *path)
|
||||
/*
|
||||
* Cut the path to the length @num, measured to the usual path metric. Note that
|
||||
* AS_CONFED_* segments have zero length and must be added if they are on edge.
|
||||
* In contrast to other as_path_* functions, @path is modified in place.
|
||||
*/
|
||||
void
|
||||
as_path_cut(struct adata *path, uint num)
|
||||
struct adata *
|
||||
as_path_cut(struct linpool *pool, const struct adata *path, uint num)
|
||||
{
|
||||
byte *pos = path->data;
|
||||
byte *end = pos + path->length;
|
||||
const byte *pos = path->data;
|
||||
const byte *end = pos + path->length;
|
||||
|
||||
while (pos < end)
|
||||
{
|
||||
@ -297,28 +304,39 @@ as_path_cut(struct adata *path, uint num)
|
||||
/* Cannot add whole segment, so try partial one and finish */
|
||||
if (num < n)
|
||||
{
|
||||
const byte *nend = pos;
|
||||
if (num)
|
||||
nend += 2 + BS * num;
|
||||
|
||||
struct adata *res = lp_alloc_adata(pool, path->length);
|
||||
res->length = nend - (const byte *) path->data;
|
||||
memcpy(res->data, path->data, res->length);
|
||||
|
||||
if (num)
|
||||
{
|
||||
pos[1] = num;
|
||||
pos += 2 + BS * num;
|
||||
byte *dpos = ((byte *) res->data) + (pos - (const byte *) path->data);
|
||||
dpos[1] = num;
|
||||
}
|
||||
|
||||
break;
|
||||
return res;
|
||||
}
|
||||
|
||||
num -= n;
|
||||
pos += 2 + BS * l;
|
||||
}
|
||||
|
||||
path->length = pos - path->data;
|
||||
struct adata *res = lp_alloc_adata(pool, path->length);
|
||||
res->length = path->length;
|
||||
memcpy(res->data, path->data, res->length);
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
* Merge (concatenate) paths @p1 and @p2 and return the result.
|
||||
* In contrast to other as_path_* functions, @p1 and @p2 may be reused.
|
||||
*/
|
||||
struct adata *
|
||||
as_path_merge(struct linpool *pool, struct adata *p1, struct adata *p2)
|
||||
const struct adata *
|
||||
as_path_merge(struct linpool *pool, const struct adata *p1, const struct adata *p2)
|
||||
{
|
||||
if (p1->length == 0)
|
||||
return p2;
|
||||
@ -561,7 +579,7 @@ as_path_contains(const struct adata *path, u32 as, int min)
|
||||
}
|
||||
|
||||
int
|
||||
as_path_match_set(const struct adata *path, struct f_tree *set)
|
||||
as_path_match_set(const struct adata *path, const struct f_tree *set)
|
||||
{
|
||||
const u8 *p = path->data;
|
||||
const u8 *q = p+path->length;
|
||||
@ -574,7 +592,7 @@ as_path_match_set(const struct adata *path, struct f_tree *set)
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
struct f_val v = {T_INT, .val.i = get_as(p)};
|
||||
if (find_tree(set, v))
|
||||
if (find_tree(set, &v))
|
||||
return 1;
|
||||
p += BS;
|
||||
}
|
||||
@ -583,8 +601,8 @@ as_path_match_set(const struct adata *path, struct f_tree *set)
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct adata *
|
||||
as_path_filter(struct linpool *pool, struct adata *path, struct f_tree *set, u32 key, int pos)
|
||||
const struct adata *
|
||||
as_path_filter(struct linpool *pool, const struct adata *path, const struct f_tree *set, u32 key, int pos)
|
||||
{
|
||||
if (!path)
|
||||
return NULL;
|
||||
@ -612,7 +630,10 @@ as_path_filter(struct linpool *pool, struct adata *path, struct f_tree *set, u32
|
||||
int match;
|
||||
|
||||
if (set)
|
||||
match = !!find_tree(set, (struct f_val){T_INT, .val.i = as});
|
||||
{
|
||||
struct f_val v = {T_INT, .val.i = as};
|
||||
match = !!find_tree(set, &v);
|
||||
}
|
||||
else
|
||||
match = (as == key);
|
||||
|
||||
@ -706,7 +727,7 @@ parse_path(const struct adata *path, struct pm_pos *pp)
|
||||
}
|
||||
|
||||
static int
|
||||
pm_match(struct pm_pos *pos, u32 asn, u32 asn2)
|
||||
pm_match_val(const struct pm_pos *pos, u32 asn, u32 asn2)
|
||||
{
|
||||
u32 gas;
|
||||
if (! pos->set)
|
||||
@ -727,25 +748,59 @@ pm_match(struct pm_pos *pos, u32 asn, u32 asn2)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
pm_mark(struct pm_pos *pos, int i, int plen, int *nl, int *nh)
|
||||
static int
|
||||
pm_match_set(const struct pm_pos *pos, const struct f_tree *set)
|
||||
{
|
||||
int j;
|
||||
struct f_val asn = { .type = T_INT };
|
||||
|
||||
if (pos[i].set)
|
||||
pos[i].mark = 1;
|
||||
if (! pos->set)
|
||||
{
|
||||
asn.val.i = pos->val.asn;
|
||||
return !!find_tree(set, &asn);
|
||||
}
|
||||
|
||||
const u8 *p = pos->val.sp;
|
||||
int len = *p++;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
asn.val.i = get_as(p + i * BS);
|
||||
if (find_tree(set, &asn))
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int
|
||||
pm_match(const struct pm_pos *pos, const struct f_path_mask_item *mask, u32 asn, u32 asn2)
|
||||
{
|
||||
return ((mask->kind == PM_QUESTION) ||
|
||||
((mask->kind != PM_ASN_SET) ?
|
||||
pm_match_val(pos, asn, asn2) :
|
||||
pm_match_set(pos, mask->set)));
|
||||
}
|
||||
|
||||
static void
|
||||
pm_mark(struct pm_pos *pos, int *i, int plen, int *nl, int *nh)
|
||||
{
|
||||
int j = *i;
|
||||
|
||||
if (pos[j].set)
|
||||
do { pos[j].mark = 1; j++; }
|
||||
while ((j < plen) && pos[j].set);
|
||||
else
|
||||
j++;
|
||||
|
||||
for (j = i + 1; (j < plen) && pos[j].set && (! pos[j].mark); j++)
|
||||
pos[j].mark = 1;
|
||||
pos[j].mark = 1;
|
||||
|
||||
/* We are going downwards, therefore every mark is
|
||||
new low and just the first mark is new high */
|
||||
/* Update low, high based on first and last marked pos */
|
||||
int l = pos[*i].set ? *i : j;
|
||||
|
||||
*nl = i + (pos[i].set ? 0 : 1);
|
||||
|
||||
if (*nh < 0)
|
||||
*nh = j;
|
||||
*nl = (*nl < 0) ? l : MIN(*nl, l);
|
||||
*nh = MAX(*nh, j);
|
||||
*i = j;
|
||||
}
|
||||
|
||||
/* AS path matching is nontrivial. Because AS path can
|
||||
@ -771,11 +826,11 @@ pm_mark(struct pm_pos *pos, int i, int plen, int *nl, int *nh)
|
||||
* is marked.
|
||||
*/
|
||||
int
|
||||
as_path_match(const struct adata *path, struct f_path_mask *mask)
|
||||
as_path_match(const struct adata *path, const struct f_path_mask *mask)
|
||||
{
|
||||
struct pm_pos pos[2048 + 1];
|
||||
int plen = parse_path(path, pos);
|
||||
int l, h, i, nh, nl;
|
||||
int l, h, i, nh, nl, last, loop;
|
||||
u32 val = 0;
|
||||
u32 val2 = 0;
|
||||
|
||||
@ -785,15 +840,15 @@ as_path_match(const struct adata *path, struct f_path_mask *mask)
|
||||
pos[plen].set = 0;
|
||||
pos[plen].mark = 0;
|
||||
|
||||
l = h = 0;
|
||||
l = h = loop = 0;
|
||||
pos[0].mark = 1;
|
||||
|
||||
while (mask)
|
||||
for (uint m=0; m < mask->len; m++)
|
||||
{
|
||||
/* We remove this mark to not step after pos[plen] */
|
||||
pos[plen].mark = 0;
|
||||
|
||||
switch (mask->kind)
|
||||
switch (mask->item[m].kind)
|
||||
{
|
||||
case PM_ASTERISK:
|
||||
for (i = l; i <= plen; i++)
|
||||
@ -801,24 +856,39 @@ as_path_match(const struct adata *path, struct f_path_mask *mask)
|
||||
h = plen;
|
||||
break;
|
||||
|
||||
case PM_LOOP:
|
||||
loop = 1;
|
||||
break;
|
||||
|
||||
case PM_ASN: /* Define single ASN as ASN..ASN - very narrow interval */
|
||||
val2 = val = mask->val;
|
||||
val2 = val = mask->item[m].asn;
|
||||
goto step;
|
||||
case PM_ASN_EXPR:
|
||||
bug("Expressions should be evaluated on AS path mask construction.");
|
||||
case PM_ASN_RANGE:
|
||||
val = mask->val;
|
||||
val2 = mask->val2;
|
||||
val = mask->item[m].from;
|
||||
val2 = mask->item[m].to;
|
||||
goto step;
|
||||
case PM_QUESTION:
|
||||
case PM_ASN_SET:
|
||||
step:
|
||||
nh = nl = -1;
|
||||
last = plen;
|
||||
for (i = h; i >= l; i--)
|
||||
if (pos[i].mark)
|
||||
{
|
||||
pos[i].mark = 0;
|
||||
if ((mask->kind == PM_QUESTION) || pm_match(pos + i, val, val2))
|
||||
pm_mark(pos, i, plen, &nl, &nh);
|
||||
int j = i;
|
||||
|
||||
match:
|
||||
if (pm_match(pos + j, &mask->item[m], val, val2))
|
||||
{
|
||||
pm_mark(pos, &j, plen, &nl, &nh);
|
||||
if (loop && (j < last))
|
||||
goto match;
|
||||
}
|
||||
|
||||
last = i;
|
||||
}
|
||||
|
||||
if (nh < 0)
|
||||
@ -826,10 +896,9 @@ as_path_match(const struct adata *path, struct f_path_mask *mask)
|
||||
|
||||
h = nh;
|
||||
l = nl;
|
||||
loop = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
mask = mask->next;
|
||||
}
|
||||
|
||||
return pos[plen].mark;
|
||||
|
@ -34,26 +34,24 @@ t_as_path_match(void)
|
||||
first_prepended = last_prepended = 0;
|
||||
struct linpool *lp = lp_new_default(&root_pool);
|
||||
|
||||
struct f_path_mask mask[AS_PATH_LENGTH] = {};
|
||||
int i;
|
||||
for (i = 0; i < AS_PATH_LENGTH; i++)
|
||||
struct f_path_mask *mask = alloca(sizeof(struct f_path_mask) + AS_PATH_LENGTH * sizeof(struct f_path_mask_item));
|
||||
mask->len = AS_PATH_LENGTH;
|
||||
for (int i = AS_PATH_LENGTH - 1; i >= 0; i--)
|
||||
{
|
||||
u32 val = bt_random();
|
||||
as_path = as_path_prepend(lp, as_path, val);
|
||||
bt_debug("Prepending ASN: %10u \n", val);
|
||||
|
||||
if (i == 0)
|
||||
first_prepended = val;
|
||||
if (i == AS_PATH_LENGTH-1)
|
||||
last_prepended = val;
|
||||
if (i == AS_PATH_LENGTH-1)
|
||||
first_prepended = val;
|
||||
|
||||
mask[i].kind = PM_ASN;
|
||||
mask[i].val = val;
|
||||
if (i)
|
||||
mask[i].next = &mask[i-1];
|
||||
mask->item[i].kind = PM_ASN;
|
||||
mask->item[i].asn = val;
|
||||
}
|
||||
|
||||
bt_assert_msg(as_path_match(as_path, &mask[AS_PATH_LENGTH-1]), "Mask should match with AS path");
|
||||
bt_assert_msg(as_path_match(as_path, mask), "Mask should match with AS path");
|
||||
|
||||
u32 asn;
|
||||
|
||||
|
76
nest/a-set.c
76
nest/a-set.c
@ -34,7 +34,7 @@
|
||||
* the buffer to indicate truncation.
|
||||
*/
|
||||
int
|
||||
int_set_format(struct adata *set, int way, int from, byte *buf, uint size)
|
||||
int_set_format(const struct adata *set, int way, int from, byte *buf, uint size)
|
||||
{
|
||||
u32 *z = (u32 *) set->data;
|
||||
byte *end = buf + size - 24;
|
||||
@ -69,18 +69,16 @@ int
|
||||
ec_format(byte *buf, u64 ec)
|
||||
{
|
||||
u32 type, key, val;
|
||||
char tbuf[16], *kind;
|
||||
char tbuf[16];
|
||||
const char *kind;
|
||||
|
||||
type = ec >> 48;
|
||||
switch (type & 0xf0ff)
|
||||
{
|
||||
case EC_RT: kind = "rt"; break;
|
||||
case EC_RO: kind = "ro"; break;
|
||||
kind = ec_subtype_str(type & 0xf0ff);
|
||||
|
||||
default:
|
||||
kind = tbuf;
|
||||
bsprintf(kind, "unknown 0x%x", type);
|
||||
}
|
||||
if (!kind) {
|
||||
bsprintf(tbuf, "unknown 0x%x", type);
|
||||
kind = tbuf;
|
||||
}
|
||||
|
||||
switch (ec >> 56)
|
||||
{
|
||||
@ -115,7 +113,7 @@ ec_format(byte *buf, u64 ec)
|
||||
}
|
||||
|
||||
int
|
||||
ec_set_format(struct adata *set, int from, byte *buf, uint size)
|
||||
ec_set_format(const struct adata *set, int from, byte *buf, uint size)
|
||||
{
|
||||
u32 *z = int_set_get_data(set);
|
||||
byte *end = buf + size - 64;
|
||||
@ -150,7 +148,7 @@ lc_format(byte *buf, lcomm lc)
|
||||
}
|
||||
|
||||
int
|
||||
lc_set_format(struct adata *set, int from, byte *buf, uint bufsize)
|
||||
lc_set_format(const struct adata *set, int from, byte *buf, uint bufsize)
|
||||
{
|
||||
u32 *d = (u32 *) set->data;
|
||||
byte *end = buf + bufsize - 64;
|
||||
@ -181,7 +179,7 @@ lc_set_format(struct adata *set, int from, byte *buf, uint bufsize)
|
||||
}
|
||||
|
||||
int
|
||||
int_set_contains(struct adata *list, u32 val)
|
||||
int_set_contains(const struct adata *list, u32 val)
|
||||
{
|
||||
if (!list)
|
||||
return 0;
|
||||
@ -198,7 +196,7 @@ int_set_contains(struct adata *list, u32 val)
|
||||
}
|
||||
|
||||
int
|
||||
ec_set_contains(struct adata *list, u64 val)
|
||||
ec_set_contains(const struct adata *list, u64 val)
|
||||
{
|
||||
if (!list)
|
||||
return 0;
|
||||
@ -217,7 +215,7 @@ ec_set_contains(struct adata *list, u64 val)
|
||||
}
|
||||
|
||||
int
|
||||
lc_set_contains(struct adata *list, lcomm val)
|
||||
lc_set_contains(const struct adata *list, lcomm val)
|
||||
{
|
||||
if (!list)
|
||||
return 0;
|
||||
@ -233,8 +231,8 @@ lc_set_contains(struct adata *list, lcomm val)
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct adata *
|
||||
int_set_prepend(struct linpool *pool, struct adata *list, u32 val)
|
||||
const struct adata *
|
||||
int_set_prepend(struct linpool *pool, const struct adata *list, u32 val)
|
||||
{
|
||||
struct adata *res;
|
||||
int len;
|
||||
@ -254,8 +252,8 @@ int_set_prepend(struct linpool *pool, struct adata *list, u32 val)
|
||||
return res;
|
||||
}
|
||||
|
||||
struct adata *
|
||||
int_set_add(struct linpool *pool, struct adata *list, u32 val)
|
||||
const struct adata *
|
||||
int_set_add(struct linpool *pool, const struct adata *list, u32 val)
|
||||
{
|
||||
struct adata *res;
|
||||
int len;
|
||||
@ -275,8 +273,8 @@ int_set_add(struct linpool *pool, struct adata *list, u32 val)
|
||||
return res;
|
||||
}
|
||||
|
||||
struct adata *
|
||||
ec_set_add(struct linpool *pool, struct adata *list, u64 val)
|
||||
const struct adata *
|
||||
ec_set_add(struct linpool *pool, const struct adata *list, u64 val)
|
||||
{
|
||||
if (ec_set_contains(list, val))
|
||||
return list;
|
||||
@ -295,8 +293,8 @@ ec_set_add(struct linpool *pool, struct adata *list, u64 val)
|
||||
return res;
|
||||
}
|
||||
|
||||
struct adata *
|
||||
lc_set_add(struct linpool *pool, struct adata *list, lcomm val)
|
||||
const struct adata *
|
||||
lc_set_add(struct linpool *pool, const struct adata *list, lcomm val)
|
||||
{
|
||||
if (lc_set_contains(list, val))
|
||||
return list;
|
||||
@ -313,8 +311,8 @@ lc_set_add(struct linpool *pool, struct adata *list, lcomm val)
|
||||
return res;
|
||||
}
|
||||
|
||||
struct adata *
|
||||
int_set_del(struct linpool *pool, struct adata *list, u32 val)
|
||||
const struct adata *
|
||||
int_set_del(struct linpool *pool, const struct adata *list, u32 val)
|
||||
{
|
||||
if (!int_set_contains(list, val))
|
||||
return list;
|
||||
@ -335,8 +333,8 @@ int_set_del(struct linpool *pool, struct adata *list, u32 val)
|
||||
return res;
|
||||
}
|
||||
|
||||
struct adata *
|
||||
ec_set_del(struct linpool *pool, struct adata *list, u64 val)
|
||||
const struct adata *
|
||||
ec_set_del(struct linpool *pool, const struct adata *list, u64 val)
|
||||
{
|
||||
if (!ec_set_contains(list, val))
|
||||
return list;
|
||||
@ -362,8 +360,8 @@ ec_set_del(struct linpool *pool, struct adata *list, u64 val)
|
||||
return res;
|
||||
}
|
||||
|
||||
struct adata *
|
||||
lc_set_del(struct linpool *pool, struct adata *list, lcomm val)
|
||||
const struct adata *
|
||||
lc_set_del(struct linpool *pool, const struct adata *list, lcomm val)
|
||||
{
|
||||
if (!lc_set_contains(list, val))
|
||||
return list;
|
||||
@ -384,8 +382,8 @@ lc_set_del(struct linpool *pool, struct adata *list, lcomm val)
|
||||
return res;
|
||||
}
|
||||
|
||||
struct adata *
|
||||
int_set_union(struct linpool *pool, struct adata *l1, struct adata *l2)
|
||||
const struct adata *
|
||||
int_set_union(struct linpool *pool, const struct adata *l1, const struct adata *l2)
|
||||
{
|
||||
if (!l1)
|
||||
return l2;
|
||||
@ -414,8 +412,8 @@ int_set_union(struct linpool *pool, struct adata *l1, struct adata *l2)
|
||||
return res;
|
||||
}
|
||||
|
||||
struct adata *
|
||||
ec_set_union(struct linpool *pool, struct adata *l1, struct adata *l2)
|
||||
const struct adata *
|
||||
ec_set_union(struct linpool *pool, const struct adata *l1, const struct adata *l2)
|
||||
{
|
||||
if (!l1)
|
||||
return l2;
|
||||
@ -447,8 +445,8 @@ ec_set_union(struct linpool *pool, struct adata *l1, struct adata *l2)
|
||||
return res;
|
||||
}
|
||||
|
||||
struct adata *
|
||||
lc_set_union(struct linpool *pool, struct adata *l1, struct adata *l2)
|
||||
const struct adata *
|
||||
lc_set_union(struct linpool *pool, const struct adata *l1, const struct adata *l2)
|
||||
{
|
||||
if (!l1)
|
||||
return l2;
|
||||
@ -479,7 +477,7 @@ lc_set_union(struct linpool *pool, struct adata *l1, struct adata *l2)
|
||||
|
||||
|
||||
struct adata *
|
||||
ec_set_del_nontrans(struct linpool *pool, struct adata *set)
|
||||
ec_set_del_nontrans(struct linpool *pool, const struct adata *set)
|
||||
{
|
||||
adata *res = lp_alloc_adata(pool, set->length);
|
||||
u32 *src = int_set_get_data(set);
|
||||
@ -510,7 +508,7 @@ int_set_cmp(const void *X, const void *Y)
|
||||
}
|
||||
|
||||
struct adata *
|
||||
int_set_sort(struct linpool *pool, struct adata *src)
|
||||
int_set_sort(struct linpool *pool, const struct adata *src)
|
||||
{
|
||||
struct adata *dst = lp_alloc_adata(pool, src->length);
|
||||
memcpy(dst->data, src->data, src->length);
|
||||
@ -528,7 +526,7 @@ ec_set_cmp(const void *X, const void *Y)
|
||||
}
|
||||
|
||||
struct adata *
|
||||
ec_set_sort(struct linpool *pool, struct adata *src)
|
||||
ec_set_sort(struct linpool *pool, const struct adata *src)
|
||||
{
|
||||
struct adata *dst = lp_alloc_adata(pool, src->length);
|
||||
memcpy(dst->data, src->data, src->length);
|
||||
@ -558,7 +556,7 @@ lc_set_cmp(const void *X, const void *Y)
|
||||
}
|
||||
|
||||
struct adata *
|
||||
lc_set_sort(struct linpool *pool, struct adata *src)
|
||||
lc_set_sort(struct linpool *pool, const struct adata *src)
|
||||
{
|
||||
struct adata *dst = lp_alloc_adata(pool, src->length);
|
||||
memcpy(dst->data, src->data, src->length);
|
||||
|
@ -15,10 +15,10 @@
|
||||
#include "lib/resource.h"
|
||||
|
||||
#define SET_SIZE 10
|
||||
static struct adata *set_sequence; /* <0; SET_SIZE) */
|
||||
static struct adata *set_sequence_same; /* <0; SET_SIZE) */
|
||||
static struct adata *set_sequence_higher; /* <SET_SIZE; 2*SET_SIZE) */
|
||||
static struct adata *set_random;
|
||||
static const struct adata *set_sequence; /* <0; SET_SIZE) */
|
||||
static const struct adata *set_sequence_same; /* <0; SET_SIZE) */
|
||||
static const struct adata *set_sequence_higher; /* <SET_SIZE; 2*SET_SIZE) */
|
||||
static const struct adata *set_random;
|
||||
|
||||
#define BUFFER_SIZE 1000
|
||||
static byte buf[BUFFER_SIZE] = {};
|
||||
@ -34,14 +34,14 @@ enum set_type
|
||||
};
|
||||
|
||||
static void
|
||||
generate_set_sequence(enum set_type type)
|
||||
generate_set_sequence(enum set_type type, int len)
|
||||
{
|
||||
struct adata empty_as_path = {};
|
||||
set_sequence = set_sequence_same = set_sequence_higher = set_random = &empty_as_path;
|
||||
lp = lp_new_default(&root_pool);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < SET_SIZE; i++)
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (type == SET_TYPE_INT)
|
||||
{
|
||||
@ -72,7 +72,7 @@ t_set_int_contains(void)
|
||||
int i;
|
||||
|
||||
resource_init();
|
||||
generate_set_sequence(SET_TYPE_INT);
|
||||
generate_set_sequence(SET_TYPE_INT, SET_SIZE);
|
||||
|
||||
bt_assert(int_set_get_size(set_sequence) == SET_SIZE);
|
||||
|
||||
@ -93,9 +93,9 @@ static int
|
||||
t_set_int_union(void)
|
||||
{
|
||||
resource_init();
|
||||
generate_set_sequence(SET_TYPE_INT);
|
||||
generate_set_sequence(SET_TYPE_INT, SET_SIZE);
|
||||
|
||||
struct adata *set_union;
|
||||
const struct adata *set_union;
|
||||
set_union = int_set_union(lp, set_sequence, set_sequence_same);
|
||||
bt_assert(int_set_get_size(set_union) == SET_SIZE);
|
||||
bt_assert(int_set_format(set_union, 0, 2, buf, BUFFER_SIZE) == 0);
|
||||
@ -112,9 +112,8 @@ static int
|
||||
t_set_int_format(void)
|
||||
{
|
||||
resource_init();
|
||||
generate_set_sequence(SET_TYPE_INT);
|
||||
generate_set_sequence(SET_TYPE_INT, SET_SIZE_FOR_FORMAT_OUTPUT);
|
||||
|
||||
set_sequence->length = 4 * SET_SIZE_FOR_FORMAT_OUTPUT; /* dirty */
|
||||
bt_assert(int_set_format(set_sequence, 0, 0, buf, BUFFER_SIZE) == 0);
|
||||
bt_assert(strcmp(buf, "0.0.0.0 0.0.0.1 0.0.0.2 0.0.0.3 0.0.0.4 0.0.0.5 0.0.0.6 0.0.0.7 0.0.0.8 0.0.0.9") == 0);
|
||||
|
||||
@ -134,9 +133,9 @@ static int
|
||||
t_set_int_delete(void)
|
||||
{
|
||||
resource_init();
|
||||
generate_set_sequence(SET_TYPE_INT);
|
||||
generate_set_sequence(SET_TYPE_INT, SET_SIZE);
|
||||
|
||||
struct adata *deleting_sequence = set_sequence;
|
||||
const struct adata *deleting_sequence = set_sequence;
|
||||
u32 i;
|
||||
for (i = 0; i < SET_SIZE; i++)
|
||||
{
|
||||
@ -162,7 +161,7 @@ t_set_ec_contains(void)
|
||||
u32 i;
|
||||
|
||||
resource_init();
|
||||
generate_set_sequence(SET_TYPE_EC);
|
||||
generate_set_sequence(SET_TYPE_EC, SET_SIZE);
|
||||
|
||||
bt_assert(ec_set_get_size(set_sequence) == SET_SIZE);
|
||||
|
||||
@ -183,9 +182,9 @@ static int
|
||||
t_set_ec_union(void)
|
||||
{
|
||||
resource_init();
|
||||
generate_set_sequence(SET_TYPE_EC);
|
||||
generate_set_sequence(SET_TYPE_EC, SET_SIZE);
|
||||
|
||||
struct adata *set_union;
|
||||
const struct adata *set_union;
|
||||
set_union = ec_set_union(lp, set_sequence, set_sequence_same);
|
||||
bt_assert(ec_set_get_size(set_union) == SET_SIZE);
|
||||
bt_assert(ec_set_format(set_union, 0, buf, BUFFER_SIZE) == 0);
|
||||
@ -203,7 +202,7 @@ t_set_ec_format(void)
|
||||
{
|
||||
resource_init();
|
||||
|
||||
struct adata empty_as_path = {};
|
||||
const struct adata empty_as_path = {};
|
||||
set_sequence = set_sequence_same = set_sequence_higher = set_random = &empty_as_path;
|
||||
lp = lp_new_default(&root_pool);
|
||||
|
||||
@ -224,9 +223,9 @@ static int
|
||||
t_set_ec_delete(void)
|
||||
{
|
||||
resource_init();
|
||||
generate_set_sequence(SET_TYPE_EC);
|
||||
generate_set_sequence(SET_TYPE_EC, SET_SIZE);
|
||||
|
||||
struct adata *deleting_sequence = set_sequence;
|
||||
const struct adata *deleting_sequence = set_sequence;
|
||||
u32 i;
|
||||
for (i = 0; i < SET_SIZE; i++)
|
||||
{
|
||||
|
122
nest/attrs.h
122
nest/attrs.h
@ -30,16 +30,16 @@
|
||||
|
||||
struct f_tree;
|
||||
|
||||
int as_path_valid(byte *data, uint len, int bs, int confed, char *err, uint elen);
|
||||
int as_path_16to32(byte *dst, byte *src, uint len);
|
||||
int as_path_32to16(byte *dst, byte *src, uint len);
|
||||
int as_path_valid(byte *data, uint len, int bs, int sets, int confed, char *err, uint elen);
|
||||
int as_path_16to32(byte *dst, const byte *src, uint len);
|
||||
int as_path_32to16(byte *dst, const byte *src, uint len);
|
||||
int as_path_contains_as4(const struct adata *path);
|
||||
int as_path_contains_confed(const struct adata *path);
|
||||
struct adata *as_path_strip_confed(struct linpool *pool, const struct adata *op);
|
||||
struct adata *as_path_prepend2(struct linpool *pool, const struct adata *op, int seq, u32 as);
|
||||
struct adata *as_path_to_old(struct linpool *pool, const struct adata *path);
|
||||
void as_path_cut(struct adata *path, uint num);
|
||||
struct adata *as_path_merge(struct linpool *pool, struct adata *p1, struct adata *p2);
|
||||
struct adata *as_path_cut(struct linpool *pool, const struct adata *path, uint num);
|
||||
const struct adata *as_path_merge(struct linpool *pool, const struct adata *p1, const struct adata *p2);
|
||||
void as_path_format(const struct adata *path, byte *buf, uint size);
|
||||
int as_path_getlen(const struct adata *path);
|
||||
int as_path_getlen_int(const struct adata *path, int bs);
|
||||
@ -48,8 +48,8 @@ int as_path_get_first_regular(const struct adata *path, u32 *last_as);
|
||||
int as_path_get_last(const struct adata *path, u32 *last_as);
|
||||
u32 as_path_get_last_nonaggregated(const struct adata *path);
|
||||
int as_path_contains(const struct adata *path, u32 as, int min);
|
||||
int as_path_match_set(const struct adata *path, struct f_tree *set);
|
||||
struct adata *as_path_filter(struct linpool *pool, struct adata *path, struct f_tree *set, u32 key, int pos);
|
||||
int as_path_match_set(const struct adata *path, const struct f_tree *set);
|
||||
const struct adata *as_path_filter(struct linpool *pool, const struct adata *path, const struct f_tree *set, u32 key, int pos);
|
||||
|
||||
static inline struct adata *as_path_prepend(struct linpool *pool, const struct adata *path, u32 as)
|
||||
{ return as_path_prepend2(pool, path, AS_PATH_SEQUENCE, as); }
|
||||
@ -60,21 +60,34 @@ static inline struct adata *as_path_prepend(struct linpool *pool, const struct a
|
||||
#define PM_ASTERISK 2
|
||||
#define PM_ASN_EXPR 3
|
||||
#define PM_ASN_RANGE 4
|
||||
#define PM_ASN_SET 5
|
||||
#define PM_LOOP 6
|
||||
|
||||
struct f_path_mask {
|
||||
struct f_path_mask *next;
|
||||
struct f_path_mask_item {
|
||||
union {
|
||||
u32 asn; /* PM_ASN */
|
||||
const struct f_line *expr; /* PM_ASN_EXPR */
|
||||
const struct f_tree *set; /* PM_ASN_SET */
|
||||
struct { /* PM_ASN_RANGE */
|
||||
u32 from;
|
||||
u32 to;
|
||||
};
|
||||
};
|
||||
int kind;
|
||||
uintptr_t val;
|
||||
uintptr_t val2;
|
||||
};
|
||||
|
||||
int as_path_match(const struct adata *path, struct f_path_mask *mask);
|
||||
struct f_path_mask {
|
||||
uint len;
|
||||
struct f_path_mask_item item[0];
|
||||
};
|
||||
|
||||
int as_path_match(const struct adata *path, const struct f_path_mask *mask);
|
||||
|
||||
|
||||
/* Counterparts to appropriate as_path_* functions */
|
||||
|
||||
static inline int
|
||||
aggregator_16to32(byte *dst, byte *src)
|
||||
aggregator_16to32(byte *dst, const byte *src)
|
||||
{
|
||||
put_u32(dst, get_u16(src));
|
||||
memcpy(dst+4, src+2, 4);
|
||||
@ -82,7 +95,7 @@ aggregator_16to32(byte *dst, byte *src)
|
||||
}
|
||||
|
||||
static inline int
|
||||
aggregator_32to16(byte *dst, byte *src)
|
||||
aggregator_32to16(byte *dst, const byte *src)
|
||||
{
|
||||
put_u16(dst, get_u32(src));
|
||||
memcpy(dst+2, src+4, 4);
|
||||
@ -90,16 +103,16 @@ aggregator_32to16(byte *dst, byte *src)
|
||||
}
|
||||
|
||||
static inline int
|
||||
aggregator_contains_as4(struct adata *a)
|
||||
aggregator_contains_as4(const struct adata *a)
|
||||
{
|
||||
return get_u32(a->data) > 0xFFFF;
|
||||
}
|
||||
|
||||
static inline struct adata *
|
||||
aggregator_to_old(struct linpool *pool, struct adata *a)
|
||||
aggregator_to_old(struct linpool *pool, const struct adata *a)
|
||||
{
|
||||
struct adata *d = lp_alloc_adata(pool, 8);
|
||||
put_u32(d->data, 0xFFFF);
|
||||
put_u32(d->data, AS_TRANS);
|
||||
memcpy(d->data + 4, a->data + 4, 4);
|
||||
return d;
|
||||
}
|
||||
@ -109,26 +122,35 @@ aggregator_to_old(struct linpool *pool, struct adata *a)
|
||||
|
||||
|
||||
/* Extended Community subtypes (kinds) */
|
||||
#define EC_RT 0x0002
|
||||
#define EC_RO 0x0003
|
||||
enum ec_subtype {
|
||||
EC_RT = 0x0002,
|
||||
EC_RO = 0x0003,
|
||||
EC_GENERIC = 0xFFFF,
|
||||
};
|
||||
|
||||
#define EC_GENERIC 0xFFFF
|
||||
static inline const char *ec_subtype_str(const enum ec_subtype ecs) {
|
||||
switch (ecs) {
|
||||
case EC_RT: return "rt";
|
||||
case EC_RO: return "ro";
|
||||
default: return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Transitive bit (for first u32 half of EC) */
|
||||
#define EC_TBIT 0x40000000
|
||||
|
||||
#define ECOMM_LENGTH 8
|
||||
|
||||
static inline int int_set_get_size(struct adata *list)
|
||||
static inline int int_set_get_size(const struct adata *list)
|
||||
{ return list->length / 4; }
|
||||
|
||||
static inline int ec_set_get_size(struct adata *list)
|
||||
static inline int ec_set_get_size(const struct adata *list)
|
||||
{ return list->length / 8; }
|
||||
|
||||
static inline int lc_set_get_size(struct adata *list)
|
||||
static inline int lc_set_get_size(const struct adata *list)
|
||||
{ return list->length / 12; }
|
||||
|
||||
static inline u32 *int_set_get_data(struct adata *list)
|
||||
static inline u32 *int_set_get_data(const struct adata *list)
|
||||
{ return (u32 *) list->data; }
|
||||
|
||||
static inline u32 ec_hi(u64 ec) { return ec >> 32; }
|
||||
@ -137,16 +159,16 @@ static inline u64 ec_get(const u32 *l, int i)
|
||||
{ return (((u64) l[i]) << 32) | l[i+1]; }
|
||||
|
||||
/* RFC 4360 3.1. Two-Octet AS Specific Extended Community */
|
||||
static inline u64 ec_as2(u64 kind, u64 key, u64 val)
|
||||
{ return ((kind | 0x0000) << 48) | (key << 32) | val; }
|
||||
static inline u64 ec_as2(enum ec_subtype kind, u64 key, u64 val)
|
||||
{ return (((u64) kind | 0x0000) << 48) | (key << 32) | val; }
|
||||
|
||||
/* RFC 5668 4-Octet AS Specific BGP Extended Community */
|
||||
static inline u64 ec_as4(u64 kind, u64 key, u64 val)
|
||||
{ return ((kind | 0x0200) << 48) | (key << 16) | val; }
|
||||
static inline u64 ec_as4(enum ec_subtype kind, u64 key, u64 val)
|
||||
{ return (((u64) kind | 0x0200) << 48) | (key << 16) | val; }
|
||||
|
||||
/* RFC 4360 3.2. IPv4 Address Specific Extended Community */
|
||||
static inline u64 ec_ip4(u64 kind, u64 key, u64 val)
|
||||
{ return ((kind | 0x0100) << 48) | (key << 16) | val; }
|
||||
static inline u64 ec_ip4(enum ec_subtype kind, u64 key, u64 val)
|
||||
{ return (((u64) kind | 0x0100) << 48) | (key << 16) | val; }
|
||||
|
||||
static inline u64 ec_generic(u64 key, u64 val)
|
||||
{ return (key << 32) | val; }
|
||||
@ -173,29 +195,29 @@ static inline u32 *lc_copy(u32 *dst, const u32 *src)
|
||||
{ memcpy(dst, src, LCOMM_LENGTH); return dst + 3; }
|
||||
|
||||
|
||||
int int_set_format(struct adata *set, int way, int from, byte *buf, uint size);
|
||||
int int_set_format(const struct adata *set, int way, int from, byte *buf, uint size);
|
||||
int ec_format(byte *buf, u64 ec);
|
||||
int ec_set_format(struct adata *set, int from, byte *buf, uint size);
|
||||
int ec_set_format(const struct adata *set, int from, byte *buf, uint size);
|
||||
int lc_format(byte *buf, lcomm lc);
|
||||
int lc_set_format(struct adata *set, int from, byte *buf, uint size);
|
||||
int int_set_contains(struct adata *list, u32 val);
|
||||
int ec_set_contains(struct adata *list, u64 val);
|
||||
int lc_set_contains(struct adata *list, lcomm val);
|
||||
struct adata *int_set_prepend(struct linpool *pool, struct adata *list, u32 val);
|
||||
struct adata *int_set_add(struct linpool *pool, struct adata *list, u32 val);
|
||||
struct adata *ec_set_add(struct linpool *pool, struct adata *list, u64 val);
|
||||
struct adata *lc_set_add(struct linpool *pool, struct adata *list, lcomm val);
|
||||
struct adata *int_set_del(struct linpool *pool, struct adata *list, u32 val);
|
||||
struct adata *ec_set_del(struct linpool *pool, struct adata *list, u64 val);
|
||||
struct adata *lc_set_del(struct linpool *pool, struct adata *list, lcomm val);
|
||||
struct adata *int_set_union(struct linpool *pool, struct adata *l1, struct adata *l2);
|
||||
struct adata *ec_set_union(struct linpool *pool, struct adata *l1, struct adata *l2);
|
||||
struct adata *lc_set_union(struct linpool *pool, struct adata *l1, struct adata *l2);
|
||||
int lc_set_format(const struct adata *set, int from, byte *buf, uint size);
|
||||
int int_set_contains(const struct adata *list, u32 val);
|
||||
int ec_set_contains(const struct adata *list, u64 val);
|
||||
int lc_set_contains(const struct adata *list, lcomm val);
|
||||
const struct adata *int_set_prepend(struct linpool *pool, const struct adata *list, u32 val);
|
||||
const struct adata *int_set_add(struct linpool *pool, const struct adata *list, u32 val);
|
||||
const struct adata *ec_set_add(struct linpool *pool, const struct adata *list, u64 val);
|
||||
const struct adata *lc_set_add(struct linpool *pool, const struct adata *list, lcomm val);
|
||||
const struct adata *int_set_del(struct linpool *pool, const struct adata *list, u32 val);
|
||||
const struct adata *ec_set_del(struct linpool *pool, const struct adata *list, u64 val);
|
||||
const struct adata *lc_set_del(struct linpool *pool, const struct adata *list, lcomm val);
|
||||
const struct adata *int_set_union(struct linpool *pool, const struct adata *l1, const struct adata *l2);
|
||||
const struct adata *ec_set_union(struct linpool *pool, const struct adata *l1, const struct adata *l2);
|
||||
const struct adata *lc_set_union(struct linpool *pool, const struct adata *l1, const struct adata *l2);
|
||||
|
||||
struct adata *ec_set_del_nontrans(struct linpool *pool, struct adata *set);
|
||||
struct adata *int_set_sort(struct linpool *pool, struct adata *src);
|
||||
struct adata *ec_set_sort(struct linpool *pool, struct adata *src);
|
||||
struct adata *lc_set_sort(struct linpool *pool, struct adata *src);
|
||||
struct adata *ec_set_del_nontrans(struct linpool *pool, const struct adata *set);
|
||||
struct adata *int_set_sort(struct linpool *pool, const struct adata *src);
|
||||
struct adata *ec_set_sort(struct linpool *pool, const struct adata *src);
|
||||
struct adata *lc_set_sort(struct linpool *pool, const struct adata *src);
|
||||
|
||||
void ec_set_sort_x(struct adata *set); /* Sort in place */
|
||||
|
||||
|
23
nest/bfd.h
23
nest/bfd.h
@ -9,9 +9,20 @@
|
||||
|
||||
#include "lib/lists.h"
|
||||
#include "lib/resource.h"
|
||||
#include "conf/conf.h"
|
||||
|
||||
struct bfd_session;
|
||||
|
||||
struct bfd_options {
|
||||
u32 min_rx_int;
|
||||
u32 min_tx_int;
|
||||
u32 idle_tx_int;
|
||||
u8 multiplier;
|
||||
u8 passive;
|
||||
u8 passive_set;
|
||||
u8 mode;
|
||||
};
|
||||
|
||||
struct bfd_request {
|
||||
resource r;
|
||||
node n;
|
||||
@ -19,6 +30,8 @@ struct bfd_request {
|
||||
ip_addr addr;
|
||||
ip_addr local;
|
||||
struct iface *iface;
|
||||
struct iface *vrf;
|
||||
struct bfd_options opts;
|
||||
|
||||
void (*hook)(struct bfd_request *);
|
||||
void *data;
|
||||
@ -31,6 +44,7 @@ struct bfd_request {
|
||||
u8 down;
|
||||
};
|
||||
|
||||
#define BGP_BFD_GRACEFUL 2 /* BFD down triggers graceful restart */
|
||||
|
||||
#define BFD_STATE_ADMIN_DOWN 0
|
||||
#define BFD_STATE_DOWN 1
|
||||
@ -38,15 +52,20 @@ struct bfd_request {
|
||||
#define BFD_STATE_UP 3
|
||||
|
||||
|
||||
static inline struct bfd_options * bfd_new_options(void)
|
||||
{ return cfg_allocz(sizeof(struct bfd_options)); }
|
||||
|
||||
#ifdef CONFIG_BFD
|
||||
|
||||
struct bfd_request * bfd_request_session(pool *p, ip_addr addr, ip_addr local, struct iface *iface, void (*hook)(struct bfd_request *), void *data);
|
||||
struct bfd_request * bfd_request_session(pool *p, ip_addr addr, ip_addr local, struct iface *iface, struct iface *vrf, void (*hook)(struct bfd_request *), void *data, const struct bfd_options *opts);
|
||||
void bfd_update_request(struct bfd_request *req, const struct bfd_options *opts);
|
||||
|
||||
static inline void cf_check_bfd(int use UNUSED) { }
|
||||
|
||||
#else
|
||||
|
||||
static inline struct bfd_request * bfd_request_session(pool *p UNUSED, ip_addr addr UNUSED, ip_addr local UNUSED, struct iface *iface UNUSED, void (*hook)(struct bfd_request *) UNUSED, void *data UNUSED) { return NULL; }
|
||||
static inline struct bfd_request * bfd_request_session(pool *p UNUSED, ip_addr addr UNUSED, ip_addr local UNUSED, struct iface *iface UNUSED, struct iface *vrf UNUSED, void (*hook)(struct bfd_request *) UNUSED, void *data UNUSED, const struct bfd_options *opts UNUSED) { return NULL; }
|
||||
static inline void bfd_update_request(struct bfd_request *req UNUSED, const struct bfd_options *opts UNUSED) { };
|
||||
|
||||
static inline void cf_check_bfd(int use) { if (use) cf_error("BFD not available"); }
|
||||
|
||||
|
@ -143,6 +143,7 @@ cli_printf(cli *c, int code, char *msg, ...)
|
||||
{
|
||||
size = bsprintf(buf, "%04d ", cd);
|
||||
errcode = 8000;
|
||||
cd = 0; /* Final message - no more continuation lines */
|
||||
}
|
||||
|
||||
c->last_reply = cd;
|
||||
@ -262,6 +263,7 @@ cli_command(struct cli *c)
|
||||
bzero(&f, sizeof(f));
|
||||
f.mem = c->parser_pool;
|
||||
f.pool = rp_new(c->pool, "Config");
|
||||
init_list(&f.symbols);
|
||||
cf_read_hook = cli_cmd_read_hook;
|
||||
cli_rh_pos = c->rx_buf;
|
||||
cli_rh_len = strlen(c->rx_buf);
|
||||
|
@ -58,6 +58,9 @@ void cli_printf(cli *, int, char *, ...);
|
||||
#define cli_msg(x...) cli_printf(this_cli, x)
|
||||
void cli_set_log_echo(cli *, uint mask, uint size);
|
||||
|
||||
static inline void cli_separator(cli *c)
|
||||
{ if (c->last_reply) cli_printf(c, -c->last_reply, ""); };
|
||||
|
||||
/* Functions provided to sysdep layer */
|
||||
|
||||
cli *cli_new(void *);
|
||||
|
11
nest/cmds.c
11
nest/cmds.c
@ -27,6 +27,7 @@ cmd_show_status(void)
|
||||
cli_msg(-1000, "BIRD " BIRD_VERSION);
|
||||
tm_format_time(tim, &config->tf_base, current_time());
|
||||
cli_msg(-1011, "Router ID is %R", config->router_id);
|
||||
cli_msg(-1011, "Hostname is %s", config->hostname);
|
||||
cli_msg(-1011, "Current server time is %s", tim);
|
||||
tm_format_time(tim, &config->tf_base, boot_time);
|
||||
cli_msg(-1011, "Last reboot on %s", tim);
|
||||
@ -95,18 +96,16 @@ cmd_show_memory(void)
|
||||
}
|
||||
|
||||
void
|
||||
cmd_eval(struct f_inst *expr)
|
||||
cmd_eval(const struct f_line *expr)
|
||||
{
|
||||
struct f_val v = f_eval(expr, this_cli->parser_pool);
|
||||
buffer buf;
|
||||
LOG_BUFFER_INIT(buf);
|
||||
|
||||
if (v.type == T_RETURN)
|
||||
if (f_eval_buf(expr, this_cli->parser_pool, &buf) > F_RETURN)
|
||||
{
|
||||
cli_msg(8008, "runtime error");
|
||||
return;
|
||||
}
|
||||
|
||||
buffer buf;
|
||||
LOG_BUFFER_INIT(buf);
|
||||
val_format(v, &buf);
|
||||
cli_msg(23, "%s", buf.start);
|
||||
}
|
||||
|
@ -16,4 +16,6 @@ struct f_inst;
|
||||
void cmd_show_status(void);
|
||||
void cmd_show_symbols(struct sym_show_data *sym);
|
||||
void cmd_show_memory(void);
|
||||
void cmd_eval(struct f_inst *expr);
|
||||
|
||||
struct f_line;
|
||||
void cmd_eval(const struct f_line *expr);
|
||||
|
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