|
OpenVAS Scanner 23.32.3
|
#include "bpf_share.h"#include "network.h"#include "pcap_openvas.h"#include "support.h"#include <arpa/inet.h>#include <errno.h>#include <gvm/base/logging.h>#include <gvm/base/networking.h>#include <ifaddrs.h>#include <net/if.h>#include <netdb.h>#include <netinet/in.h>#include <pcap.h>#include <pcap/pcap.h>#include <resolv.h>#include <stdlib.h>#include <string.h>#include <sys/ioctl.h>#include <sys/param.h>#include <sys/types.h>#include <unistd.h>

Go to the source code of this file.
Data Structures | |
| struct | interface_info |
| struct | myroute |
Macros | |
| #define | MAXROUTES 1024 |
| #define | G_LOG_DOMAIN "lib misc" |
| GLib logging domain. | |
| #define | MAX_IFACE_NAME_LEN 64 |
| Maximum length of an interface's name. | |
| #define | DEBUG_IPV4(x) |
Functions | |
| struct interface_info * | getinterfaces (int *howmany) |
| struct interface_info * | v6_getinterfaces (int *howmany) |
| int | getipv6routes (struct myroute *myroutes, int *numroutes) |
| Get the IPv6 routes and number of routes. | |
| static int | ipv6_prefix_to_mask (unsigned prefix, struct in6_addr *mask) |
| Generate an ipv6 mask from the given ipv6 prefix. | |
| int | v6_is_local_ip (struct in6_addr *addr) |
| static int | v6_ipaddr2devname (char *dev, int sz, struct in6_addr *addr) |
| static int | ipaddr2devname (char *dev, int sz, struct in_addr *addr) |
| int | v6_islocalhost (struct in6_addr *addr) |
| Tests whether a packet sent to IP is LIKELY to route through the kernel localhost interface. | |
| int | islocalhost (struct in_addr *addr) |
| Tests whether a packet sent to IP is LIKELY to route through the kernel localhost interface. | |
| int | get_datalink_size (int datalink) |
| int | v6_getsourceip (struct in6_addr *src, struct in6_addr *dst) |
| static int | getipv4routes (struct myroute *myroutes, int *numroutes) |
| Get the ipv4 routes and number of routes. | |
| char * | v6_routethrough (struct in6_addr *dest, struct in6_addr *source) |
| An awesome function to determine what interface a packet to a given destination should be routed through. | |
| char * | routethrough (struct in_addr *dest, struct in_addr *source) |
| An awesome function to determine what interface a packet to a given destination should be routed through. | |
| char * | get_iface_from_ip (const char *local_ip) |
| Given an IP address, determines which interface belongs to. | |
| int | get_iface_index (struct in6_addr *ipaddr, int *ifindex) |
| Get the interface index depending on the target's IP. | |
| #define DEBUG_IPV4 | ( | x | ) |
Definition at line 44 of file pcap.c.
Referenced by v6_is_local_ip().
| #define MAX_IFACE_NAME_LEN 64 |
Maximum length of an interface's name.
Definition at line 41 of file pcap.c.
Referenced by getinterfaces(), getipv4routes(), and routethrough().
| #define MAXROUTES 1024 |
Definition at line 30 of file pcap.c.
Referenced by getipv4routes(), getipv6routes(), routethrough(), v6_is_local_ip(), and v6_routethrough().
| int get_datalink_size | ( | int | datalink | ) |
Definition at line 298 of file pcap.c.
Referenced by capture_next_frame(), capture_next_packet(), capture_next_v6_packet(), nasl_pcap_next(), nasl_send_capture(), and scan().

| char * get_iface_from_ip | ( | const char * | local_ip | ) |
Given an IP address, determines which interface belongs to.
| local_ip | IP address. |
Definition at line 1280 of file pcap.c.
Referenced by get_iface_index(), and get_local_mac_address_from_ip().

| int get_iface_index | ( | struct in6_addr * | ipaddr, |
| int * | ifindex ) |
Get the interface index depending on the target's IP.
| [in] | ipaddr | The ip address of the target. |
| [out] | ifindex | the index of the selected iface |
Definition at line 1334 of file pcap.c.
References get_iface_from_ip(), and v6_getsourceip().
Referenced by send_frame().


| struct interface_info * getinterfaces | ( | int * | howmany | ) |
| [out] | howmany | Return location for the number of interfaces found (might be NULL). |
Definition at line 413 of file pcap.c.
References len, MAX_IFACE_NAME_LEN, interface_info::name, and name.
Referenced by ipaddr2devname(), and routethrough().

|
static |
Get the ipv4 routes and number of routes.
This function is only used for getting the ipv4 routes in v6_routethrough(). routethrough() overwrites the global myroutes struct with a local version and uses its own logic for getting the routes from /proc/net/route.
| [out] | myroutes | Array of routes. |
| [out] | numroutes | Number of routes in myroutes. |
Definition at line 591 of file pcap.c.
References myroute::dest6, myroute::dev, myroute::mask, MAX_IFACE_NAME_LEN, MAXROUTES, myroute::metric, name, and v6_getinterfaces().
Referenced by v6_routethrough().


| int getipv6routes | ( | struct myroute * | myroutes, |
| int * | numroutes ) |
Get the IPv6 routes and number of routes.
This function parses the /proc/net/ipv6_route file into an array of myroute structs.
| [out] | myroutes | Array of routes. |
| [out] | numroutes | Number of routes in myroutes. |
Definition at line 729 of file pcap.c.
References myroute::dev, len, myroute::mask, MAXROUTES, myroute::metric, name, and v6_getinterfaces().
Referenced by v6_is_local_ip(), and v6_routethrough().


|
static |
Definition at line 207 of file pcap.c.
References interface_info::addr, getinterfaces(), and name.
Referenced by islocalhost().


|
static |
Generate an ipv6 mask from the given ipv6 prefix.
This function is a copy of the function ipv6_prefix_to_mask() obtained from GPL-2.0 licensed https://gitlab.com/ipcalc/ipcalc/-/blob/master/ipcalc.c.
| [in] | prefix | The ipv6 prefix. |
| [out] | mask | The mask corresponding to the prefix. |
Definition at line 89 of file pcap.c.
References prefix().
Referenced by Ensure(), openvas_routethrough(), v6_is_local_ip(), and v6_routethrough().


| int islocalhost | ( | struct in_addr * | addr | ) |
Tests whether a packet sent to IP is LIKELY to route through the kernel localhost interface.
Definition at line 271 of file pcap.c.
References interface_info::addr, and ipaddr2devname().
Referenced by Ensure(), init_capture_device(), nasl_send_packet(), nasl_tcp_ping(), openvas_routethrough(), plugin_run_synscan(), and routethrough().


| char * routethrough | ( | struct in_addr * | dest, |
| struct in_addr * | source ) |
An awesome function to determine what interface a packet to a given destination should be routed through.
It returns NULL if no appropriate interface is found, otherwise it returns the device name and fills in the source parameter. Some of the stuff is from Stevens' Unix Network Programming V2. He had an easier suggestion for doing this (in the book), but it isn't portable :(
Definition at line 1070 of file pcap.c.
References myroute::dest, myroute::dev, getinterfaces(), islocalhost(), myroute::mask, MAX_IFACE_NAME_LEN, MAXROUTES, myroute::metric, interface_info::name, and name.
Referenced by Ensure(), Ensure(), Ensure(), Ensure(), Ensure(), init_capture_device(), nasl_pcap_next(), nasl_send_arp_request(), nasl_send_capture(), nasl_tcp_ping(), and openbpf().


| struct interface_info * v6_getinterfaces | ( | int * | howmany | ) |
Definition at line 338 of file pcap.c.
References interface_info::addr6, interface_info::mask, name, s6addr, and saddr.
Referenced by getipv4routes(), getipv6routes(), v6_ipaddr2devname(), v6_is_local_ip(), and v6_routethrough().

| int v6_getsourceip | ( | struct in6_addr * | src, |
| struct in6_addr * | dst ) |
Definition at line 487 of file pcap.c.
References name.
Referenced by get_iface_index(), nasl_this_host(), and v6_routethrough().

|
static |
Definition at line 176 of file pcap.c.
References interface_info::addr, interface_info::addr6, name, and v6_getinterfaces().
Referenced by v6_islocalhost().


| int v6_is_local_ip | ( | struct in6_addr * | addr | ) |
Definition at line 115 of file pcap.c.
References interface_info::addr6, DEBUG_IPV4, getipv6routes(), ipv6_prefix_to_mask(), interface_info::mask, MAXROUTES, name, and v6_getinterfaces().
Referenced by nasl_islocalnet().


| int v6_islocalhost | ( | struct in6_addr * | addr | ) |
Tests whether a packet sent to IP is LIKELY to route through the kernel localhost interface.
Definition at line 234 of file pcap.c.
References interface_info::addr, and v6_ipaddr2devname().
Referenced by Ensure(), init_v6_capture_device(), nasl_islocalhost(), nasl_send_v6packet(), nasl_tcp_v6_ping(), nasl_this_host(), openvas_routethrough(), and v6_routethrough().


| char * v6_routethrough | ( | struct in6_addr * | dest, |
| struct in6_addr * | source ) |
An awesome function to determine what interface a packet to a given destination should be routed through.
It returns NULL if no appropriate interface is found, otherwise it returns the device name and fills in the source parameter. Some of the stuff is from Stevens' Unix Network Programming V2. He had an easier suggestion for doing this (in the book), but it isn't portable :(
Definition at line 851 of file pcap.c.
References myroute::dev, getipv4routes(), getipv6routes(), ipv6_prefix_to_mask(), MAXROUTES, interface_info::name, v6_getinterfaces(), v6_getsourceip(), and v6_islocalhost().
Referenced by get_mtu(), init_v6_capture_device(), nasl_pcap_next(), nasl_send_capture(), nasl_tcp_v6_ping(), and v6_openbpf().

