23RCSID(
"$Id: 54b36d4a0a4fdcd6f5743a9a0be5ea055caaa640 $")
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;
623 bool have_netmask =
false;
630 while (*str && (
count < 4) && (netmask == 0)) {
636 case '0':
case '1':
case '2':
case '3':
637 case '4':
case '5':
case '6':
case '7':
640 ip[
count] += (*str) -
'0';
647 if (ip[
count] > 255) {
663 if ((masklen < 0) || (masklen > 32)) {
667 str += strspn(str,
"0123456789");
683 if (ip[
count] > 255) {
706 }
else if ((*ipaddr & 0x80000000) == 0) {
708 }
else if ((*ipaddr & 0xc0000000) == 0x80000000) {
710 }
else if ((*ipaddr & 0xe0000000) == 0xc0000000) {
717 *ipaddr = htonl(*ipaddr);
739 if (strspn(str,
"0123456789") == strlen(str)) {
745 if ((token < 0) || (token > 65535)) {
751 *port = htons(*port);
757#define IP_SRC_ADDR_FLAG (1 << 0)
758#define IP_DEST_ADDR_FLAG (1 << 1)
759#define IP_SRC_PORT_FLAG (1 << 2)
760#define IP_DEST_PORT_FLAG (1 << 3)
761#define IP_PROTO_FLAG (1 << 4)
762#define IP_EST_FLAG (1 << 5)
764#define DONE_FLAGS (IP_SRC_ADDR_FLAG | IP_DEST_ADDR_FLAG | \
765 IP_SRC_PORT_FLAG | IP_DEST_PORT_FLAG | \
766 IP_PROTO_FLAG | IP_EST_FLAG)
808 if (argc == 0)
return 0;
825 fr_strerror_printf(
"Insufficient arguments for '%s' when parsing 'abinary' IP type", argv[0]);
830 if (slen < 0)
return slen;
840 if (argc < 2)
goto insufficient;
843 if (slen < 0)
return slen;
853 if (argc < 3)
goto insufficient;
857 if (slen < 0)
return slen;
867 if (argc < 3)
goto insufficient;
871 if (slen < 0)
return slen;
889 if (strspn(argv[0],
"0123456789") == strlen(argv[0])) {
890 token = atoi(argv[0]);
899 filter->
proto = token;
936 if (argc == 0)
return 0;
955 fr_strerror_printf(
"Insufficient arguments for '%s' when parsing 'abinary' IPv6 type", argv[0]);
959 if (
fr_inet_pton6(&ipaddr, argv[1], strlen(argv[1]),
false,
false,
true) < 0)
return -1;
960 memcpy(&filter->
srcip, ipaddr.
addr.v6.s6_addr, 16);
970 if (argc < 2)
goto insufficient;
972 if (
fr_inet_pton6(&ipaddr, argv[1], strlen(argv[1]),
false,
false,
true) < 0)
return -1;
973 memcpy(&filter->
dstip, ipaddr.
addr.v6.s6_addr, 16);
983 if (argc < 3)
goto insufficient;
987 if (slen < 0)
return slen;
997 if (argc < 3)
goto insufficient;
1001 if (slen < 0)
return slen;
1019 if (strspn(argv[0],
"0123456789") == strlen(argv[0])) {
1020 token = atoi(argv[0]);
1029 filter->
proto = token;
1084 if (argc == 0)
return 0;
1105 if (strspn(argv[0],
"0123456789") != strlen(argv[0])) {
1111 slen = atoi(argv[0]);
1112 if (slen > 65535)
goto invalid;
1120 if (slen !=
sizeof(filter->
mask)) {
1128 if (token !=
sizeof(filter->
value)) {
1134 filter->
len = htons(filter->
len);
1139 if (argc == 3)
return 0;
1151 fr_strerror_printf(
"Duplicate field '%s' when parsing 'abinary' generic type", argv[0]);
1158 if (flags & 0x01)
goto duplicate;
1164 if (flags & 0x02)
goto duplicate;
1165 filter->
more = htons( 1 );
1224 memset(&filter, 0,
sizeof(filter));
1296 size =
sizeof(filter);
1300 if (slen < 0)
goto fail;
1326 uint64_t aligned[256 /
sizeof(uint64_t)];
1328 static char const *action[] = {
"drop",
"forward"};
1329 static char const *direction[] = {
"out",
"in"};
1334 if (data_len < 4)
return -1;
1342 memcpy(aligned,
data, data_len);
1348 size =
sizeof(filter->ip);
1352 size =
sizeof(filter->ipx);
1356 size =
sizeof(filter->generic);
1360 size =
sizeof(filter->ipv6);
1367 if (data_len < size)
return -size;
1378 if (filter->ip.srcip) {
1380 ((
uint8_t const *) &filter->ip.srcip)[0],
1381 ((
uint8_t const *) &filter->ip.srcip)[1],
1382 ((
uint8_t const *) &filter->ip.srcip)[2],
1383 ((
uint8_t const *) &filter->ip.srcip)[3],
1384 filter->ip.srcmask);
1387 if (filter->ip.dstip) {
1389 ((
uint8_t const *) &filter->ip.dstip)[0],
1390 ((
uint8_t const *) &filter->ip.dstip)[1],
1391 ((
uint8_t const *) &filter->ip.dstip)[2],
1392 ((
uint8_t const *) &filter->ip.dstip)[3],
1393 filter->ip.dstmask);
1401 ntohs(filter->ip.srcport));
1407 ntohs(filter->ip.dstport));
1410 if (filter->ip.established) {
1420 if (filter->ipx.src.net) {
1422 (
unsigned int)ntohl(filter->ipx.src.net),
1423 filter->ipx.src.node[0], filter->ipx.src.node[1],
1424 filter->ipx.src.node[2], filter->ipx.src.node[3],
1425 filter->ipx.src.node[4], filter->ipx.src.node[5]);
1430 ntohs(filter->ipx.src.socket));
1435 if (filter->ipx.dst.net) {
1437 (
unsigned int)ntohl(filter->ipx.dst.net),
1438 filter->ipx.dst.node[0], filter->ipx.dst.node[1],
1439 filter->ipx.dst.node[2], filter->ipx.dst.node[3],
1440 filter->ipx.dst.node[4], filter->ipx.dst.node[5]);
1445 ntohs(filter->ipx.dst.socket));
1457 len = ntohs(filter->generic.len);
1458 if (len >
sizeof(filter->generic.mask)) {
1465 for (i = 0; i < len; i++) {
1472 for (i = 0; i < len; i++) {
1478 if (filter->generic.more != 0) {
1491 memset(&ipaddr, 0,
sizeof(ipaddr));
1492 ipaddr.
af = AF_INET6;
1493 memcpy(&ipaddr.
addr.v6.s6_addr, filter->ipv6.srcip,
sizeof(filter->ipv6.srcip));
1494 ipaddr.
prefix = filter->ipv6.srcmask;
1504 memset(&ipaddr, 0,
sizeof(ipaddr));
1505 ipaddr.
af = AF_INET6;
1506 memcpy(&ipaddr.
addr.v6.s6_addr, filter->ipv6.dstip,
sizeof(filter->ipv6.dstip));
1507 ipaddr.
prefix = filter->ipv6.dstmask;
1519 ntohs(filter->ipv6.srcport));
1525 ntohs(filter->ipv6.dstport));
1528 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::@137 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 int8_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)