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)
...
@@ -1689,16 +1689,16 @@ flush_rule(int prio, int family)
/* The table used for non-specific routes is "export_table", therefore, we can
/* The table used for non-specific routes is "export_table", therefore, we can
take the convention of plen == 0 <=> empty table. */
take the convention of plen == 0 <=> empty table. */
struct
kernel_tab
le
{
struct
ru
le
{
unsigned
char
src
[
16
];
unsigned
char
src
[
16
];
unsigned
char
plen
;
unsigned
char
plen
;
unsigned
char
table
;
unsigned
char
table
;
};
};
/*
kernel_tables contains informations about the rules we installed. It is an
/*
rules contains informations about the rules we installed. It is an array
array
indexed by: <table priority> - src_table_prio.
indexed by: <table priority> - src_table_prio.
(First entries are the most specific, since they have priority.) */
(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 is indexed by: <table number> - src_table_idx
used_tables[i] == 1 <=> the table number (i + src_table_idx) is used */
used_tables[i] == 1 <=> the table number (i + src_table_idx) is used */
static
char
used_tables
[
SRC_TABLE_NUM
]
=
{
0
};
static
char
used_tables
[
SRC_TABLE_NUM
]
=
{
0
};
...
@@ -1717,9 +1717,9 @@ change_table_priority(const unsigned char *src, int plen, int table,
...
@@ -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
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
/* Return a new table at index [idx] of
rules. If cell at that index is not
not
free, we need to shift cells (and rules). If it's full, return NULL. */
free, we need to shift cells (and rules). If it's full, return NULL. */
static
struct
kernel_tab
le
*
static
struct
ru
le
*
insert_table
(
const
unsigned
char
*
src
,
unsigned
short
src_plen
,
int
idx
)
insert_table
(
const
unsigned
char
*
src
,
unsigned
short
src_plen
,
int
idx
)
{
{
int
table
;
int
table
;
...
@@ -1743,22 +1743,22 @@ insert_table(const unsigned char *src, unsigned short src_plen, int idx)
...
@@ -1743,22 +1743,22 @@ insert_table(const unsigned char *src, unsigned short src_plen, int idx)
table
+=
src_table_idx
;
table
+=
src_table_idx
;
/* Create the table's rule at the right place. Shift rules if necessary. */
/* 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 */
/* shift right */
i
=
src_table_used
;
i
=
src_table_used
;
while
(
i
>
idx
)
{
while
(
i
>
idx
)
{
i
--
;
i
--
;
rc
=
change_table_priority
(
kernel_tab
les
[
i
].
src
,
rc
=
change_table_priority
(
ru
les
[
i
].
src
,
kernel_tab
les
[
i
].
plen
,
ru
les
[
i
].
plen
,
kernel_tab
les
[
i
].
table
,
ru
les
[
i
].
table
,
i
+
src_table_prio
,
i
+
src_table_prio
,
i
+
1
+
src_table_prio
);
i
+
1
+
src_table_prio
);
if
(
rc
<
0
)
{
if
(
rc
<
0
)
{
perror
(
"change_table_priority"
);
perror
(
"change_table_priority"
);
return
NULL
;
return
NULL
;
}
}
kernel_tables
[
i
+
1
]
=
kernel_tab
les
[
i
];
rules
[
i
+
1
]
=
ru
les
[
i
];
kernel_tab
les
[
i
].
plen
=
0
;
ru
les
[
i
].
plen
=
0
;
}
}
}
}
...
@@ -1768,27 +1768,27 @@ insert_table(const unsigned char *src, unsigned short src_plen, int idx)
...
@@ -1768,27 +1768,27 @@ insert_table(const unsigned char *src, unsigned short src_plen, int idx)
return
NULL
;
return
NULL
;
}
}
used_tables
[
table
-
src_table_idx
]
=
1
;
used_tables
[
table
-
src_table_idx
]
=
1
;
memcpy
(
kernel_tab
les
[
idx
].
src
,
src
,
16
);
memcpy
(
ru
les
[
idx
].
src
,
src
,
16
);
kernel_tab
les
[
idx
].
plen
=
src_plen
;
ru
les
[
idx
].
plen
=
src_plen
;
kernel_tab
les
[
idx
].
table
=
table
;
ru
les
[
idx
].
table
=
table
;
src_table_used
++
;
src_table_used
++
;
return
&
kernel_tab
les
[
idx
];
return
&
ru
les
[
idx
];
}
}
/* Sorting
kernel_tables in a well ordered fashion will increase code complexity
/* Sorting
rules in a well ordered fashion will increase code complexity and
and
decrease performances, because more rule shifs will be required, so more
decrease performances, because more rule shifs will be required, so more
system calls invoked. */
system calls invoked. */
static
int
static
int
find_table_slot
(
const
unsigned
char
*
src
,
unsigned
short
src_plen
,
find_table_slot
(
const
unsigned
char
*
src
,
unsigned
short
src_plen
,
int
*
new_return
)
int
*
new_return
)
{
{
struct
kernel_tab
le
*
kt
=
NULL
;
struct
ru
le
*
kt
=
NULL
;
int
i
;
int
i
;
*
new_return
=
-
1
;
*
new_return
=
-
1
;
for
(
i
=
0
;
i
<
SRC_TABLE_NUM
;
i
++
)
{
for
(
i
=
0
;
i
<
SRC_TABLE_NUM
;
i
++
)
{
kt
=
&
kernel_tab
les
[
i
];
kt
=
&
ru
les
[
i
];
if
(
kt
->
plen
==
0
)
if
(
kt
->
plen
==
0
)
goto
new_table_here
;
/* empty table here */
goto
new_table_here
;
/* empty table here */
switch
(
prefix_cmp
(
src
,
src_plen
,
kt
->
src
,
kt
->
plen
))
{
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,
...
@@ -1811,7 +1811,7 @@ find_table_slot(const unsigned char *src, unsigned short src_plen,
static
int
static
int
find_table
(
const
unsigned
char
*
src
,
unsigned
short
src_plen
)
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
;
int
i
,
new_i
;
if
(
src_plen
==
0
||
if
(
src_plen
==
0
||
...
@@ -1827,7 +1827,7 @@ find_table(const unsigned char *src, unsigned short src_plen)
...
@@ -1827,7 +1827,7 @@ find_table(const unsigned char *src, unsigned short src_plen)
return
-
1
;
return
-
1
;
kt
=
insert_table
(
src
,
src_plen
,
new_i
);
kt
=
insert_table
(
src
,
src_plen
,
new_i
);
}
else
{
}
else
{
kt
=
&
kernel_tab
les
[
i
];
kt
=
&
ru
les
[
i
];
}
}
return
kt
==
NULL
?
-
1
:
kt
->
table
;
return
kt
==
NULL
?
-
1
:
kt
->
table
;
}
}
...
@@ -1837,10 +1837,10 @@ release_tables(void)
...
@@ -1837,10 +1837,10 @@ release_tables(void)
{
{
int
i
;
int
i
;
for
(
i
=
0
;
i
<
SRC_TABLE_NUM
;
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
,
flush_rule
(
i
+
src_table_prio
,
v4mapped
(
kernel_tab
les
[
i
].
src
)
?
AF_INET
:
AF_INET6
);
v4mapped
(
ru
les
[
i
].
src
)
?
AF_INET
:
AF_INET6
);
kernel_tab
les
[
i
].
plen
=
0
;
ru
les
[
i
].
plen
=
0
;
}
}
used_tables
[
i
]
=
0
;
used_tables
[
i
]
=
0
;
}
}
...
@@ -1935,8 +1935,8 @@ filter_kernel_rules(struct nlmsghdr *nh, void *data)
...
@@ -1935,8 +1935,8 @@ filter_kernel_rules(struct nlmsghdr *nh, void *data)
return
1
;
return
1
;
if
(
prefix_cmp
(
src
,
src_plen
,
if
(
prefix_cmp
(
src
,
src_plen
,
kernel_tables
[
i
].
src
,
kernel_tab
les
[
i
].
plen
)
==
PST_EQUALS
&&
rules
[
i
].
src
,
ru
les
[
i
].
plen
)
==
PST_EQUALS
&&
table
==
kernel_tab
les
[
i
].
table
&&
table
==
ru
les
[
i
].
table
&&
!
rule_exists
[
i
])
{
!
rule_exists
[
i
])
{
rule_exists
[
i
]
=
1
;
rule_exists
[
i
]
=
1
;
}
else
{
}
else
{
...
@@ -1944,7 +1944,7 @@ filter_kernel_rules(struct nlmsghdr *nh, void *data)
...
@@ -1944,7 +1944,7 @@ filter_kernel_rules(struct nlmsghdr *nh, void *data)
do
{
do
{
rc
=
flush_rule
(
i
+
src_table_prio
,
is_v4
?
AF_INET
:
AF_INET6
);
rc
=
flush_rule
(
i
+
src_table_prio
,
is_v4
?
AF_INET
:
AF_INET6
);
}
while
(
rc
>=
0
);
}
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. */
will be used afterwards to reinstall the rule. */
if
(
errno
!=
ENOENT
&&
errno
!=
EEXIST
)
if
(
errno
!=
ENOENT
&&
errno
!=
EEXIST
)
fprintf
(
stderr
,
fprintf
(
stderr
,
...
@@ -1968,16 +1968,16 @@ install_missing_rules(char rule_exists[SRC_TABLE_NUM], int v4)
...
@@ -1968,16 +1968,16 @@ install_missing_rules(char rule_exists[SRC_TABLE_NUM], int v4)
{
{
int
i
,
rc
;
int
i
,
rc
;
for
(
i
=
0
;
i
<
SRC_TABLE_NUM
;
i
++
)
for
(
i
=
0
;
i
<
SRC_TABLE_NUM
;
i
++
)
if
(
v4mapped
(
kernel_tab
les
[
i
].
src
)
==
v4
&&
if
(
v4mapped
(
ru
les
[
i
].
src
)
==
v4
&&
!
rule_exists
[
i
]
&&
kernel_tab
les
[
i
].
plen
!=
0
)
{
!
rule_exists
[
i
]
&&
ru
les
[
i
].
plen
!=
0
)
{
rc
=
add_rule
(
i
+
src_table_prio
,
kernel_tab
les
[
i
].
src
,
rc
=
add_rule
(
i
+
src_table_prio
,
ru
les
[
i
].
src
,
kernel_tables
[
i
].
plen
,
kernel_tab
les
[
i
].
table
);
rules
[
i
].
plen
,
ru
les
[
i
].
table
);
if
(
rc
<
0
)
if
(
rc
<
0
)
fprintf
(
stderr
,
fprintf
(
stderr
,
"install_missing_rules: "
"install_missing_rules: "
"Cannot install rule: table %d prio %d from %s
\n
"
,
"Cannot install rule: table %d prio %d from %s
\n
"
,
kernel_tab
les
[
i
].
table
,
i
+
src_table_prio
,
ru
les
[
i
].
table
,
i
+
src_table_prio
,
format_prefix
(
kernel_tab
les
[
i
].
src
,
format_prefix
(
ru
les
[
i
].
src
,
kernel_tab
les
[
i
].
plen
));
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