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
ae417d54
Commit
ae417d54
authored
Oct 12, 2015
by
Matthieu Boutier
Committed by
Juliusz Chroboczek
Nov 12, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename "struct kernel_table" in "struct rule".
parent
2c151460
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
36 deletions
+36
-36
kernel_netlink.c
kernel_netlink.c
+36
-36
No files found.
kernel_netlink.c
View file @
ae417d54
...
...
@@ -1689,16 +1689,16 @@ flush_rule(int prio, int family)
/* The table used for non-specific routes is "export_table", therefore, we can
take the convention of plen == 0 <=> empty table. */
struct
kernel_tab
le
{
struct
ru
le
{
unsigned
char
src
[
16
];
unsigned
char
plen
;
unsigned
char
table
;
};
/*
kernel_tables contains informations about the rules we installed. It is an
array
indexed by: <table priority> - src_table_prio.
/*
rules contains informations about the rules we installed. It is an array
indexed by: <table priority> - src_table_prio.
(First entries are the most specific, since they have priority.) */
static
struct
kernel_table
kernel_tab
les
[
SRC_TABLE_NUM
];
static
struct
rule
ru
les
[
SRC_TABLE_NUM
];
/* used tables is indexed by: <table number> - src_table_idx
used_tables[i] == 1 <=> the table number (i + src_table_idx) is used */
static
char
used_tables
[
SRC_TABLE_NUM
]
=
{
0
};
...
...
@@ -1717,9 +1717,9 @@ change_table_priority(const unsigned char *src, int plen, int table,
return
flush_rule
(
old_prio
,
v4mapped
(
src
)
?
AF_INET
:
AF_INET6
);
}
/* Return a new table at index [idx] of
kernel_tables. If cell at that index is
not
free, we need to shift cells (and rules). If it's full, return NULL. */
static
struct
kernel_tab
le
*
/* Return a new table at index [idx] of
rules. If cell at that index is not
free, we need to shift cells (and rules). If it's full, return NULL. */
static
struct
ru
le
*
insert_table
(
const
unsigned
char
*
src
,
unsigned
short
src_plen
,
int
idx
)
{
int
table
;
...
...
@@ -1743,22 +1743,22 @@ insert_table(const unsigned char *src, unsigned short src_plen, int idx)
table
+=
src_table_idx
;
/* Create the table's rule at the right place. Shift rules if necessary. */
if
(
kernel_tab
les
[
idx
].
plen
!=
0
)
{
if
(
ru
les
[
idx
].
plen
!=
0
)
{
/* shift right */
i
=
src_table_used
;
while
(
i
>
idx
)
{
i
--
;
rc
=
change_table_priority
(
kernel_tab
les
[
i
].
src
,
kernel_tab
les
[
i
].
plen
,
kernel_tab
les
[
i
].
table
,
rc
=
change_table_priority
(
ru
les
[
i
].
src
,
ru
les
[
i
].
plen
,
ru
les
[
i
].
table
,
i
+
src_table_prio
,
i
+
1
+
src_table_prio
);
if
(
rc
<
0
)
{
perror
(
"change_table_priority"
);
return
NULL
;
}
kernel_tables
[
i
+
1
]
=
kernel_tab
les
[
i
];
kernel_tab
les
[
i
].
plen
=
0
;
rules
[
i
+
1
]
=
ru
les
[
i
];
ru
les
[
i
].
plen
=
0
;
}
}
...
...
@@ -1768,27 +1768,27 @@ insert_table(const unsigned char *src, unsigned short src_plen, int idx)
return
NULL
;
}
used_tables
[
table
-
src_table_idx
]
=
1
;
memcpy
(
kernel_tab
les
[
idx
].
src
,
src
,
16
);
kernel_tab
les
[
idx
].
plen
=
src_plen
;
kernel_tab
les
[
idx
].
table
=
table
;
memcpy
(
ru
les
[
idx
].
src
,
src
,
16
);
ru
les
[
idx
].
plen
=
src_plen
;
ru
les
[
idx
].
table
=
table
;
src_table_used
++
;
return
&
kernel_tab
les
[
idx
];
return
&
ru
les
[
idx
];
}
/* Sorting
kernel_tables in a well ordered fashion will increase code complexity
and
decrease performances, because more rule shifs will be required, so more
/* Sorting
rules in a well ordered fashion will increase code complexity and
decrease performances, because more rule shifs will be required, so more
system calls invoked. */
static
int
find_table_slot
(
const
unsigned
char
*
src
,
unsigned
short
src_plen
,
int
*
new_return
)
{
struct
kernel_tab
le
*
kt
=
NULL
;
struct
ru
le
*
kt
=
NULL
;
int
i
;
*
new_return
=
-
1
;
for
(
i
=
0
;
i
<
SRC_TABLE_NUM
;
i
++
)
{
kt
=
&
kernel_tab
les
[
i
];
kt
=
&
ru
les
[
i
];
if
(
kt
->
plen
==
0
)
goto
new_table_here
;
/* empty table here */
switch
(
prefix_cmp
(
src
,
src_plen
,
kt
->
src
,
kt
->
plen
))
{
...
...
@@ -1811,7 +1811,7 @@ find_table_slot(const unsigned char *src, unsigned short src_plen,
static
int
find_table
(
const
unsigned
char
*
src
,
unsigned
short
src_plen
)
{
struct
kernel_tab
le
*
kt
=
NULL
;
struct
ru
le
*
kt
=
NULL
;
int
i
,
new_i
;
if
(
src_plen
==
0
||
...
...
@@ -1827,7 +1827,7 @@ find_table(const unsigned char *src, unsigned short src_plen)
return
-
1
;
kt
=
insert_table
(
src
,
src_plen
,
new_i
);
}
else
{
kt
=
&
kernel_tab
les
[
i
];
kt
=
&
ru
les
[
i
];
}
return
kt
==
NULL
?
-
1
:
kt
->
table
;
}
...
...
@@ -1837,10 +1837,10 @@ release_tables(void)
{
int
i
;
for
(
i
=
0
;
i
<
SRC_TABLE_NUM
;
i
++
)
{
if
(
kernel_tab
les
[
i
].
plen
!=
0
)
{
if
(
ru
les
[
i
].
plen
!=
0
)
{
flush_rule
(
i
+
src_table_prio
,
v4mapped
(
kernel_tab
les
[
i
].
src
)
?
AF_INET
:
AF_INET6
);
kernel_tab
les
[
i
].
plen
=
0
;
v4mapped
(
ru
les
[
i
].
src
)
?
AF_INET
:
AF_INET6
);
ru
les
[
i
].
plen
=
0
;
}
used_tables
[
i
]
=
0
;
}
...
...
@@ -1935,8 +1935,8 @@ filter_kernel_rules(struct nlmsghdr *nh, void *data)
return
1
;
if
(
prefix_cmp
(
src
,
src_plen
,
kernel_tables
[
i
].
src
,
kernel_tab
les
[
i
].
plen
)
==
PST_EQUALS
&&
table
==
kernel_tab
les
[
i
].
table
&&
rules
[
i
].
src
,
ru
les
[
i
].
plen
)
==
PST_EQUALS
&&
table
==
ru
les
[
i
].
table
&&
!
rule_exists
[
i
])
{
rule_exists
[
i
]
=
1
;
}
else
{
...
...
@@ -1944,7 +1944,7 @@ filter_kernel_rules(struct nlmsghdr *nh, void *data)
do
{
rc
=
flush_rule
(
i
+
src_table_prio
,
is_v4
?
AF_INET
:
AF_INET6
);
}
while
(
rc
>=
0
);
/* flush unexpected rules, but keep information in
kernel_tab
les[i]. It
/* flush unexpected rules, but keep information in
ru
les[i]. It
will be used afterwards to reinstall the rule. */
if
(
errno
!=
ENOENT
&&
errno
!=
EEXIST
)
fprintf
(
stderr
,
...
...
@@ -1968,16 +1968,16 @@ install_missing_rules(char rule_exists[SRC_TABLE_NUM], int v4)
{
int
i
,
rc
;
for
(
i
=
0
;
i
<
SRC_TABLE_NUM
;
i
++
)
if
(
v4mapped
(
kernel_tab
les
[
i
].
src
)
==
v4
&&
!
rule_exists
[
i
]
&&
kernel_tab
les
[
i
].
plen
!=
0
)
{
rc
=
add_rule
(
i
+
src_table_prio
,
kernel_tab
les
[
i
].
src
,
kernel_tables
[
i
].
plen
,
kernel_tab
les
[
i
].
table
);
if
(
v4mapped
(
ru
les
[
i
].
src
)
==
v4
&&
!
rule_exists
[
i
]
&&
ru
les
[
i
].
plen
!=
0
)
{
rc
=
add_rule
(
i
+
src_table_prio
,
ru
les
[
i
].
src
,
rules
[
i
].
plen
,
ru
les
[
i
].
table
);
if
(
rc
<
0
)
fprintf
(
stderr
,
"install_missing_rules: "
"Cannot install rule: table %d prio %d from %s
\n
"
,
kernel_tab
les
[
i
].
table
,
i
+
src_table_prio
,
format_prefix
(
kernel_tab
les
[
i
].
src
,
kernel_tab
les
[
i
].
plen
));
ru
les
[
i
].
table
,
i
+
src_table_prio
,
format_prefix
(
ru
les
[
i
].
src
,
ru
les
[
i
].
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