Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
babeld
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
babeld
Commits
4df8ccad
Commit
4df8ccad
authored
Nov 14, 2013
by
Matthieu Boutier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set the source prefixes through filters.
Since it's a route attribute, it fits better there.
parent
79c1a379
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
86 additions
and
26 deletions
+86
-26
babeld.man
babeld.man
+10
-0
configuration.c
configuration.c
+33
-12
configuration.h
configuration.h
+13
-4
message.c
message.c
+1
-1
resend.c
resend.c
+3
-2
route.c
route.c
+4
-4
xroute.c
xroute.c
+22
-3
No files found.
babeld.man
View file @
4df8ccad
...
...
@@ -472,6 +472,10 @@ For an input or output filter, allow this route after increasing its metric by
.IR value .
For a redistribute filter, redistribute this route with metric
.IR value .
.TP
.BI src-prefix " prefix"
For a redistribute filter, set the source prefix of this route to
.IR prefix .
.PP
If
.I action
...
...
@@ -514,6 +518,12 @@ or, if you want to constrain the routes that you redistribute,
\-C 'redistribute proto 11 ip ::/0 le 64 metric 256' \\
\-C 'redistribute proto 11 ip 0.0.0.0/0 le 24 metric 256' \\
wlan0
.SS Source-sensitive routing
.PP
If your want to redistribute kernel routes as source-specific to the network,
with the 2001:DB8:0:1::/64 prefix:
.IP
redistribute src-prefix 2001:DB8:0:1::/64
.SH FILES
.TP
.B /etc/babeld.conf
...
...
configuration.c
View file @
4df8ccad
...
...
@@ -381,16 +381,28 @@ parse_filter(int c, gnc_t gnc, void *closure, struct filter **filter_return)
filter
->
ifname
=
interface
;
filter
->
ifindex
=
if_nametoindex
(
interface
);
}
else
if
(
strcmp
(
token
,
"allow"
)
==
0
)
{
filter
->
add_metric
=
0
;
filter
->
a
ction
.
a
dd_metric
=
0
;
}
else
if
(
strcmp
(
token
,
"deny"
)
==
0
)
{
filter
->
add_metric
=
INFINITY
;
filter
->
a
ction
.
a
dd_metric
=
INFINITY
;
}
else
if
(
strcmp
(
token
,
"metric"
)
==
0
)
{
int
metric
;
c
=
getint
(
c
,
&
metric
,
gnc
,
closure
);
if
(
c
<
-
1
)
goto
error
;
if
(
metric
<=
0
||
metric
>
INFINITY
)
goto
error
;
filter
->
add_metric
=
metric
;
filter
->
action
.
add_metric
=
metric
;
}
else
if
(
strcmp
(
token
,
"src-prefix"
)
==
0
)
{
int
af
;
c
=
getnet
(
c
,
&
filter
->
action
.
src_prefix
,
&
filter
->
action
.
src_plen
,
&
af
,
gnc
,
closure
);
if
(
c
<
-
1
)
goto
error
;
if
(
filter
->
af
==
AF_UNSPEC
)
filter
->
af
=
af
;
else
if
(
filter
->
af
!=
af
)
goto
error
;
if
(
af
==
AF_INET
&&
filter
->
action
.
src_plen
==
96
)
memset
(
&
filter
->
action
.
src_prefix
,
0
,
16
);
}
else
{
goto
error
;
}
...
...
@@ -988,12 +1000,18 @@ static int
do_filter
(
struct
filter
*
f
,
const
unsigned
char
*
id
,
const
unsigned
char
*
prefix
,
unsigned
short
plen
,
const
unsigned
char
*
src_prefix
,
unsigned
short
src_plen
,
const
unsigned
char
*
neigh
,
unsigned
int
ifindex
,
int
proto
)
const
unsigned
char
*
neigh
,
unsigned
int
ifindex
,
int
proto
,
struct
filter_result
*
result
)
{
if
(
result
)
memset
(
result
,
0
,
sizeof
(
struct
filter_result
));
while
(
f
)
{
if
(
filter_match
(
f
,
id
,
prefix
,
plen
,
src_prefix
,
src_plen
,
neigh
,
ifindex
,
proto
))
return
f
->
add_metric
;
neigh
,
ifindex
,
proto
))
{
if
(
result
)
memcpy
(
result
,
&
f
->
action
,
sizeof
(
struct
filter_result
));
return
f
->
action
.
add_metric
;
}
f
=
f
->
next
;
}
return
-
1
;
...
...
@@ -1003,11 +1021,12 @@ int
input_filter
(
const
unsigned
char
*
id
,
const
unsigned
char
*
prefix
,
unsigned
short
plen
,
const
unsigned
char
*
src_prefix
,
unsigned
short
src_plen
,
const
unsigned
char
*
neigh
,
unsigned
int
ifindex
)
const
unsigned
char
*
neigh
,
unsigned
int
ifindex
,
struct
filter_result
*
result
)
{
int
res
;
res
=
do_filter
(
input_filters
,
id
,
prefix
,
plen
,
src_prefix
,
src_plen
,
neigh
,
ifindex
,
0
);
src_prefix
,
src_plen
,
neigh
,
ifindex
,
0
,
result
);
if
(
res
<
0
)
res
=
0
;
return
res
;
...
...
@@ -1017,11 +1036,12 @@ int
output_filter
(
const
unsigned
char
*
id
,
const
unsigned
char
*
prefix
,
unsigned
short
plen
,
const
unsigned
char
*
src_prefix
,
unsigned
short
src_plen
,
unsigned
int
ifindex
)
unsigned
int
ifindex
,
struct
filter_result
*
result
)
{
int
res
;
res
=
do_filter
(
output_filters
,
id
,
prefix
,
plen
,
src_prefix
,
src_plen
,
NULL
,
ifindex
,
0
);
src_prefix
,
src_plen
,
NULL
,
ifindex
,
0
,
result
);
if
(
res
<
0
)
res
=
0
;
return
res
;
...
...
@@ -1030,11 +1050,12 @@ output_filter(const unsigned char *id,
int
redistribute_filter
(
const
unsigned
char
*
prefix
,
unsigned
short
plen
,
const
unsigned
char
*
src_prefix
,
unsigned
short
src_plen
,
unsigned
int
ifindex
,
int
proto
)
unsigned
int
ifindex
,
int
proto
,
struct
filter_result
*
result
)
{
int
res
;
res
=
do_filter
(
redistribute_filters
,
NULL
,
prefix
,
plen
,
src_prefix
,
src_plen
,
NULL
,
ifindex
,
proto
);
src_prefix
,
src_plen
,
NULL
,
ifindex
,
proto
,
result
);
if
(
res
<
0
)
res
=
INFINITY
;
return
res
;
...
...
configuration.h
View file @
4df8ccad
...
...
@@ -20,6 +20,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
struct
filter_result
{
unsigned
int
add_metric
;
/* allow = 0, deny = INF, metric = <0..INF> */
unsigned
char
*
src_prefix
;
unsigned
char
src_plen
;
};
struct
filter
{
int
af
;
char
*
ifname
;
...
...
@@ -33,7 +39,7 @@ struct filter {
unsigned
char
src_plen_ge
,
src_plen_le
;
unsigned
char
*
neigh
;
int
proto
;
/* May be negative */
unsigned
int
add_metric
;
struct
filter_result
action
;
struct
filter
*
next
;
};
...
...
@@ -46,12 +52,15 @@ void renumber_filters(void);
int
input_filter
(
const
unsigned
char
*
id
,
const
unsigned
char
*
prefix
,
unsigned
short
plen
,
const
unsigned
char
*
src_prefix
,
unsigned
short
src_plen
,
const
unsigned
char
*
neigh
,
unsigned
int
ifindex
);
const
unsigned
char
*
neigh
,
unsigned
int
ifindex
,
struct
filter_result
*
result
);
int
output_filter
(
const
unsigned
char
*
id
,
const
unsigned
char
*
prefix
,
unsigned
short
plen
,
const
unsigned
char
*
src_prefix
,
unsigned
short
src_plen
,
unsigned
int
ifindex
);
unsigned
int
ifindex
,
struct
filter_result
*
result
);
int
redistribute_filter
(
const
unsigned
char
*
prefix
,
unsigned
short
plen
,
const
unsigned
char
*
src_prefix
,
unsigned
short
src_plen
,
unsigned
int
ifindex
,
int
proto
);
unsigned
int
ifindex
,
int
proto
,
struct
filter_result
*
result
);
int
finalise_config
(
void
);
message.c
View file @
4df8ccad
...
...
@@ -1093,7 +1093,7 @@ really_send_update(struct interface *ifp,
return
;
add_metric
=
output_filter
(
id
,
prefix
,
plen
,
src_prefix
,
src_plen
,
ifp
->
ifindex
);
src_plen
,
ifp
->
ifindex
,
NULL
);
if
(
add_metric
>=
INFINITY
)
return
;
...
...
resend.c
View file @
4df8ccad
...
...
@@ -101,10 +101,11 @@ record_resend(int kind, const unsigned char *prefix, unsigned char plen,
return
0
;
if
((
kind
==
RESEND_REQUEST
&&
input_filter
(
NULL
,
prefix
,
plen
,
NULL
,
0
,
NULL
,
ifindex
)
>=
input_filter
(
NULL
,
prefix
,
plen
,
NULL
,
0
,
NULL
,
ifindex
,
NULL
)
>=
INFINITY
)
||
(
kind
==
RESEND_UPDATE
&&
output_filter
(
NULL
,
prefix
,
plen
,
src_prefix
,
src_plen
,
ifindex
)
>=
output_filter
(
NULL
,
prefix
,
plen
,
src_prefix
,
src_plen
,
ifindex
,
NULL
)
>=
INFINITY
))
return
0
;
...
...
route.c
View file @
4df8ccad
...
...
@@ -767,7 +767,7 @@ update_route_metric(struct babel_route *route)
route
->
src
->
src_prefix
,
route
->
src
->
src_plen
,
neigh
->
address
,
neigh
->
ifp
->
ifindex
);
neigh
->
ifp
->
ifindex
,
NULL
);
change_route_metric
(
route
,
route
->
refmetric
,
neighbour_cost
(
route
->
neigh
),
add_metric
);
if
(
route_metric
(
route
)
!=
oldmetric
||
...
...
@@ -849,9 +849,9 @@ update_route(const unsigned char *id,
return
NULL
;
add_metric
=
input_filter
(
id
,
prefix
,
plen
,
src_prefix
,
src_plen
,
neigh
->
address
,
neigh
->
ifp
->
ifindex
);
add_metric
=
input_filter
(
id
,
prefix
,
plen
,
src_prefix
,
src_plen
,
neigh
->
address
,
neigh
->
ifp
->
ifindex
,
NULL
);
if
(
add_metric
>=
INFINITY
)
return
NULL
;
...
...
xroute.c
View file @
4df8ccad
...
...
@@ -169,7 +169,8 @@ check_xroutes(int send_updates)
{
int
i
,
j
,
metric
,
export
,
change
=
0
,
rc
;
struct
kernel_route
*
routes
;
int
numroutes
;
struct
filter_result
filter_result
=
{
0
};
int
numroutes
,
numaddresses
;
static
int
maxroutes
=
8
;
const
int
maxmaxroutes
=
16
*
1024
;
...
...
@@ -191,6 +192,8 @@ check_xroutes(int send_updates)
if
(
numroutes
>=
maxroutes
)
goto
resize
;
numaddresses
=
numroutes
;
rc
=
kernel_routes
(
routes
+
numroutes
,
maxroutes
-
numroutes
);
if
(
rc
<
0
)
fprintf
(
stderr
,
"Couldn't get kernel routes.
\n
"
);
...
...
@@ -200,6 +203,21 @@ check_xroutes(int send_updates)
if
(
numroutes
>=
maxroutes
)
goto
resize
;
/* Apply filter to kernel routes (e.g. change the source prefix). */
for
(
i
=
numaddresses
;
i
<
numroutes
;
i
++
)
{
filter_result
.
src_prefix
=
NULL
;
redistribute_filter
(
routes
[
i
].
prefix
,
routes
[
i
].
plen
,
routes
[
i
].
src_prefix
,
routes
[
i
].
src_plen
,
routes
[
i
].
ifindex
,
routes
[
i
].
proto
,
&
filter_result
);
if
(
filter_result
.
src_prefix
)
{
memcpy
(
routes
[
i
].
src_prefix
,
filter_result
.
src_prefix
,
16
);
routes
[
i
].
src_plen
=
filter_result
.
src_plen
;
}
}
/* Check for any routes that need to be flushed */
i
=
0
;
...
...
@@ -207,7 +225,8 @@ check_xroutes(int send_updates)
export
=
0
;
metric
=
redistribute_filter
(
xroutes
[
i
].
prefix
,
xroutes
[
i
].
plen
,
xroutes
[
i
].
src_prefix
,
xroutes
[
i
].
src_plen
,
xroutes
[
i
].
ifindex
,
xroutes
[
i
].
proto
);
xroutes
[
i
].
ifindex
,
xroutes
[
i
].
proto
,
NULL
);
if
(
metric
<
INFINITY
&&
metric
==
xroutes
[
i
].
metric
)
{
for
(
j
=
0
;
j
<
numroutes
;
j
++
)
{
if
(
xroutes
[
i
].
plen
==
routes
[
j
].
plen
&&
...
...
@@ -249,7 +268,7 @@ check_xroutes(int send_updates)
continue
;
metric
=
redistribute_filter
(
routes
[
i
].
prefix
,
routes
[
i
].
plen
,
routes
[
i
].
src_prefix
,
routes
[
i
].
src_plen
,
routes
[
i
].
ifindex
,
routes
[
i
].
proto
);
routes
[
i
].
ifindex
,
routes
[
i
].
proto
,
NULL
);
if
(
metric
<
INFINITY
)
{
rc
=
add_xroute
(
routes
[
i
].
prefix
,
routes
[
i
].
plen
,
routes
[
i
].
src_prefix
,
routes
[
i
].
src_plen
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment