23RCSID(
"$Id: ac5a0e0ed4ad6522eb6cdd8519bd7fff938b30bc $")
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;
486 token = strtoul(argv[5], NULL, 16);
549 if (argc == 0)
return 0;
559 while ((argc > 0) && (flags != 0x03)) {
571 if (slen < 0)
return -1;
578 if (flags & 0x02)
goto duplicate;
582 if (slen < 0)
return -1;
629 while (*str && (
count < 4) && (netmask == 0)) {
635 case '0':
case '1':
case '2':
case '3':
636 case '4':
case '5':
case '6':
case '7':
639 ip[
count] += (*str) -
'0';
646 if (ip[
count] > 255) {
661 if ((masklen < 0) || (masklen > 32)) {
665 str += strspn(str,
"0123456789");
681 if (ip[
count] > 255) {
704 }
else if ((*ipaddr & 0x80000000) == 0) {
706 }
else if ((*ipaddr & 0xc0000000) == 0x80000000) {
708 }
else if ((*ipaddr & 0xe0000000) == 0xc0000000) {
715 *ipaddr = htonl(*ipaddr);
737 if (strspn(str,
"0123456789") == strlen(str)) {
743 if ((token < 0) || (token > 65535)) {
749 *port = htons(*port);
755#define IP_SRC_ADDR_FLAG (1 << 0)
756#define IP_DEST_ADDR_FLAG (1 << 1)
757#define IP_SRC_PORT_FLAG (1 << 2)
758#define IP_DEST_PORT_FLAG (1 << 3)
759#define IP_PROTO_FLAG (1 << 4)
760#define IP_EST_FLAG (1 << 5)
762#define DONE_FLAGS (IP_SRC_ADDR_FLAG | IP_DEST_ADDR_FLAG | \
763 IP_SRC_PORT_FLAG | IP_DEST_PORT_FLAG | \
764 IP_PROTO_FLAG | IP_EST_FLAG)
806 if (argc == 0)
return 0;
823 fr_strerror_printf(
"Insufficient arguments for '%s' when parsing 'abinary' IP type", argv[0]);
828 if (slen < 0)
return slen;
838 if (argc < 2)
goto insufficient;
841 if (slen < 0)
return slen;
851 if (argc < 3)
goto insufficient;
855 if (slen < 0)
return slen;
865 if (argc < 3)
goto insufficient;
869 if (slen < 0)
return slen;
887 if (strspn(argv[0],
"0123456789") == strlen(argv[0])) {
888 token = atoi(argv[0]);
897 filter->
proto = token;
934 if (argc == 0)
return 0;
953 fr_strerror_printf(
"Insufficient arguments for '%s' when parsing 'abinary' IPv6 type", argv[0]);
957 if (
fr_inet_pton6(&ipaddr, argv[1], strlen(argv[1]),
false,
false,
true) < 0)
return -1;
958 memcpy(&filter->
srcip, ipaddr.
addr.v6.s6_addr, 16);
968 if (argc < 2)
goto insufficient;
970 if (
fr_inet_pton6(&ipaddr, argv[1], strlen(argv[1]),
false,
false,
true) < 0)
return -1;
971 memcpy(&filter->
dstip, ipaddr.
addr.v6.s6_addr, 16);
981 if (argc < 3)
goto insufficient;
985 if (slen < 0)
return slen;
995 if (argc < 3)
goto insufficient;
999 if (slen < 0)
return slen;
1017 if (strspn(argv[0],
"0123456789") == strlen(argv[0])) {
1018 token = atoi(argv[0]);
1027 filter->
proto = token;
1082 if (argc == 0)
return 0;
1103 if (strspn(argv[0],
"0123456789") != strlen(argv[0])) {
1109 slen = atoi(argv[0]);
1110 if (slen > 65535)
goto invalid;
1118 if (slen !=
sizeof(filter->
mask)) {
1126 if (token !=
sizeof(filter->
value)) {
1132 filter->
len = htons(filter->
len);
1137 if (argc == 3)
return 0;
1149 fr_strerror_printf(
"Duplicate field '%s' when parsing 'abinary' generic type", argv[0]);
1156 if (flags & 0x01)
goto duplicate;
1162 if (flags & 0x02)
goto duplicate;
1163 filter->
more = htons( 1 );
1222 memset(&filter, 0,
sizeof(filter));
1294 size =
sizeof(filter);
1298 if (slen < 0)
goto fail;
1324 uint64_t aligned[256 /
sizeof(uint64_t)];
1326 static char const *action[] = {
"drop",
"forward"};
1327 static char const *direction[] = {
"out",
"in"};
1332 if (data_len < 4)
return -1;
1340 memcpy(aligned,
data, data_len);
1346 size =
sizeof(filter->ip);
1350 size =
sizeof(filter->ipx);
1354 size =
sizeof(filter->generic);
1358 size =
sizeof(filter->ipv6);
1365 if (data_len < size)
return -size;
1376 if (filter->ip.srcip) {
1378 ((
uint8_t const *) &filter->ip.srcip)[0],
1379 ((
uint8_t const *) &filter->ip.srcip)[1],
1380 ((
uint8_t const *) &filter->ip.srcip)[2],
1381 ((
uint8_t const *) &filter->ip.srcip)[3],
1382 filter->ip.srcmask);
1385 if (filter->ip.dstip) {
1387 ((
uint8_t const *) &filter->ip.dstip)[0],
1388 ((
uint8_t const *) &filter->ip.dstip)[1],
1389 ((
uint8_t const *) &filter->ip.dstip)[2],
1390 ((
uint8_t const *) &filter->ip.dstip)[3],
1391 filter->ip.dstmask);
1399 ntohs(filter->ip.srcport));
1405 ntohs(filter->ip.dstport));
1408 if (filter->ip.established) {
1418 if (filter->ipx.src.net) {
1420 (
unsigned int)ntohl(filter->ipx.src.net),
1421 filter->ipx.src.node[0], filter->ipx.src.node[1],
1422 filter->ipx.src.node[2], filter->ipx.src.node[3],
1423 filter->ipx.src.node[4], filter->ipx.src.node[5]);
1428 ntohs(filter->ipx.src.socket));
1433 if (filter->ipx.dst.net) {
1435 (
unsigned int)ntohl(filter->ipx.dst.net),
1436 filter->ipx.dst.node[0], filter->ipx.dst.node[1],
1437 filter->ipx.dst.node[2], filter->ipx.dst.node[3],
1438 filter->ipx.dst.node[4], filter->ipx.dst.node[5]);
1443 ntohs(filter->ipx.dst.socket));
1455 len = ntohs(filter->generic.len);
1456 if (len >=
sizeof(filter->generic.mask)) {
1463 for (i = 0; i < len; i++) {
1470 for (i = 0; i < len; i++) {
1476 if (filter->generic.more != 0) {
1489 memset(&ipaddr, 0,
sizeof(ipaddr));
1490 ipaddr.
af = AF_INET6;
1491 memcpy(&ipaddr.
addr.v6.s6_addr, filter->ipv6.srcip,
sizeof(filter->ipv6.srcip));
1492 ipaddr.
prefix = filter->ipv6.srcmask;
1502 memset(&ipaddr, 0,
sizeof(ipaddr));
1503 ipaddr.
af = AF_INET6;
1504 memcpy(&ipaddr.
addr.v6.s6_addr, filter->ipv6.dstip,
sizeof(filter->ipv6.dstip));
1505 ipaddr.
prefix = filter->ipv6.dstmask;
1517 ntohs(filter->ipv6.srcport));
1523 ntohs(filter->ipv6.dstport));
1526 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.
#define FR_IPADDR_PREFIX_STRLEN
Like FR_IPADDR_STRLEN but with space for a prefix.
union fr_ipaddr_t::@130 addr
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 int8_t comp(void const *a, void const *b)
#define FR_SBUFF_IN(_start, _len_or_end)
#define FR_SBUFF_IN_SPRINTF_RETURN(...)
#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)