Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libloc
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
libloc
Commits
88a3db10
Commit
88a3db10
authored
Mar 07, 2022
by
Michael Tremer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
network-list: Cap prefix length based on family
Signed-off-by:
Michael Tremer
<
michael.tremer@ipfire.org
>
parent
9306c68d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
4 deletions
+27
-4
src/libloc/network.h
src/libloc/network.h
+13
-0
src/network-list.c
src/network-list.c
+14
-4
No files found.
src/libloc/network.h
View file @
88a3db10
...
...
@@ -103,6 +103,19 @@ static inline int loc_address_family(const struct in6_addr* address) {
return
AF_INET6
;
}
static
inline
int
loc_address_family_bit_length
(
const
int
family
)
{
switch
(
family
)
{
case
AF_INET6
:
return
128
;
case
AF_INET
:
return
32
;
default:
return
-
1
;
}
}
static
inline
int
loc_address_all_zeroes
(
const
struct
in6_addr
*
address
)
{
struct
in6_addr
all_zeroes
=
IN6ADDR_ANY_INIT
;
...
...
src/network-list.c
View file @
88a3db10
...
...
@@ -307,10 +307,11 @@ int loc_network_list_summarize(struct loc_ctx* ctx,
return
1
;
}
int
family
=
loc_address_family
(
first
);
const
int
family1
=
loc_address_family
(
first
);
const
int
family2
=
loc_address_family
(
last
);
//
Families must
match
if
(
family
!=
loc_address_family
(
last
)
)
{
//
Check if address families
match
if
(
family
1
!=
family2
)
{
ERROR
(
ctx
,
"Address families do not match
\n
"
);
errno
=
EINVAL
;
return
1
;
...
...
@@ -326,11 +327,20 @@ int loc_network_list_summarize(struct loc_ctx* ctx,
struct
loc_network
*
network
=
NULL
;
struct
in6_addr
start
=
*
first
;
const
int
family_bit_length
=
loc_address_family_bit_length
(
family1
);
while
(
in6_addr_cmp
(
&
start
,
last
)
<=
0
)
{
struct
in6_addr
num
;
int
bits1
;
// Find the number of trailing zeroes of the start address
int
bits1
=
loc_address_count_trailing_zero_bits
(
&
start
);
if
(
loc_address_all_zeroes
(
&
start
))
bits1
=
family_bit_length
;
else
{
bits1
=
loc_address_count_trailing_zero_bits
(
&
start
);
if
(
bits1
>
family_bit_length
)
bits1
=
family_bit_length
;
}
// Subtract the start address from the last address and add one
// (i.e. how many addresses are in this network?)
...
...
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