The FreeRADIUS server
$Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
|
Structures and functions for parsing, printing, masking and retrieving IP addresses. More...
#include <freeradius-devel/build.h>
#include <freeradius-devel/missing.h>
#include <freeradius-devel/util/talloc.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <netinet/in.h>
#include <stdbool.h>
Go to the source code of this file.
Data Structures | |
struct | fr_ethernet_t |
Struct to represent an ethernet address. More... | |
struct | fr_ifid_t |
Struct to represent an interface id. More... | |
struct | fr_ipaddr_t |
IPv4/6 prefix. More... | |
union | fr_ipaddr_t.addr |
Macros | |
#define | FR_IPADDR_PREFIX_STRLEN (FR_IPADDR_STRLEN + 1 + 4) |
Like FR_IPADDR_STRLEN but with space for a prefix. More... | |
#define | FR_IPADDR_STRLEN (INET6_ADDRSTRLEN + 1 + IFNAMSIZ) |
Like INET6_ADDRSTRLEN but includes space for the textual Zone ID. More... | |
Functions | |
int | fr_inet_hton (fr_ipaddr_t *out, int af, char const *hostname, bool fallback) |
Wrappers for IPv4/IPv6 host to IP address lookup. More... | |
char * | fr_inet_ifid_ntop (char *out, size_t outlen, uint8_t const *ifid) |
Print an interface-id in standard colon notation. More... | |
uint8_t * | fr_inet_ifid_pton (uint8_t out[static 8], char const *ifid_str) |
Convert interface-id in colon notation to 8 byte binary form. More... | |
char const * | fr_inet_ntoh (fr_ipaddr_t const *src, char *out, size_t outlen) |
Perform reverse resolution of an IP address. More... | |
char * | fr_inet_ntop (char out[static FR_IPADDR_STRLEN], size_t outlen, fr_ipaddr_t const *addr) |
Print the address portion of a fr_ipaddr_t. More... | |
char * | fr_inet_ntop_prefix (char out[static FR_IPADDR_PREFIX_STRLEN], size_t outlen, fr_ipaddr_t const *addr) |
Print a fr_ipaddr_t as a CIDR style network prefix. More... | |
int | fr_inet_pton (fr_ipaddr_t *out, char const *value, ssize_t inlen, int af, bool resolve, bool mask) |
Simple wrapper to decide whether an IP value is v4 or v6 and call the appropriate parser. More... | |
int | fr_inet_pton4 (fr_ipaddr_t *out, char const *value, ssize_t inlen, bool resolve, bool fallback, bool mask) |
Parse an IPv4 address or IPv4 prefix in presentation format (and others) More... | |
int | fr_inet_pton6 (fr_ipaddr_t *out, char const *value, ssize_t inlen, bool resolve, bool fallback, bool mask) |
Parse an IPv6 address or IPv6 prefix in presentation format (and others) More... | |
int | fr_inet_pton_port (fr_ipaddr_t *out, uint16_t *port_out, char const *value, ssize_t inlen, int af, bool resolve, bool mask) |
Parses IPv4/6 address + port, to fr_ipaddr_t and integer (port) More... | |
int | fr_interface_to_ethernet (char const *interface, fr_ethernet_t *ethernet) |
int | fr_interface_to_ipaddr (char const *interface, fr_ipaddr_t *ipaddr, int af, bool link_local) |
int8_t | fr_ipaddr_cmp (fr_ipaddr_t const *a, fr_ipaddr_t const *b) |
Compare two ip addresses. More... | |
int | fr_ipaddr_from_ifname (fr_ipaddr_t *out, int af, char const *name) |
int | fr_ipaddr_from_sockaddr (fr_ipaddr_t *ipaddr, uint16_t *port, struct sockaddr_storage const *sa, socklen_t salen) |
Convert sockaddr to our internal ip address representation. More... | |
void | fr_ipaddr_get_scope_id (fr_ipaddr_t *ipaddr) |
int | fr_ipaddr_is_inaddr_any (fr_ipaddr_t const *ipaddr) |
Determine if an address is the INADDR_ANY address for its address family. More... | |
int | fr_ipaddr_is_multicast (fr_ipaddr_t const *ipaddr) |
Determine if an address is a multicast address. More... | |
int | fr_ipaddr_is_prefix (fr_ipaddr_t const *ipaddr) |
Determine if an address is a prefix. More... | |
void | fr_ipaddr_mask (fr_ipaddr_t *addr, uint8_t prefix) |
Zeroes out the host portion of an fr_ipaddr_t. More... | |
char * | fr_ipaddr_to_interface (TALLOC_CTX *ctx, fr_ipaddr_t *ipaddr) |
int | fr_ipaddr_to_sockaddr (struct sockaddr_storage *sa, socklen_t *salen, fr_ipaddr_t const *ipaddr, uint16_t port) |
Convert our internal ip address representation to a sockaddr. More... | |
Variables | |
bool | fr_hostname_lookups |
hostname -> IP lookups? More... | |
struct in6_addr | fr_inet_link_local6 |
bool | fr_reverse_lookups |
IP -> hostname lookups? More... | |
Structures and functions for parsing, printing, masking and retrieving IP addresses.
Definition in file inet.h.
struct fr_ethernet_t |
struct fr_ifid_t |
struct fr_ipaddr_t |
IPv4/6 prefix.
Abstraction around the standard in_addr/in6_addr structures to support address family agnostic functions.
Definition at line 272 of file merged_model.c.
Data Fields | ||
---|---|---|
union fr_ipaddr_t | addr | |
int | af | Address family. |
uint8_t | prefix | Prefix length - Between 0-32 for IPv4 and 0-128 for IPv6. |
uint32_t | scope_id |
A host may have multiple link-local interfaces the scope ID allows the application to specify which of those interfaces the IP applies to. A special scope_id of zero means that any interface of a given scope can be used. |
union fr_ipaddr_t.addr |
#define FR_IPADDR_PREFIX_STRLEN (FR_IPADDR_STRLEN + 1 + 4) |
#define FR_IPADDR_STRLEN (INET6_ADDRSTRLEN + 1 + IFNAMSIZ) |
int fr_inet_hton | ( | fr_ipaddr_t * | out, |
int | af, | ||
char const * | hostname, | ||
bool | fallback | ||
) |
Wrappers for IPv4/IPv6 host to IP address lookup.
This function returns only one IP address, of the specified address family, or the first address (of whatever family), if AF_UNSPEC is used.
If fallback is specified and af is AF_INET, but not AF_INET records were found and a record for AF_INET6 exists that record will be returned.
If fallback is specified and af is AF_INET6, and a record with AF_INET4 exists that record will be returned inserted.
[out] | out | Where to write result. |
[in] | af | To search for in preference. |
[in] | hostname | to search for. |
[in] | fallback | to the other address family, if no records matching af, found. |
Definition at line 254 of file inet.c.
Print an interface-id in standard colon notation.
[out] | out | Where to write the resulting interface-id string. |
[in] | outlen | of output buffer. |
[in] | ifid | to print. |
Definition at line 1099 of file inet.c.
char const* fr_inet_ntoh | ( | fr_ipaddr_t const * | src, |
char * | out, | ||
size_t | outlen | ||
) |
Perform reverse resolution of an IP address.
Attempt to resolve an IP address to a DNS record (if dns lookups are enabled).
[in] | src | address to resolve. |
[out] | out | Where to write the resulting hostname. |
[in] | outlen | length of the output buffer. |
Definition at line 355 of file inet.c.
char* fr_inet_ntop | ( | char | out[static FR_IPADDR_STRLEN], |
size_t | outlen, | ||
fr_ipaddr_t const * | addr | ||
) |
Print the address portion of a fr_ipaddr_t.
[out] | out | Where to write the resulting IP string. Should be at least FR_IPADDR_STRLEN bytes. |
[in] | outlen | of output buffer. |
[in] | addr | to convert to presentation format. |
Definition at line 1018 of file inet.c.
char* fr_inet_ntop_prefix | ( | char | out[static FR_IPADDR_PREFIX_STRLEN], |
size_t | outlen, | ||
fr_ipaddr_t const * | addr | ||
) |
Print a fr_ipaddr_t as a CIDR style network prefix.
[out] | out | Where to write the resulting prefix string. Should be at least FR_IPADDR_PREFIX_STRLEN bytes. |
[in] | outlen | of output buffer. |
[in] | addr | to convert to presentation format. |
Definition at line 1073 of file inet.c.
int fr_inet_pton | ( | fr_ipaddr_t * | out, |
char const * | value, | ||
ssize_t | inlen, | ||
int | af, | ||
bool | resolve, | ||
bool | mask | ||
) |
Simple wrapper to decide whether an IP value is v4 or v6 and call the appropriate parser.
[out] | out | Where to write the ip address value. |
[in] | value | to parse. |
[in] | inlen | Length of value, if value is \0 terminated inlen may be -1. |
[in] | resolve | If true and value doesn't look like an IP address, try and resolve value as a hostname. |
[in] | af | If the address type is not obvious from the format, and resolve is true, the DNS record (A or AAAA) we require. Also controls which parser we pass the address to if we have no idea what it is.
|
[in] | mask | If true, set address bits to zero. |
Definition at line 778 of file inet.c.
int fr_inet_pton4 | ( | fr_ipaddr_t * | out, |
char const * | value, | ||
ssize_t | inlen, | ||
bool | resolve, | ||
bool | fallback, | ||
bool | mask_bits | ||
) |
Parse an IPv4 address or IPv4 prefix in presentation format (and others)
[out] | out | Where to write the ip address value. |
[in] | value | to parse, may be:
|
[in] | inlen | Length of value, if value is \0 terminated inlen may be -1. |
[in] | resolve | If true and value doesn't look like an IP address, try and resolve value as a hostname. |
[in] | fallback | to IPv6 resolution if no A records can be found. |
[in] | mask_bits | If true, set address bits to zero. |
Definition at line 275 of file merged_model.c.
int fr_inet_pton6 | ( | fr_ipaddr_t * | out, |
char const * | value, | ||
ssize_t | inlen, | ||
bool | resolve, | ||
bool | fallback, | ||
bool | mask | ||
) |
Parse an IPv6 address or IPv6 prefix in presentation format (and others)
[out] | out | Where to write the ip address value. |
[in] | value | to parse, may be:
|
[in] | inlen | Length of value, if value is \0 terminated inlen may be -1. |
[in] | resolve | If true and value doesn't look like an IP address, try and resolve value as a hostname. |
[in] | fallback | to IPv4 resolution if no AAAA records can be found. |
[in] | mask | If true, set address bits to zero. |
Definition at line 629 of file inet.c.
int fr_inet_pton_port | ( | fr_ipaddr_t * | out, |
uint16_t * | port_out, | ||
char const * | value, | ||
ssize_t | inlen, | ||
int | af, | ||
bool | resolve, | ||
bool | mask | ||
) |
Parses IPv4/6 address + port, to fr_ipaddr_t and integer (port)
[out] | out | Where to write the ip address value. |
[out] | port_out | Where to write the port (0 if no port found). |
[in] | value | to parse. |
[in] | inlen | Length of value, if value is \0 terminated inlen may be -1. |
[in] | resolve | If true and value doesn't look like an IP address, try and resolve value as a hostname. |
[in] | af | If the address type is not obvious from the format, and resolve is true, the DNS record (A or AAAA) we require. Also controls which parser we pass the address to if we have no idea what it is.
|
[in] | mask | If true, set address bits to zero. |
Definition at line 937 of file inet.c.
int fr_interface_to_ethernet | ( | char const * | interface, |
fr_ethernet_t * | ethernet | ||
) |
int fr_interface_to_ipaddr | ( | char const * | interface, |
fr_ipaddr_t * | ipaddr, | ||
int | af, | ||
bool | link_local | ||
) |
int8_t fr_ipaddr_cmp | ( | fr_ipaddr_t const * | a, |
fr_ipaddr_t const * | b | ||
) |
int fr_ipaddr_from_ifname | ( | fr_ipaddr_t * | out, |
int | af, | ||
char const * | name | ||
) |
int fr_ipaddr_from_sockaddr | ( | fr_ipaddr_t * | ipaddr, |
uint16_t * | port, | ||
struct sockaddr_storage const * | sa, | ||
socklen_t | salen | ||
) |
Convert sockaddr to our internal ip address representation.
[out] | ipaddr | Where to write the ipaddr. |
[out] | port | Where to write the port. |
[in] | sa | struct to convert. |
[in] | salen | Length of the sockaddr struct. |
Definition at line 1441 of file inet.c.
void fr_ipaddr_get_scope_id | ( | fr_ipaddr_t * | ipaddr | ) |
int fr_ipaddr_is_inaddr_any | ( | fr_ipaddr_t const * | ipaddr | ) |
int fr_ipaddr_is_multicast | ( | fr_ipaddr_t const * | ipaddr | ) |
int fr_ipaddr_is_prefix | ( | fr_ipaddr_t const * | ipaddr | ) |
void fr_ipaddr_mask | ( | fr_ipaddr_t * | addr, |
uint8_t | prefix | ||
) |
Zeroes out the host portion of an fr_ipaddr_t.
[in,out] | addr | to mask |
[in] | prefix | Length of the network portion. |
Definition at line 217 of file inet.c.
char* fr_ipaddr_to_interface | ( | TALLOC_CTX * | ctx, |
fr_ipaddr_t * | ipaddr | ||
) |
int fr_ipaddr_to_sockaddr | ( | struct sockaddr_storage * | sa, |
socklen_t * | salen, | ||
fr_ipaddr_t const * | ipaddr, | ||
uint16_t | port | ||
) |
Convert our internal ip address representation to a sockaddr.
[out] | sa | where to write out the sockaddr, must be large enough to hold sizeof(s6). |
[out] | salen | Length of the sockaddr struct. |
[in] | ipaddr | IP address to convert. |
[in] | port | Port to convert. |
Definition at line 1392 of file inet.c.
|
extern |