Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libdap
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
cellframe
libdap
Commits
1d6029b5
Commit
1d6029b5
authored
6 years ago
by
cheloveck3-0
Committed by
Kurotych Anatolii
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
additional events on network monitoring (#42)
parent
cc2353da
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/unix/linux/dap_network_monitor.c
+39
-10
39 additions, 10 deletions
core/unix/linux/dap_network_monitor.c
core/unix/linux/dap_network_monitor.h
+8
-1
8 additions, 1 deletion
core/unix/linux/dap_network_monitor.h
with
47 additions
and
11 deletions
core/unix/linux/dap_network_monitor.c
+
39
−
10
View file @
1d6029b5
...
@@ -49,14 +49,14 @@ int dap_network_monitor_init(dap_network_monitor_notification_callback_t cb)
...
@@ -49,14 +49,14 @@ int dap_network_monitor_init(dap_network_monitor_notification_callback_t cb)
{
{
memset
((
void
*
)
&
_net_notification
,
0
,
sizeof
(
_net_notification
));
memset
((
void
*
)
&
_net_notification
,
0
,
sizeof
(
_net_notification
));
if
((
_net_notification
.
socket
=
socket
(
P
F_NETLINK
,
SOCK_RAW
,
NETLINK_ROUTE
))
==
-
1
)
{
if
((
_net_notification
.
socket
=
socket
(
A
F_NETLINK
,
SOCK_RAW
,
NETLINK_ROUTE
))
==
-
1
)
{
log_it
(
L_ERROR
,
"Can't open notification socket"
);
log_it
(
L_ERROR
,
"Can't open notification socket"
);
return
-
1
;
return
-
1
;
}
}
struct
sockaddr_nl
addr
=
{
0
};
struct
sockaddr_nl
addr
=
{
0
};
addr
.
nl_family
=
AF_NETLINK
;
addr
.
nl_family
=
AF_NETLINK
;
addr
.
nl_groups
=
RTMGRP_IPV4_IFADDR
|
RTMGRP_IPV4_ROUTE
;
addr
.
nl_groups
=
RTMGRP_LINK
|
RTMGRP_IPV4_IFADDR
|
RTMGRP_IPV4_ROUTE
;
if
(
bind
(
_net_notification
.
socket
,
(
struct
sockaddr
*
)
&
addr
,
sizeof
(
addr
))
==
-
1
)
{
if
(
bind
(
_net_notification
.
socket
,
(
struct
sockaddr
*
)
&
addr
,
sizeof
(
addr
))
==
-
1
)
{
log_it
(
L_ERROR
,
"Can't bind notification socket"
);
log_it
(
L_ERROR
,
"Can't bind notification socket"
);
return
-
2
;
return
-
2
;
...
@@ -161,6 +161,27 @@ static void _route_msg_handler(struct nlmsghdr *nlh,
...
@@ -161,6 +161,27 @@ static void _route_msg_handler(struct nlmsghdr *nlh,
}
}
static
void
_link_msg_handler
(
struct
nlmsghdr
*
nlh
,
dap_network_notification_t
*
result
,
struct
sockaddr_nl
sa
){
struct
ifaddrmsg
*
ifa
=
NLMSG_DATA
(
nlh
);
struct
ifinfomsg
*
ifi
=
NLMSG_DATA
(
nlh
);;
switch
(
nlh
->
nlmsg_type
){
case
RTM_NEWLINK
:
if_indextoname
(
ifa
->
ifa_index
,
result
->
link
.
interface_name
);
result
->
link
.
is_up
=
ifi
->
ifi_flags
&
IFF_UP
?
true
:
false
;
result
->
link
.
is_running
=
ifi
->
ifi_flags
&
IFF_RUNNING
?
true
:
false
;
//printf("netlink_link_state: Link %s is %s and %s\n",
// result->link.interface_name, (ifi->ifi_flags & IFF_UP)?"Up":"Down", (ifi->ifi_flags & IFF_RUNNING)?"Running":"Not Running");
break
;
case
RTM_DELLINK
:
if_indextoname
(
ifa
->
ifa_index
,
result
->
link
.
interface_name
);
//printf("msg_handler: RTM_DELLINK : %s\n",result->link.interface_name);
break
;
}
}
static
void
clear_results
(
dap_network_notification_t
*
cb_result
)
static
void
clear_results
(
dap_network_notification_t
*
cb_result
)
{
{
bzero
(
cb_result
,
sizeof
(
dap_network_notification_t
));
bzero
(
cb_result
,
sizeof
(
dap_network_notification_t
));
...
@@ -177,19 +198,24 @@ static void* network_monitor_worker(void *arg)
...
@@ -177,19 +198,24 @@ static void* network_monitor_worker(void *arg)
return
NULL
;
return
NULL
;
}
}
char
buffer
[
4096
];
dap_network_notification_t
callback_result
;
dap_network_notification_t
callback_result
;
struct
nlmsghdr
*
nlh
=
(
struct
nlmsghdr
*
)
buffer
;
int
len
;
int
len
;
char
buf
[
4096
];
struct
iovec
iov
=
{
buf
,
sizeof
(
buf
)
};
struct
sockaddr_nl
sa
;
struct
nlmsghdr
*
nlh
;
struct
msghdr
msg
=
{
&
sa
,
sizeof
(
sa
),
&
iov
,
1
,
NULL
,
0
,
0
};
pthread_barrier_wait
(
barrier
);
pthread_barrier_wait
(
barrier
);
while
((
len
=
recvmsg
(
_net_notification
.
socket
,
&
msg
,
0
))
>
0
){
while
((
len
=
recv
(
_net_notification
.
socket
,
nlh
,
sizeof
(
buffer
),
0
))
>
0
)
{
_send_NLM_F_ACK_msg
(
_net_notification
.
socket
);
_send_NLM_F_ACK_msg
(
_net_notification
.
socket
);
for
(;
(
NLMSG_OK
(
nlh
,
len
))
&&
(
nlh
->
nlmsg_type
!=
NLMSG_DONE
);
nlh
=
NLMSG_NEXT
(
nlh
,
len
))
{
for
(
nlh
=
(
struct
nlmsghdr
*
)
buf
;
(
NLMSG_OK
(
nlh
,
len
))
&&
(
nlh
->
nlmsg_type
!=
NLMSG_DONE
);
nlh
=
NLMSG_NEXT
(
nlh
,
len
))
{
if
(
nlh
->
nlmsg_type
==
NLMSG_ERROR
){
/* Do some error handling. */
log_it
(
L_DEBUG
,
"There an error! nlmsg_type %d"
,
nlh
->
nlmsg_type
);
break
;
}
clear_results
(
&
callback_result
);
clear_results
(
&
callback_result
);
...
@@ -198,7 +224,10 @@ static void* network_monitor_worker(void *arg)
...
@@ -198,7 +224,10 @@ static void* network_monitor_worker(void *arg)
_ip_addr_msg_handler
(
nlh
,
&
callback_result
);
_ip_addr_msg_handler
(
nlh
,
&
callback_result
);
}
else
if
(
nlh
->
nlmsg_type
==
RTM_NEWROUTE
||
nlh
->
nlmsg_type
==
RTM_DELROUTE
)
{
}
else
if
(
nlh
->
nlmsg_type
==
RTM_NEWROUTE
||
nlh
->
nlmsg_type
==
RTM_DELROUTE
)
{
_route_msg_handler
(
nlh
,
&
callback_result
,
len
);
_route_msg_handler
(
nlh
,
&
callback_result
,
len
);
}
else
{
}
else
if
(
nlh
->
nlmsg_type
==
RTM_NEWLINK
||
nlh
->
nlmsg_type
==
RTM_DELLINK
){
_link_msg_handler
(
nlh
,
&
callback_result
,
sa
);
}
else
{
log_it
(
L_DEBUG
,
"Not supported msg type %d"
,
nlh
->
nlmsg_type
);
log_it
(
L_DEBUG
,
"Not supported msg type %d"
,
nlh
->
nlmsg_type
);
continue
;
continue
;
}
}
...
...
This diff is collapsed.
Click to expand it.
core/unix/linux/dap_network_monitor.h
+
8
−
1
View file @
1d6029b5
...
@@ -41,7 +41,9 @@ typedef enum {
...
@@ -41,7 +41,9 @@ typedef enum {
IP_ADDR_ADD
=
RTM_NEWADDR
,
IP_ADDR_ADD
=
RTM_NEWADDR
,
IP_ADDR_REMOVE
,
IP_ADDR_REMOVE
,
IP_ROUTE_ADD
=
RTM_NEWROUTE
,
IP_ROUTE_ADD
=
RTM_NEWROUTE
,
IP_ROUTE_REMOVE
IP_ROUTE_REMOVE
,
IP_LINK_NEW
=
RTM_NEWLINK
,
IP_LINK_DEL
}
dap_network_monitor_notification_type_t
;
}
dap_network_monitor_notification_type_t
;
typedef
struct
{
typedef
struct
{
...
@@ -60,6 +62,11 @@ typedef struct {
...
@@ -60,6 +62,11 @@ typedef struct {
uint8_t
protocol
;
uint8_t
protocol
;
uint8_t
netmask
;
uint8_t
netmask
;
}
route
;
// for IP_ROUTE_ADD, IP_ROUTE_REMOVE
}
route
;
// for IP_ROUTE_ADD, IP_ROUTE_REMOVE
struct
{
char
interface_name
[
IF_NAMESIZE
];
bool
is_up
;
bool
is_running
;
}
link
;
// for RTM_NEWLINK, RTM_DELLINK
};
};
}
dap_network_notification_t
;
}
dap_network_notification_t
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment