return ll_name_to_index(dev);
}
-void *parse_hostcond(char *addr)
+void *parse_hostcond(char *addr, bool is_port)
{
char *port = NULL;
struct aafilter a = { .port = -1 };
} else {
port = strrchr(strchr(addr, '/') ? : addr, ':');
}
+
+ if (is_port)
+ port = addr;
+
if (port && *port) {
- if (*port != ':')
- return NULL;
- *port++ = 0;
+ if (*port == ':')
+ *port++ = 0;
+
if (*port && *port != '*') {
if (get_integer(&a.port, port, 0)) {
struct servent *se1 = NULL;
}
}
}
- if (addr && *addr && *addr != '*') {
+ if (!is_port && addr && *addr && *addr != '*') {
if (get_prefix_1(&a.addr, addr, fam)) {
if (get_dns_host(&a, addr, fam)) {
fprintf(stderr, "Error: an inet prefix is expected rather than \"%s\".\n", addr);
#define SSF_S_LE 8
#define SSF_S_AUTO 9
+#include <stdbool.h>
+
struct ssfilter
{
int type;
};
int ssfilter_parse(struct ssfilter **f, int argc, char **argv, FILE *fp);
-void *parse_hostcond(char*);
+void *parse_hostcond(char *addr, bool is_port);
static int yy_argc;
static FILE *yy_fp;
static ssfilter_t *yy_ret;
+static int tok_type = -1;
static int yylex(void);
return '(';
if (strcmp(curtok, ")") == 0)
return ')';
- if (strcmp(curtok, "dst") == 0)
+ if (strcmp(curtok, "dst") == 0) {
+ tok_type = DCOND;
return DCOND;
- if (strcmp(curtok, "src") == 0)
+ }
+ if (strcmp(curtok, "src") == 0) {
+ tok_type = SCOND;
return SCOND;
- if (strcmp(curtok, "dport") == 0)
+ }
+ if (strcmp(curtok, "dport") == 0) {
+ tok_type = DPORT;
return DPORT;
- if (strcmp(curtok, "sport") == 0)
+ }
+ if (strcmp(curtok, "sport") == 0) {
+ tok_type = SPORT;
return SPORT;
+ }
if (strcmp(curtok, ">=") == 0 ||
strcmp(curtok, "ge") == 0 ||
strcmp(curtok, "geq") == 0)
if (strcmp(curtok, "<") == 0 ||
strcmp(curtok, "lt") == 0)
return '<';
- if (strcmp(curtok, "autobound") == 0)
+ if (strcmp(curtok, "autobound") == 0) {
+ tok_type = AUTOBOUND;
return AUTOBOUND;
- yylval = (void*)parse_hostcond(curtok);
+ }
+ yylval = (void*)parse_hostcond(curtok, tok_type == SPORT || tok_type == DPORT);
if (yylval == NULL) {
fprintf(stderr, "Cannot parse dst/src address.\n");
exit(1);