howto/Bird-communities.md
... ...
@@ -43,56 +43,44 @@ For example, if your peer is 12ms away and the link speed between you is 250Mbit
43 43
# This comes from my own experience so let me know if I'm wrong :) -tombii
44 44
protocol bgp tombii from dnpeers {
45 45
neighbor 172.23.102.x as 4242420321;
46
- import filter {
47
- if is_valid_network() && !is_self_net() then {
48
- update_flags(3,24,33);
49
- accept;
50
- }
51
- reject;
52
- };
53
- export filter {
54
- if is_valid_network() then {
55
- update_flags(3,24,33);
56
- accept;
57
- }
58
- reject;
59
- };
46
+ import where dn42_import_filter(3,24,33);
47
+ export where dn42_export_filter(3,24,33);
60 48
};
61 49
```
62 50
```
63 51
#/etc/bird/community_filters.conf
64 52
function update_latency(int link_latency) {
65
- bgp_community.add((64511, link_latency));
66
- if (64511, 9) ~ bgp_community then { bgp_community.delete([(64511, 1..8)]); return 9; }
67
- else if (64511, 8) ~ bgp_community then { bgp_community.delete([(64511, 1..7)]); return 8; }
68
- else if (64511, 7) ~ bgp_community then { bgp_community.delete([(64511, 1..6)]); return 7; }
69
- else if (64511, 6) ~ bgp_community then { bgp_community.delete([(64511, 1..5)]); return 6; }
70
- else if (64511, 5) ~ bgp_community then { bgp_community.delete([(64511, 1..4)]); return 5; }
71
- else if (64511, 4) ~ bgp_community then { bgp_community.delete([(64511, 1..3)]); return 4; }
72
- else if (64511, 3) ~ bgp_community then { bgp_community.delete([(64511, 1..2)]); return 3; }
73
- else if (64511, 2) ~ bgp_community then { bgp_community.delete([(64511, 1..1)]); return 2; }
74
- else return 1;
53
+ bgp_community.add((64511, link_latency));
54
+ if (64511, 9) ~ bgp_community then { bgp_community.delete([(64511, 1..8)]); return 9; }
55
+ else if (64511, 8) ~ bgp_community then { bgp_community.delete([(64511, 1..7)]); return 8; }
56
+ else if (64511, 7) ~ bgp_community then { bgp_community.delete([(64511, 1..6)]); return 7; }
57
+ else if (64511, 6) ~ bgp_community then { bgp_community.delete([(64511, 1..5)]); return 6; }
58
+ else if (64511, 5) ~ bgp_community then { bgp_community.delete([(64511, 1..4)]); return 5; }
59
+ else if (64511, 4) ~ bgp_community then { bgp_community.delete([(64511, 1..3)]); return 4; }
60
+ else if (64511, 3) ~ bgp_community then { bgp_community.delete([(64511, 1..2)]); return 3; }
61
+ else if (64511, 2) ~ bgp_community then { bgp_community.delete([(64511, 1..1)]); return 2; }
62
+ else return 1;
75 63
}
76 64
77 65
function update_bandwidth(int link_bandwidth) {
78
- bgp_community.add((64511, link_bandwidth));
79
- if (64511, 21) ~ bgp_community then { bgp_community.delete([(64511, 22..29)]); return 21; }
80
- else if (64511, 22) ~ bgp_community then { bgp_community.delete([(64511, 23..29)]); return 22; }
81
- else if (64511, 23) ~ bgp_community then { bgp_community.delete([(64511, 24..29)]); return 23; }
82
- else if (64511, 24) ~ bgp_community then { bgp_community.delete([(64511, 25..29)]); return 24; }
83
- else if (64511, 25) ~ bgp_community then { bgp_community.delete([(64511, 26..29)]); return 25; }
84
- else if (64511, 26) ~ bgp_community then { bgp_community.delete([(64511, 27..29)]); return 26; }
85
- else if (64511, 27) ~ bgp_community then { bgp_community.delete([(64511, 28..29)]); return 27; }
86
- else if (64511, 28) ~ bgp_community then { bgp_community.delete([(64511, 29..29)]); return 28; }
87
- else return 29;
66
+ bgp_community.add((64511, link_bandwidth));
67
+ if (64511, 21) ~ bgp_community then { bgp_community.delete([(64511, 22..29)]); return 21; }
68
+ else if (64511, 22) ~ bgp_community then { bgp_community.delete([(64511, 23..29)]); return 22; }
69
+ else if (64511, 23) ~ bgp_community then { bgp_community.delete([(64511, 24..29)]); return 23; }
70
+ else if (64511, 24) ~ bgp_community then { bgp_community.delete([(64511, 25..29)]); return 24; }
71
+ else if (64511, 25) ~ bgp_community then { bgp_community.delete([(64511, 26..29)]); return 25; }
72
+ else if (64511, 26) ~ bgp_community then { bgp_community.delete([(64511, 27..29)]); return 26; }
73
+ else if (64511, 27) ~ bgp_community then { bgp_community.delete([(64511, 28..29)]); return 27; }
74
+ else if (64511, 28) ~ bgp_community then { bgp_community.delete([(64511, 29..29)]); return 28; }
75
+ else return 29;
88 76
}
89 77
90 78
function update_crypto(int link_crypto) {
91
- bgp_community.add((64511, link_crypto));
92
- if (64511, 31) ~ bgp_community then { bgp_community.delete([(64511, 32..34)]); return 31; }
93
- else if (64511, 32) ~ bgp_community then { bgp_community.delete([(64511, 33..34)]); return 32; }
94
- else if (64511, 33) ~ bgp_community then { bgp_community.delete([(64511, 34..34)]); return 33; }
95
- else return 34;
79
+ bgp_community.add((64511, link_crypto));
80
+ if (64511, 31) ~ bgp_community then { bgp_community.delete([(64511, 32..34)]); return 31; }
81
+ else if (64511, 32) ~ bgp_community then { bgp_community.delete([(64511, 33..34)]); return 32; }
82
+ else if (64511, 33) ~ bgp_community then { bgp_community.delete([(64511, 34..34)]); return 33; }
83
+ else return 34;
96 84
}
97 85
98 86
function update_flags(int link_latency; int link_bandwidth; int link_crypto)
... ...
@@ -100,15 +88,41 @@ int dn42_latency;
100 88
int dn42_bandwidth;
101 89
int dn42_crypto;
102 90
{
103
-dn42_latency = update_latency(link_latency);
104
-dn42_bandwidth = update_bandwidth(link_bandwidth) - 20;
105
-dn42_crypto = update_crypto(link_crypto) - 30;
106
-if dn42_bandwidth > 4 then dn42_bandwidth = 4;
107
-return true;
108
-}
91
+ dn42_latency = update_latency(link_latency);
92
+ dn42_bandwidth = update_bandwidth(link_bandwidth) - 20;
93
+ dn42_crypto = update_crypto(link_crypto) - 30;
94
+ # replace 4 with your calculated bandwidth value
95
+ if dn42_bandwidth > 4 then dn42_bandwidth = 4;
96
+ return true;
97
+}
98
+
99
+# Combines filter from local4.conf/local6.conf and filter4.conf/filter6.conf,
100
+# which means, these must included before this file
101
+
102
+function dn42_import_filter(int link_latency; int link_bandwith; int link_crypto) {
103
+ if is_valid_network() && !is_self_net() then {
104
+ update_flags(link_latency, link_bandwith, link_crypto);
105
+ accept;
106
+ }
107
+ reject;
108
+}
109
+
110
+function dn42_export_filter(int link_latency; int link_bandwith; int link_crypto) {
111
+ if is_valid_network() then {
112
+ update_flags(link_latency, link_bandwith, link_crypto);
113
+ accept;
114
+ }
115
+ reject;
116
+}
117
+
109 118
```
110 119
Please remember to include /etc/bird/community_filters.conf in your bird.conf/birdc6.conf
111 120
```
121
+
122
+# local configuration
123
+######################
124
+include "bird/local4.conf";
125
+
112 126
# filter helpers
113 127
#################
114 128