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
ce4f5752
Commit
ce4f5752
authored
Sep 18, 2020
by
Michael Tremer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
networks: Rename start_address to first_address
Signed-off-by:
Michael Tremer
<
michael.tremer@ipfire.org
>
parent
43554dc4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
17 deletions
+17
-17
src/loc/network.h
src/loc/network.h
+1
-1
src/network.c
src/network.c
+16
-16
No files found.
src/loc/network.h
View file @
ce4f5752
...
...
@@ -30,7 +30,7 @@ enum loc_network_flags {
struct
loc_network
;
int
loc_network_new
(
struct
loc_ctx
*
ctx
,
struct
loc_network
**
network
,
struct
in6_addr
*
star
t_address
,
unsigned
int
prefix
);
struct
in6_addr
*
firs
t_address
,
unsigned
int
prefix
);
int
loc_network_new_from_string
(
struct
loc_ctx
*
ctx
,
struct
loc_network
**
network
,
const
char
*
address_string
);
struct
loc_network
*
loc_network_ref
(
struct
loc_network
*
network
);
...
...
src/network.c
View file @
ce4f5752
...
...
@@ -35,7 +35,7 @@ struct loc_network {
struct
loc_ctx
*
ctx
;
int
refcount
;
struct
in6_addr
star
t_address
;
struct
in6_addr
firs
t_address
;
unsigned
int
prefix
;
char
country_code
[
3
];
...
...
@@ -75,7 +75,7 @@ static struct in6_addr prefix_to_bitmask(unsigned int prefix) {
return
bitmask
;
}
static
struct
in6_addr
make_
star
t_address
(
const
struct
in6_addr
*
address
,
unsigned
int
prefix
)
{
static
struct
in6_addr
make_
firs
t_address
(
const
struct
in6_addr
*
address
,
unsigned
int
prefix
)
{
struct
in6_addr
a
;
struct
in6_addr
bitmask
=
prefix_to_bitmask
(
prefix
);
...
...
@@ -137,7 +137,7 @@ LOC_EXPORT int loc_network_new(struct loc_ctx* ctx, struct loc_network** network
n
->
refcount
=
1
;
// Store the first address in the network
n
->
start_address
=
make_star
t_address
(
address
,
prefix
);
n
->
first_address
=
make_firs
t_address
(
address
,
prefix
);
n
->
prefix
=
prefix
;
DEBUG
(
n
->
ctx
,
"Network allocated at %p
\n
"
,
n
);
...
...
@@ -147,7 +147,7 @@ LOC_EXPORT int loc_network_new(struct loc_ctx* ctx, struct loc_network** network
LOC_EXPORT
int
loc_network_new_from_string
(
struct
loc_ctx
*
ctx
,
struct
loc_network
**
network
,
const
char
*
address_string
)
{
struct
in6_addr
star
t_address
;
struct
in6_addr
firs
t_address
;
unsigned
int
prefix
=
0
;
char
*
prefix_string
;
int
r
=
1
;
...
...
@@ -166,10 +166,10 @@ LOC_EXPORT int loc_network_new_from_string(struct loc_ctx* ctx, struct loc_netwo
if
(
prefix
)
{
// Parse the address
r
=
loc_parse_address
(
ctx
,
address_string
,
&
star
t_address
);
r
=
loc_parse_address
(
ctx
,
address_string
,
&
firs
t_address
);
// Map the prefix to IPv6 if needed
if
(
IN6_IS_ADDR_V4MAPPED
(
&
star
t_address
))
if
(
IN6_IS_ADDR_V4MAPPED
(
&
firs
t_address
))
prefix
+=
96
;
}
}
...
...
@@ -178,7 +178,7 @@ LOC_EXPORT int loc_network_new_from_string(struct loc_ctx* ctx, struct loc_netwo
free
(
buffer
);
if
(
r
==
0
)
{
r
=
loc_network_new
(
ctx
,
network
,
&
star
t_address
,
prefix
);
r
=
loc_network_new
(
ctx
,
network
,
&
firs
t_address
,
prefix
);
}
return
r
;
...
...
@@ -240,11 +240,11 @@ LOC_EXPORT char* loc_network_str(struct loc_network* network) {
int
family
=
loc_network_address_family
(
network
);
switch
(
family
)
{
case
AF_INET6
:
r
=
format_ipv6_address
(
&
network
->
star
t_address
,
string
,
length
);
r
=
format_ipv6_address
(
&
network
->
firs
t_address
,
string
,
length
);
break
;
case
AF_INET
:
r
=
format_ipv4_address
(
&
network
->
star
t_address
,
string
,
length
);
r
=
format_ipv4_address
(
&
network
->
firs
t_address
,
string
,
length
);
prefix
-=
96
;
break
;
...
...
@@ -267,7 +267,7 @@ LOC_EXPORT char* loc_network_str(struct loc_network* network) {
}
LOC_EXPORT
int
loc_network_address_family
(
struct
loc_network
*
network
)
{
if
(
IN6_IS_ADDR_V4MAPPED
(
&
network
->
star
t_address
))
if
(
IN6_IS_ADDR_V4MAPPED
(
&
network
->
firs
t_address
))
return
AF_INET
;
return
AF_INET6
;
...
...
@@ -275,11 +275,11 @@ LOC_EXPORT int loc_network_address_family(struct loc_network* network) {
LOC_EXPORT
int
loc_network_match_address
(
struct
loc_network
*
network
,
const
struct
in6_addr
*
address
)
{
// Address must be larger than the start address
if
(
in6_addr_cmp
(
&
network
->
star
t_address
,
address
)
>
0
)
if
(
in6_addr_cmp
(
&
network
->
firs
t_address
,
address
)
>
0
)
return
1
;
// Determine the last address in this network
struct
in6_addr
last_address
=
make_last_address
(
&
network
->
star
t_address
,
network
->
prefix
);
struct
in6_addr
last_address
=
make_last_address
(
&
network
->
firs
t_address
,
network
->
prefix
);
// Address must be smaller than the last address
if
(
in6_addr_cmp
(
address
,
&
last_address
)
>
0
)
...
...
@@ -349,12 +349,12 @@ LOC_EXPORT int loc_network_match_flag(struct loc_network* network, uint32_t flag
LOC_EXPORT
int
loc_network_is_subnet_of
(
struct
loc_network
*
self
,
struct
loc_network
*
other
)
{
// If the start address of the other network is smaller than this network,
// it cannot be a subnet.
if
(
in6_addr_cmp
(
&
self
->
start_address
,
&
other
->
star
t_address
)
<
0
)
if
(
in6_addr_cmp
(
&
self
->
first_address
,
&
other
->
firs
t_address
)
<
0
)
return
0
;
// Get the end addresses
struct
in6_addr
last_address_self
=
make_last_address
(
&
self
->
star
t_address
,
self
->
prefix
);
struct
in6_addr
last_address_other
=
make_last_address
(
&
other
->
star
t_address
,
other
->
prefix
);
struct
in6_addr
last_address_self
=
make_last_address
(
&
self
->
firs
t_address
,
self
->
prefix
);
struct
in6_addr
last_address_other
=
make_last_address
(
&
other
->
firs
t_address
,
other
->
prefix
);
// If the end address of the other network is greater than this network,
// it cannot be a subnet.
...
...
@@ -570,7 +570,7 @@ LOC_EXPORT int loc_network_tree_add_network(struct loc_network_tree* tree, struc
DEBUG
(
tree
->
ctx
,
"Adding network %p to tree %p
\n
"
,
network
,
tree
);
struct
loc_network_tree_node
*
node
=
loc_network_tree_get_path
(
tree
,
&
network
->
star
t_address
,
network
->
prefix
);
&
network
->
firs
t_address
,
network
->
prefix
);
if
(
!
node
)
{
ERROR
(
tree
->
ctx
,
"Could not find a node
\n
"
);
return
-
ENOMEM
;
...
...
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