23RCSID(
"$Id: af917f9af43017603ec37a247e257760c77fef42 $")
25#include <freeradius-devel/util/base16.h>
26#include <freeradius-devel/util/misc.h>
27#include <freeradius-devel/util/pair.h>
47#define RAD_MAX_FILTER_LEN 6
53#define IPX_NODE_ADDR_LEN 6
279 {
L(
"ftp-data"), 20 },
281 {
L(
"hostname"), 101 },
282 {
L(
"kerberos"), 88 },
284 {
L(
"nameserver"), 42 },
405 net->
net = htonl(strtol(argv[0], NULL, 16));
425 if ((memcmp(p,
"0X", 2) == 0) ||
426 (memcmp(p,
"0x", 2) == 0)) p += 2;
442 if (argc == 3)
return 3;
487 unsigned long ipx_socket = strtoul(argv[5], NULL, 16);
489 if (ipx_socket > UINT16_MAX) {
552 if (argc == 0)
return 0;
562 while ((argc > 0) && (flags != 0x03)) {
574 if (slen < 0)
return -1;
581 if (flags & 0x02)
goto duplicate;
585 if (slen < 0)
return -1;
626 bool have_netmask =
false;
633 while (*str && (
count < 4) && (netmask == 0)) {
639 case '0':
case '1':
case '2':
case '3':
640 case '4':
case '5':
case '6':
case '7':
643 ip[
count] += (*str) -
'0';
650 if (ip[
count] > 255) {
666 if ((masklen < 0) || (masklen > 32)) {
670 str += strspn(str,
"0123456789");
686 if (ip[
count] > 255) {
709 }
else if ((*ipaddr & 0x80000000) == 0) {
711 }
else if ((*ipaddr & 0xc0000000) == 0x80000000) {
713 }
else if ((*ipaddr & 0xe0000000) == 0xc0000000) {
720 *ipaddr = htonl(*ipaddr);
742 if (strspn(str,
"0123456789") == strlen(str)) {
748 if ((token < 0) || (token > 65535)) {
754 *port = htons(*port);
760#define IP_SRC_ADDR_FLAG (1 << 0)
761#define IP_DEST_ADDR_FLAG (1 << 1)
762#define IP_SRC_PORT_FLAG (1 << 2)
763#define IP_DEST_PORT_FLAG (1 << 3)
764#define IP_PROTO_FLAG (1 << 4)
765#define IP_EST_FLAG (1 << 5)
767#define DONE_FLAGS (IP_SRC_ADDR_FLAG | IP_DEST_ADDR_FLAG | \
768 IP_SRC_PORT_FLAG | IP_DEST_PORT_FLAG | \
769 IP_PROTO_FLAG | IP_EST_FLAG)
811 if (argc == 0)
return 0;
828 fr_strerror_printf(
"Insufficient arguments for '%s' when parsing 'abinary' IP type", argv[0]);
833 if (slen < 0)
return slen;
843 if (argc < 2)
goto insufficient;
846 if (slen < 0)
return slen;
856 if (argc < 3)
goto insufficient;
860 if (slen < 0)
return slen;
870 if (argc < 3)
goto insufficient;
874 if (slen < 0)
return slen;
892 if (strspn(argv[0],
"0123456789") == strlen(argv[0])) {
893 token = atoi(argv[0]);
906 filter->
proto = token;
943 if (argc == 0)
return 0;
962 fr_strerror_printf(
"Insufficient arguments for '%s' when parsing 'abinary' IPv6 type", argv[0]);
966 if (
fr_inet_pton6(&ipaddr, argv[1], strlen(argv[1]),
false,
false,
true) < 0)
return -1;
967 memcpy(&filter->
srcip, ipaddr.
addr.v6.s6_addr, 16);
977 if (argc < 2)
goto insufficient;
979 if (
fr_inet_pton6(&ipaddr, argv[1], strlen(argv[1]),
false,
false,
true) < 0)
return -1;
980 memcpy(&filter->
dstip, ipaddr.
addr.v6.s6_addr, 16);
990 if (argc < 3)
goto insufficient;
994 if (slen < 0)
return slen;
1004 if (argc < 3)
goto insufficient;
1008 if (slen < 0)
return slen;
1026 if (strspn(argv[0],
"0123456789") == strlen(argv[0])) {
1027 token = atoi(argv[0]);
1040 filter->
proto = token;
1095 if (argc == 0)
return 0;
1116 if (strspn(argv[0],
"0123456789") != strlen(argv[0])) {
1123 unsigned long offset = strtoul(argv[0], NULL, 10);
1125 if (offset > UINT16_MAX)
goto invalid;
1134 if (slen !=
sizeof(filter->
mask)) {
1142 if (token !=
sizeof(filter->
value)) {
1148 filter->
len = htons(filter->
len);
1153 if (argc == 3)
return 0;
1165 fr_strerror_printf(
"Duplicate field '%s' when parsing 'abinary' generic type", argv[0]);
1172 if (flags & 0x01)
goto duplicate;
1178 if (flags & 0x02)
goto duplicate;
1179 filter->
more = htons( 1 );
1238 memset(&filter, 0,
sizeof(filter));
1310 size =
sizeof(filter);
1314 if (slen < 0)
goto fail;
1340 uint64_t aligned[256 /
sizeof(uint64_t)];
1342 static char const *action[] = {
"drop",
"forward"};
1343 static char const *direction[] = {
"out",
"in"};
1348 if (data_len < 4)
return -1;
1356 memcpy(aligned,
data, data_len);
1362 size =
sizeof(filter->ip);
1366 size =
sizeof(filter->ipx);
1370 size =
sizeof(filter->generic);
1374 size =
sizeof(filter->ipv6);
1384 if (data_len < (4 + size))
return -size;
1395 if (filter->ip.srcip) {
1397 ((
uint8_t const *) &filter->ip.srcip)[0],
1398 ((
uint8_t const *) &filter->ip.srcip)[1],
1399 ((
uint8_t const *) &filter->ip.srcip)[2],
1400 ((
uint8_t const *) &filter->ip.srcip)[3],
1401 filter->ip.srcmask);
1404 if (filter->ip.dstip) {
1406 ((
uint8_t const *) &filter->ip.dstip)[0],
1407 ((
uint8_t const *) &filter->ip.dstip)[1],
1408 ((
uint8_t const *) &filter->ip.dstip)[2],
1409 ((
uint8_t const *) &filter->ip.dstip)[3],
1410 filter->ip.dstmask);
1418 ntohs(filter->ip.srcport));
1424 ntohs(filter->ip.dstport));
1427 if (filter->ip.established) {
1437 if (filter->ipx.src.net) {
1439 (
unsigned int)ntohl(filter->ipx.src.net),
1440 filter->ipx.src.node[0], filter->ipx.src.node[1],
1441 filter->ipx.src.node[2], filter->ipx.src.node[3],
1442 filter->ipx.src.node[4], filter->ipx.src.node[5]);
1447 ntohs(filter->ipx.src.socket));
1452 if (filter->ipx.dst.net) {
1454 (
unsigned int)ntohl(filter->ipx.dst.net),
1455 filter->ipx.dst.node[0], filter->ipx.dst.node[1],
1456 filter->ipx.dst.node[2], filter->ipx.dst.node[3],
1457 filter->ipx.dst.node[4], filter->ipx.dst.node[5]);
1462 ntohs(filter->ipx.dst.socket));
1474 len = ntohs(filter->generic.len);
1475 if (
len >
sizeof(filter->generic.mask)) {
1482 for (i = 0; i <
len; i++) {
1489 for (i = 0; i <
len; i++) {
1495 if (filter->generic.more != 0) {
1508 memset(&ipaddr, 0,
sizeof(ipaddr));
1509 ipaddr.
af = AF_INET6;
1510 memcpy(&ipaddr.
addr.v6.s6_addr, filter->ipv6.srcip,
sizeof(filter->ipv6.srcip));
1511 ipaddr.
prefix = filter->ipv6.srcmask;
1521 memset(&ipaddr, 0,
sizeof(ipaddr));
1522 ipaddr.
af = AF_INET6;
1523 memcpy(&ipaddr.
addr.v6.s6_addr, filter->ipv6.dstip,
sizeof(filter->ipv6.dstip));
1524 ipaddr.
prefix = filter->ipv6.dstmask;
1536 ntohs(filter->ipv6.srcport));
1542 ntohs(filter->ipv6.dstport));
1545 if (filter->ipv6.established) {
#define IP_DEST_ADDR_FLAG
uint8_t value[RAD_MAX_FILTER_LEN]
static fr_table_num_sorted_t const filterType[]
ssize_t fr_radius_decode_abinary(fr_pair_t *vp, uint8_t const *data, size_t data_len)
Print an Ascend binary filter attribute to a string,.
static size_t filterPortType_len
static int ascend_parse_ipx(int argc, char **argv, ascend_ipx_filter_t *filter)
static int ascend_parse_ip(int argc, char **argv, ascend_ip_filter_t *filter)
static size_t filterType_len
static int ascend_parse_ipx_net(int argc, char **argv, ascend_ipx_net_t *net, uint8_t *comp)
static size_t filterCompare_len
uint8_t node[IPX_NODE_ADDR_LEN]
static int ascend_parse_generic(int argc, char **argv, ascend_generic_filter_t *filter)
#define IPX_NODE_ADDR_LEN
uint8_t mask[RAD_MAX_FILTER_LEN]
static fr_table_num_sorted_t const filterPortType[]
static fr_table_num_sorted_t const filterCompare[]
static int ascend_parse_ipv6(int argc, char **argv, ascend_ipv6_filter_t *filter)
static int ascend_parse_port(uint16_t *port, char *compare, char *str)
static size_t filterKeywords_len
#define IP_DEST_PORT_FLAG
static size_t filterProtoName_len
ssize_t fr_radius_encode_abinary(fr_pair_t const *vp, fr_dbuff_t *dbuff)
Encode a string to abinary.
static fr_table_num_sorted_t const filterProtoName[]
static int ascend_parse_ipaddr(uint32_t *ipaddr, char *str)
#define RAD_MAX_FILTER_LEN
static fr_table_num_sorted_t const filterKeywords[]
static int const char char buffer[256]
#define fr_base16_decode(_err, _out, _in, _no_trailing)
#define L(_str)
Helper for initialising arrays of string literals.
#define fr_dbuff_in_memcpy(_dbuff_or_marker, _in, _inlen)
Copy exactly _inlen bytes into a dbuff or marker.
#define FR_DBUFF_TMP(_start, _len_or_end)
Creates a compound literal to pass into functions which accept a dbuff.
int fr_dict_str_to_argv(char *str, char **argv, int max_argc)
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.
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)
uint8_t prefix
Prefix length - Between 0-32 for IPv4 and 0-128 for IPv6.
union fr_ipaddr_t::@159 addr
#define FR_IPADDR_PREFIX_STRLEN
Like FR_IPADDR_STRLEN but with space for a prefix.
int fr_pair_value_strdup(fr_pair_t *vp, char const *src, bool tainted)
Copy data into an "string" data type.
#define RADIUS_MAX_STRING_LENGTH
static fr_cmp_ret_t comp(void const *a, void const *b)
#define FR_SBUFF_IN_SPRINTF_RETURN(...)
#define FR_SBUFF_IN_STR(_start)
#define FR_SBUFF_OUT(_start, _len_or_end)
#define FR_SBUFF_IN_STRCPY_RETURN(...)
fr_aka_sim_id_type_t type
Stores an attribute, a value and various bits of other data.
#define fr_table_value_by_str(_table, _name, _def)
Convert a string to a value using a sorted or ordered table.
#define fr_table_str_by_value(_table, _number, _def)
Convert an integer to a string.
An element in a lexicographically sorted array of name to num mappings.
char * talloc_bstrndup(TALLOC_CTX *ctx, char const *in, size_t inlen)
Binary safe strndup function.
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.
#define fr_strerror_const(_msg)
static fr_sbuff_err_t char size_t * len