23RCSID(
"$Id: 8e951a2aade5c236b163533aa837beeed4c30a17 $")
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 },
396 unsigned long socket_num;
407 net->
net = htonl(strtol(argv[0], NULL, 16));
427 if ((memcmp(p,
"0X", 2) == 0) ||
428 (memcmp(p,
"0x", 2) == 0)) p += 2;
444 if (argc == 3)
return 3;
488 socket_num = strtoul(argv[5], NULL, 16);
489 if (socket_num > 65535) {
551 if (argc == 0)
return 0;
561 while ((argc > 0) && (flags != 0x03)) {
573 if (slen < 0)
return -1;
580 if (flags & 0x02)
goto duplicate;
584 if (slen < 0)
return -1;
625 bool have_netmask =
false;
632 while (*str && (
count < 4) && (netmask == 0)) {
638 case '0':
case '1':
case '2':
case '3':
639 case '4':
case '5':
case '6':
case '7':
642 ip[
count] += (*str) -
'0';
649 if (ip[
count] > 255) {
665 if ((masklen < 0) || (masklen > 32)) {
669 str += strspn(str,
"0123456789");
685 if (ip[
count] > 255) {
708 }
else if ((*ipaddr & 0x80000000) == 0) {
710 }
else if ((*ipaddr & 0xc0000000) == 0x80000000) {
712 }
else if ((*ipaddr & 0xe0000000) == 0xc0000000) {
719 *ipaddr = htonl(*ipaddr);
741 if (strspn(str,
"0123456789") == strlen(str)) {
747 if ((token < 0) || (token > 65535)) {
753 *port = htons(*port);
759#define IP_SRC_ADDR_FLAG (1 << 0)
760#define IP_DEST_ADDR_FLAG (1 << 1)
761#define IP_SRC_PORT_FLAG (1 << 2)
762#define IP_DEST_PORT_FLAG (1 << 3)
763#define IP_PROTO_FLAG (1 << 4)
764#define IP_EST_FLAG (1 << 5)
766#define DONE_FLAGS (IP_SRC_ADDR_FLAG | IP_DEST_ADDR_FLAG | \
767 IP_SRC_PORT_FLAG | IP_DEST_PORT_FLAG | \
768 IP_PROTO_FLAG | IP_EST_FLAG)
810 if (argc == 0)
return 0;
827 fr_strerror_printf(
"Insufficient arguments for '%s' when parsing 'abinary' IP type", argv[0]);
832 if (slen < 0)
return slen;
842 if (argc < 2)
goto insufficient;
845 if (slen < 0)
return slen;
855 if (argc < 3)
goto insufficient;
859 if (slen < 0)
return slen;
869 if (argc < 3)
goto insufficient;
873 if (slen < 0)
return slen;
891 if (strspn(argv[0],
"0123456789") == strlen(argv[0])) {
892 token = atoi(argv[0]);
905 filter->
proto = token;
942 if (argc == 0)
return 0;
961 fr_strerror_printf(
"Insufficient arguments for '%s' when parsing 'abinary' IPv6 type", argv[0]);
965 if (
fr_inet_pton6(&ipaddr, argv[1], strlen(argv[1]),
false,
false,
true) < 0)
return -1;
966 memcpy(&filter->
srcip, ipaddr.
addr.v6.s6_addr, 16);
976 if (argc < 2)
goto insufficient;
978 if (
fr_inet_pton6(&ipaddr, argv[1], strlen(argv[1]),
false,
false,
true) < 0)
return -1;
979 memcpy(&filter->
dstip, ipaddr.
addr.v6.s6_addr, 16);
989 if (argc < 3)
goto insufficient;
993 if (slen < 0)
return slen;
1003 if (argc < 3)
goto insufficient;
1007 if (slen < 0)
return slen;
1025 if (strspn(argv[0],
"0123456789") == strlen(argv[0])) {
1026 token = atoi(argv[0]);
1039 filter->
proto = token;
1087 unsigned long offset;
1096 if (argc == 0)
return 0;
1117 if (strspn(argv[0],
"0123456789") != strlen(argv[0])) {
1123 offset = strtoul(argv[0], NULL, 10);
1124 if (offset > UINT16_MAX)
goto invalid;
1132 if (slen !=
sizeof(filter->
mask)) {
1140 if (value_slen !=
sizeof(filter->
value)) {
1146 filter->
len = htons(filter->
len);
1151 if (argc == 3)
return 0;
1163 fr_strerror_printf(
"Duplicate field '%s' when parsing 'abinary' generic type", argv[0]);
1170 if (flags & 0x01)
goto duplicate;
1176 if (flags & 0x02)
goto duplicate;
1177 filter->
more = htons( 1 );
1236 memset(&filter, 0,
sizeof(filter));
1308 size =
sizeof(filter);
1312 if (slen < 0)
goto fail;
1338 uint64_t aligned[256 /
sizeof(uint64_t)];
1340 static char const *action[] = {
"drop",
"forward"};
1341 static char const *direction[] = {
"out",
"in"};
1346 if (data_len < 4)
return -1;
1354 memcpy(aligned,
data, data_len);
1360 size =
sizeof(filter->ip);
1364 size =
sizeof(filter->ipx);
1368 size =
sizeof(filter->generic);
1372 size =
sizeof(filter->ipv6);
1382 if (data_len < (4 + size))
return -size;
1393 if (filter->ip.srcip) {
1395 ((
uint8_t const *) &filter->ip.srcip)[0],
1396 ((
uint8_t const *) &filter->ip.srcip)[1],
1397 ((
uint8_t const *) &filter->ip.srcip)[2],
1398 ((
uint8_t const *) &filter->ip.srcip)[3],
1399 filter->ip.srcmask);
1402 if (filter->ip.dstip) {
1404 ((
uint8_t const *) &filter->ip.dstip)[0],
1405 ((
uint8_t const *) &filter->ip.dstip)[1],
1406 ((
uint8_t const *) &filter->ip.dstip)[2],
1407 ((
uint8_t const *) &filter->ip.dstip)[3],
1408 filter->ip.dstmask);
1416 ntohs(filter->ip.srcport));
1422 ntohs(filter->ip.dstport));
1425 if (filter->ip.established) {
1435 if (filter->ipx.src.net) {
1437 (
unsigned int)ntohl(filter->ipx.src.net),
1438 filter->ipx.src.node[0], filter->ipx.src.node[1],
1439 filter->ipx.src.node[2], filter->ipx.src.node[3],
1440 filter->ipx.src.node[4], filter->ipx.src.node[5]);
1445 ntohs(filter->ipx.src.socket));
1450 if (filter->ipx.dst.net) {
1452 (
unsigned int)ntohl(filter->ipx.dst.net),
1453 filter->ipx.dst.node[0], filter->ipx.dst.node[1],
1454 filter->ipx.dst.node[2], filter->ipx.dst.node[3],
1455 filter->ipx.dst.node[4], filter->ipx.dst.node[5]);
1460 ntohs(filter->ipx.dst.socket));
1472 len = ntohs(filter->generic.len);
1473 if (
len >
sizeof(filter->generic.mask)) {
1480 for (i = 0; i <
len; i++) {
1487 for (i = 0; i <
len; i++) {
1493 if (filter->generic.more != 0) {
1506 memset(&ipaddr, 0,
sizeof(ipaddr));
1507 ipaddr.
af = AF_INET6;
1508 memcpy(&ipaddr.
addr.v6.s6_addr, filter->ipv6.srcip,
sizeof(filter->ipv6.srcip));
1509 ipaddr.
prefix = filter->ipv6.srcmask;
1519 memset(&ipaddr, 0,
sizeof(ipaddr));
1520 ipaddr.
af = AF_INET6;
1521 memcpy(&ipaddr.
addr.v6.s6_addr, filter->ipv6.dstip,
sizeof(filter->ipv6.dstip));
1522 ipaddr.
prefix = filter->ipv6.dstmask;
1534 ntohs(filter->ipv6.srcport));
1540 ntohs(filter->ipv6.dstport));
1543 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::@160 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