Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add in support for network namespaces #676

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,38 @@ include(CheckTypeSize)
check_include_file(inttypes.h HAVE_INTTYPES_H)
check_include_file(stdint.h HAVE_STDINT_H)
check_include_file(unistd.h HAVE_UNISTD_H)
check_include_file(sys/capability.h HAVE_SYS_CAPABILITY_H)
if(HAVE_SYS_CAPABILITY_H)
add_definitions(-DHAVE_SYS_CAPABILITY=1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be true only if HAVE_SYS_CAPABILITY (set below on lines 326-336 is true?

check_c_source_compiles(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can HAVE_LINUX_NETWORK_NAMESPACE without HAVE_SYS_CAPABILITY_H, no?

"#define _GNU_SOURCE
#include <sched.h>

int
main(void)
{
int i = setns( 0, CLONE_NEWNET );
return 0;
}
"
HAVE_LINUX_NETWORK_NAMESPACE)
if(HAVE_LINUX_NETWORK_NAMESPACE)
add_definitions(-DHAVE_LINUX_NETWORK_NAMESPACE=1)
endif(HAVE_LINUX_NETWORK_NAMESPACE)
endif(HAVE_SYS_CAPABILITY_H)

check_c_source_compiles(
"# include <sys/capability.h>

int
main(void)
{
cap_value_t cap_list[3] = { CAP_NET_ADMIN, CAP_NET_RAW, CAP_SYS_ADMIN };
return 0;
}
"
HAVE_SYS_CAPABILITY)

if(NOT HAVE_UNISTD_H)
add_definitions(-DYY_NO_UNISTD_H)
endif(NOT HAVE_UNISTD_H)
Expand Down
12 changes: 10 additions & 2 deletions fad-getad.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,16 @@ get_sa_len(struct sockaddr *addr)
* could be opened.
*/
int
pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
pcap_findalldevs_interfaces(const char *dev_prefix, pcap_if_list_t *devlistp, char *errbuf,
int (*check_usable)(const char *), get_if_flags_func get_flags_func)
{
struct ifaddrs *ifap, *ifa;
struct sockaddr *addr, *netmask, *broadaddr, *dstaddr;
size_t addr_size, broadaddr_size, dstaddr_size;
int ret = 0;
char *p, *q;
char devbuf[120];
char *devname;

/*
* Get the list of interface addresses.
Expand Down Expand Up @@ -261,10 +263,16 @@ pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
dstaddr_size = 0;
}

if (dev_prefix) {
snprintf( devbuf, sizeof(devbuf), "%s%s", dev_prefix, ifa->ifa_name );
devname = devbuf;
} else {
devname = ifa->ifa_name;
}
/*
* Add information for this address to the list.
*/
if (add_addr_to_if(devlistp, ifa->ifa_name, ifa->ifa_flags,
if (add_addr_to_if(devlistp, devname, ifa->ifa_flags,
get_flags_func,
addr, addr_size, netmask, addr_size,
broadaddr, broadaddr_size, dstaddr, dstaddr_size,
Expand Down
2 changes: 1 addition & 1 deletion fad-gifc.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ struct rtentry; /* declarations in <net/if.h> */
* we already have that.
*/
int
pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
pcap_findalldevs_interfaces(const char *dev_prefix, pcap_if_list_t *devlistp, char *errbuf,
int (*check_usable)(const char *), get_if_flags_func get_flags_func)
{
register int fd;
Expand Down
2 changes: 1 addition & 1 deletion fad-glifc.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct rtentry; /* declarations in <net/if.h> */
* SIOCGLIFCONF rather than SIOCGIFCONF in order to get IPv6 addresses.)
*/
int
pcap_findalldevs_interfaces(pcap_if_list_t *devlistp, char *errbuf,
pcap_findalldevs_interfaces(const char *dev_prefix, pcap_if_list_t *devlistp, char *errbuf,
int (*check_usable)(const char *), get_if_flags_func get_flags_func)
{
register int fd4, fd6, fd;
Expand Down
2 changes: 1 addition & 1 deletion pcap-bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2851,7 +2851,7 @@ pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
/*
* Get the list of regular interfaces first.
*/
if (pcap_findalldevs_interfaces(devlistp, errbuf, check_bpf_bindable,
if (pcap_findalldevs_interfaces(NULL, devlistp, errbuf, check_bpf_bindable,
get_if_flags) == -1)
return (-1); /* failure */

Expand Down
2 changes: 1 addition & 1 deletion pcap-dlpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
/*
* Get the list of regular interfaces first.
*/
if (pcap_findalldevs_interfaces(devlistp, errbuf, is_dlpi_interface,
if (pcap_findalldevs_interfaces(NULL, devlistp, errbuf, is_dlpi_interface,
get_if_flags) == -1)
return (-1); /* failure */

Expand Down
2 changes: 1 addition & 1 deletion pcap-int.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ typedef struct pcap_if_list pcap_if_list_t;
typedef int (*get_if_flags_func)(const char *, bpf_u_int32 *, char *);
int pcap_platform_finddevs(pcap_if_list_t *, char *);
#if !defined(_WIN32) && !defined(MSDOS)
int pcap_findalldevs_interfaces(pcap_if_list_t *, char *,
int pcap_findalldevs_interfaces(const char *, pcap_if_list_t *, char *,
int (*)(const char *), get_if_flags_func);
#endif
pcap_if_t *find_or_add_dev(pcap_if_list_t *, const char *, bpf_u_int32,
Expand Down
2 changes: 1 addition & 1 deletion pcap-libdlpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
/*
* Get the list of regular interfaces first.
*/
if (pcap_findalldevs_interfaces(devlistp, errbuf,
if (pcap_findalldevs_interfaces(NULL, devlistp, errbuf,
is_dlpi_interface, get_if_flags) == -1)
return (-1); /* failure */

Expand Down
Loading