Skip to content

Commit e06168a

Browse files
committed
define the function that appends a queue to a rule
checks: first checks if the queue obeys best practices(having a default queue etc) checks if the referenced queue is defined in the queues then sets the queue to queue nvpair in the rules nvlist.
1 parent 1dad8e5 commit e06168a

File tree

7 files changed

+44
-2
lines changed

7 files changed

+44
-2
lines changed

distrib/sets/lists/comp/mi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2762,6 +2762,7 @@
27622762
./usr/include/net/net_stats.h comp-c-include
27632763
./usr/include/net/netisr.h comp-obsolete obsolete
27642764
./usr/include/net/npf.h comp-c-include
2765+
./usr/include/net/npf_altq.h comp-c-include
27652766
./usr/include/net/npf_ncode.h comp-obsolete obsolete
27662767
./usr/include/net/pfil.h comp-c-include
27672768
./usr/include/net/pfkeyv2.h comp-c-include

lib/libnpf/npf.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,13 @@ npf_rule_setproc(nl_rule_t *rl, const char *name)
735735
return nvlist_error(rl->rule_dict);
736736
}
737737

738+
int
739+
npf_rule_setqueue(nl_rule_t *rl, const char *qname)
740+
{
741+
nvlist_add_string(rl->rule_dict, "queue", qname);
742+
return nvlist_error(rl->rule_dict);
743+
}
744+
738745
void *
739746
npf_rule_export(nl_rule_t *rl, size_t *length)
740747
{

lib/libnpf/npf.expsym

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ npf_rule_setinfo
7575
npf_rule_setkey
7676
npf_rule_setprio
7777
npf_rule_setproc
78+
npf_rule_setqueue
7879
npf_ruleset_add
7980
npf_ruleset_flush
8081
npf_ruleset_remkey

lib/libnpf/npf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ int npf_rule_setprio(nl_rule_t *, int);
108108
int npf_rule_setproc(nl_rule_t *, const char *);
109109
int npf_rule_setkey(nl_rule_t *, const void *, size_t);
110110
int npf_rule_setinfo(nl_rule_t *, const void *, size_t);
111+
int npf_rule_setqueue(nl_rule_t *, const char *);
111112
const char * npf_rule_getname(nl_rule_t *);
112113
uint32_t npf_rule_getattr(nl_rule_t *);
113114
const char * npf_rule_getinterface(nl_rule_t *);

usr.sbin/npf/npfctl/npf_build.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ npfctl_build_group_end(void)
702702
void
703703
npfctl_build_rule(uint32_t attr, const char *ifname, sa_family_t family,
704704
const npfvar_t *popts, const filt_opts_t *fopts,
705-
const char *pcap_filter, const char *rproc)
705+
const char *pcap_filter, const char *rproc, struct node_qassign queue)
706706
{
707707
nl_rule_t *rl;
708708

@@ -719,6 +719,17 @@ npfctl_build_rule(uint32_t attr, const char *ifname, sa_family_t family,
719719
npf_rule_setproc(rl, rproc);
720720
}
721721

722+
/* first ensure a queue is set on rule */
723+
if (queue.qname != NULL ) {
724+
/* ensure altq config obeys best practices */
725+
if (check_commit_altq())
726+
errx(EXIT_FAILURE, "error in altq config");
727+
/* ensure the referenced queue is defined */
728+
if (npf_rule_qnames_exists(queue.qname))
729+
if (npf_rule_setqueue(rl, queue.qname))
730+
errx(EXIT_FAILURE, "rule queue %s cannot be set", queue.qname);
731+
}
732+
722733
if (npf_conf) {
723734
nl_rule_t *cg = current_group[rule_nesting_level];
724735

usr.sbin/npf/npfctl/npfctl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ void npfctl_build_group(const char *, int, const char *, bool);
294294
void npfctl_build_group_end(void);
295295
void npfctl_build_rule(uint32_t, const char *, sa_family_t,
296296
const npfvar_t *, const filt_opts_t *,
297-
const char *, const char *);
297+
const char *, const char *, struct node_qassign);
298298
void npfctl_build_natseg(int, int, unsigned, const char *,
299299
const addr_port_t *, const addr_port_t *,
300300
const npfvar_t *, const filt_opts_t *, unsigned);
@@ -327,6 +327,7 @@ uint32_t qname_to_qid(const char *);
327327
struct npf_altq *npfaltq_lookup(const char *ifname);
328328
char *rate2str(double);
329329
int check_commit_altq(void);
330+
int npf_rule_qnames_exists(const char *);
330331

331332
/*
332333
* For the systems which do not define TH_ECE and TW_CRW.

usr.sbin/npf/npfctl/npfctl_altq.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,3 +1289,23 @@ check_commit_hfsc(struct npf_altq *pa)
12891289
}
12901290
return error;
12911291
}
1292+
1293+
/* this checks for undefined queues appended on a rule */
1294+
int
1295+
npf_rule_qnames_exists(const char *qname)
1296+
{
1297+
int found = 0;
1298+
struct npf_altq* a;
1299+
TAILQ_FOREACH(a, &altqs, entries) {
1300+
if (a->qname[0] != 0){
1301+
if (strcmp(a->qname, qname) == 0){
1302+
found = 1;
1303+
break;
1304+
}
1305+
}
1306+
}
1307+
if (!found)
1308+
yyerror("no qname named '%s' defined\n", qname);
1309+
1310+
return found;
1311+
}

0 commit comments

Comments
 (0)