Changeset View
Changeset View
Standalone View
Standalone View
sys/netpfil/pf/pf_ioctl.c
| Show First 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | |||||
| static int pf_commit_eth(uint32_t, const char *); | static int pf_commit_eth(uint32_t, const char *); | ||||
| static void pf_free_eth_rule(struct pf_keth_rule *); | static void pf_free_eth_rule(struct pf_keth_rule *); | ||||
| #ifdef ALTQ | #ifdef ALTQ | ||||
| static int pf_begin_altq(u_int32_t *); | static int pf_begin_altq(u_int32_t *); | ||||
| static int pf_rollback_altq(u_int32_t); | static int pf_rollback_altq(u_int32_t); | ||||
| static int pf_commit_altq(u_int32_t); | static int pf_commit_altq(u_int32_t); | ||||
| static int pf_enable_altq(struct pf_altq *); | static int pf_enable_altq(struct pf_altq *); | ||||
| static int pf_disable_altq(struct pf_altq *); | static int pf_disable_altq(struct pf_altq *); | ||||
| static uint16_t pf_qname2qid(const char *); | |||||
| static void pf_qid_unref(uint16_t); | static void pf_qid_unref(uint16_t); | ||||
| #endif /* ALTQ */ | #endif /* ALTQ */ | ||||
| static int pf_begin_rules(u_int32_t *, int, const char *); | static int pf_begin_rules(u_int32_t *, int, const char *); | ||||
| static int pf_rollback_rules(u_int32_t, int, char *); | static int pf_rollback_rules(u_int32_t, int, char *); | ||||
| static int pf_setup_pfsync_matching(struct pf_kruleset *); | static int pf_setup_pfsync_matching(struct pf_kruleset *); | ||||
| static void pf_hash_rule_rolling(MD5_CTX *, struct pf_krule *); | static void pf_hash_rule_rolling(MD5_CTX *, struct pf_krule *); | ||||
| static void pf_hash_rule(struct pf_krule *); | static void pf_hash_rule(struct pf_krule *); | ||||
| static void pf_hash_rule_addr(MD5_CTX *, struct pf_rule_addr *); | static void pf_hash_rule_addr(MD5_CTX *, struct pf_rule_addr *); | ||||
| ▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | SYSCTL_BOOL(_net_pf, OID_AUTO, default_to_drop, CTLFLAG_RDTUN | CTLFLAG_VNET, | ||||
| &VNET_NAME(default_to_drop), false, | &VNET_NAME(default_to_drop), false, | ||||
| "Make the default rule drop all packets."); | "Make the default rule drop all packets."); | ||||
| static void pf_init_tagset(struct pf_tagset *, unsigned int *, | static void pf_init_tagset(struct pf_tagset *, unsigned int *, | ||||
| unsigned int); | unsigned int); | ||||
| static void pf_cleanup_tagset(struct pf_tagset *); | static void pf_cleanup_tagset(struct pf_tagset *); | ||||
| static uint16_t tagname2hashindex(const struct pf_tagset *, const char *); | static uint16_t tagname2hashindex(const struct pf_tagset *, const char *); | ||||
| static uint16_t tag2hashindex(const struct pf_tagset *, uint16_t); | static uint16_t tag2hashindex(const struct pf_tagset *, uint16_t); | ||||
| static u_int16_t tagname2tag(struct pf_tagset *, const char *); | static u_int16_t tagname2tag(struct pf_tagset *, const char *, bool); | ||||
| static u_int16_t pf_tagname2tag(const char *); | |||||
| static void tag_unref(struct pf_tagset *, u_int16_t); | static void tag_unref(struct pf_tagset *, u_int16_t); | ||||
| struct cdev *pf_dev; | struct cdev *pf_dev; | ||||
| /* | /* | ||||
| * XXX - These are new and need to be checked when moveing to a new version | * XXX - These are new and need to be checked when moveing to a new version | ||||
| */ | */ | ||||
| static void pf_clear_all_states(void); | static void pf_clear_all_states(void); | ||||
| ▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | |||||
| */ | */ | ||||
| VNET_DEFINE(int, pf_vnet_active); | VNET_DEFINE(int, pf_vnet_active); | ||||
| #define V_pf_vnet_active VNET(pf_vnet_active) | #define V_pf_vnet_active VNET(pf_vnet_active) | ||||
| int pf_end_threads; | int pf_end_threads; | ||||
| struct proc *pf_purge_proc; | struct proc *pf_purge_proc; | ||||
| VNET_DEFINE(struct rmlock, pf_rules_lock); | VNET_DEFINE(struct rmlock, pf_rules_lock); | ||||
| VNET_DEFINE(struct rmlock, pf_tags_lock); | |||||
| VNET_DEFINE_STATIC(struct sx, pf_ioctl_lock); | VNET_DEFINE_STATIC(struct sx, pf_ioctl_lock); | ||||
| #define V_pf_ioctl_lock VNET(pf_ioctl_lock) | #define V_pf_ioctl_lock VNET(pf_ioctl_lock) | ||||
| struct sx pf_end_lock; | struct sx pf_end_lock; | ||||
| /* pfsync */ | /* pfsync */ | ||||
| VNET_DEFINE(pfsync_state_import_t *, pfsync_state_import_ptr); | VNET_DEFINE(pfsync_state_import_t *, pfsync_state_import_ptr); | ||||
| VNET_DEFINE(pfsync_insert_state_t *, pfsync_insert_state_ptr); | VNET_DEFINE(pfsync_insert_state_t *, pfsync_insert_state_ptr); | ||||
| VNET_DEFINE(pfsync_update_state_t *, pfsync_update_state_ptr); | VNET_DEFINE(pfsync_update_state_t *, pfsync_update_state_ptr); | ||||
| ▲ Show 20 Lines • Show All 383 Lines • ▼ Show 20 Lines | |||||
| static uint16_t | static uint16_t | ||||
| tag2hashindex(const struct pf_tagset *ts, uint16_t tag) | tag2hashindex(const struct pf_tagset *ts, uint16_t tag) | ||||
| { | { | ||||
| return (tag & ts->mask); | return (tag & ts->mask); | ||||
| } | } | ||||
| static u_int16_t | static u_int16_t | ||||
| tagname2tag(struct pf_tagset *ts, const char *tagname) | tagname2tag(struct pf_tagset *ts, const char *tagname, bool add_new) | ||||
| { | { | ||||
| struct pf_tagname *tag; | struct pf_tagname *tag; | ||||
| u_int32_t index; | u_int32_t index; | ||||
| u_int16_t new_tagid; | u_int16_t new_tagid; | ||||
| PF_RULES_WASSERT(); | PF_TAGS_RLOCK_TRACKER; | ||||
| PF_TAGS_RLOCK(); | |||||
| index = tagname2hashindex(ts, tagname); | index = tagname2hashindex(ts, tagname); | ||||
| TAILQ_FOREACH(tag, &ts->namehash[index], namehash_entries) | TAILQ_FOREACH(tag, &ts->namehash[index], namehash_entries) | ||||
| if (strcmp(tagname, tag->name) == 0) { | if (strcmp(tagname, tag->name) == 0) { | ||||
| tag->ref++; | tag->ref++; | ||||
| return (tag->tag); | new_tagid = tag->tag; | ||||
| PF_TAGS_RUNLOCK(); | |||||
| return (new_tagid); | |||||
| } | } | ||||
| /* | /* | ||||
| * When used for pfsync with queues we must not create new entries. | |||||
| * Pf tags can be created just fine by this function, but queues | |||||
| * require additional configuration. If they are missing on the target | |||||
| * system we just ignore them | |||||
| */ | |||||
| if (add_new == false) { | |||||
| printf("%s: Not creating a new tag\n", __func__); | |||||
| PF_TAGS_RUNLOCK(); | |||||
| return (0); | |||||
| } | |||||
| /* | |||||
| * If a new entry must be created do it under a write lock. | |||||
| * But first search again, somebody could have created the tag | |||||
| * between unlocking the read lock and locking the write lock. | |||||
| */ | |||||
| PF_TAGS_RUNLOCK(); | |||||
| PF_TAGS_WLOCK(); | |||||
| TAILQ_FOREACH(tag, &ts->namehash[index], namehash_entries) | |||||
| if (strcmp(tagname, tag->name) == 0) { | |||||
| tag->ref++; | |||||
| new_tagid = tag->tag; | |||||
| PF_TAGS_WUNLOCK(); | |||||
| return (new_tagid); | |||||
| } | |||||
| /* | |||||
| * new entry | * new entry | ||||
| * | * | ||||
| * to avoid fragmentation, we do a linear search from the beginning | * to avoid fragmentation, we do a linear search from the beginning | ||||
| * and take the first free slot we find. | * and take the first free slot we find. | ||||
| */ | */ | ||||
| new_tagid = BIT_FFS(TAGID_MAX, &ts->avail); | new_tagid = BIT_FFS(TAGID_MAX, &ts->avail); | ||||
| /* | /* | ||||
| * Tags are 1-based, with valid tags in the range [1..TAGID_MAX]. | * Tags are 1-based, with valid tags in the range [1..TAGID_MAX]. | ||||
| * BIT_FFS() returns a 1-based bit number, with 0 indicating no bits | * BIT_FFS() returns a 1-based bit number, with 0 indicating no bits | ||||
| * set. It may also return a bit number greater than TAGID_MAX due | * set. It may also return a bit number greater than TAGID_MAX due | ||||
| * to rounding of the number of bits in the vector up to a multiple | * to rounding of the number of bits in the vector up to a multiple | ||||
| * of the vector word size at declaration/allocation time. | * of the vector word size at declaration/allocation time. | ||||
| */ | */ | ||||
| if ((new_tagid == 0) || (new_tagid > TAGID_MAX)) | if ((new_tagid == 0) || (new_tagid > TAGID_MAX)) { | ||||
| PF_TAGS_WUNLOCK(); | |||||
| return (0); | return (0); | ||||
| } | |||||
| /* Mark the tag as in use. Bits are 0-based for BIT_CLR() */ | /* Mark the tag as in use. Bits are 0-based for BIT_CLR() */ | ||||
| BIT_CLR(TAGID_MAX, new_tagid - 1, &ts->avail); | BIT_CLR(TAGID_MAX, new_tagid - 1, &ts->avail); | ||||
| /* allocate and fill new struct pf_tagname */ | /* allocate and fill new struct pf_tagname */ | ||||
| tag = uma_zalloc(V_pf_tag_z, M_NOWAIT); | tag = uma_zalloc(V_pf_tag_z, M_NOWAIT); | ||||
| if (tag == NULL) | if (tag == NULL) { | ||||
| PF_TAGS_WUNLOCK(); | |||||
| return (0); | return (0); | ||||
| } | |||||
| strlcpy(tag->name, tagname, sizeof(tag->name)); | strlcpy(tag->name, tagname, sizeof(tag->name)); | ||||
| tag->tag = new_tagid; | tag->tag = new_tagid; | ||||
| tag->ref = 1; | tag->ref = 1; | ||||
| /* Insert into namehash */ | /* Insert into namehash */ | ||||
| TAILQ_INSERT_TAIL(&ts->namehash[index], tag, namehash_entries); | TAILQ_INSERT_TAIL(&ts->namehash[index], tag, namehash_entries); | ||||
| /* Insert into taghash */ | /* Insert into taghash */ | ||||
| index = tag2hashindex(ts, new_tagid); | index = tag2hashindex(ts, new_tagid); | ||||
| TAILQ_INSERT_TAIL(&ts->taghash[index], tag, taghash_entries); | TAILQ_INSERT_TAIL(&ts->taghash[index], tag, taghash_entries); | ||||
| return (tag->tag); | PF_TAGS_WUNLOCK(); | ||||
| return (new_tagid); | |||||
| } | } | ||||
| static char * | |||||
| tag2tagname(struct pf_tagset *ts, u_int16_t tag) | |||||
| { | |||||
| struct pf_tagname *t; | |||||
| uint16_t index; | |||||
| PF_TAGS_RLOCK_TRACKER; | |||||
| PF_TAGS_RLOCK(); | |||||
| index = tag2hashindex(ts, tag); | |||||
| TAILQ_FOREACH(t, &ts->taghash[index], taghash_entries) | |||||
| if (tag == t->tag) { | |||||
| PF_TAGS_RUNLOCK(); | |||||
| return (t->name); | |||||
| } | |||||
| PF_TAGS_RUNLOCK(); | |||||
| return (NULL); | |||||
kp: return (NULL) | |||||
| } | |||||
| static void | static void | ||||
| tag_unref(struct pf_tagset *ts, u_int16_t tag) | tag_unref(struct pf_tagset *ts, u_int16_t tag) | ||||
| { | { | ||||
| struct pf_tagname *t; | struct pf_tagname *t; | ||||
| uint16_t index; | uint16_t index; | ||||
| PF_RULES_WASSERT(); | PF_TAGS_WLOCK(); | ||||
| index = tag2hashindex(ts, tag); | index = tag2hashindex(ts, tag); | ||||
| TAILQ_FOREACH(t, &ts->taghash[index], taghash_entries) | TAILQ_FOREACH(t, &ts->taghash[index], taghash_entries) | ||||
| if (tag == t->tag) { | if (tag == t->tag) { | ||||
| if (--t->ref == 0) { | if (--t->ref == 0) { | ||||
| TAILQ_REMOVE(&ts->taghash[index], t, | TAILQ_REMOVE(&ts->taghash[index], t, | ||||
| taghash_entries); | taghash_entries); | ||||
| index = tagname2hashindex(ts, t->name); | index = tagname2hashindex(ts, t->name); | ||||
| TAILQ_REMOVE(&ts->namehash[index], t, | TAILQ_REMOVE(&ts->namehash[index], t, | ||||
| namehash_entries); | namehash_entries); | ||||
| /* Bits are 0-based for BIT_SET() */ | /* Bits are 0-based for BIT_SET() */ | ||||
| BIT_SET(TAGID_MAX, tag - 1, &ts->avail); | BIT_SET(TAGID_MAX, tag - 1, &ts->avail); | ||||
| uma_zfree(V_pf_tag_z, t); | uma_zfree(V_pf_tag_z, t); | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| PF_TAGS_WUNLOCK(); | |||||
| } | } | ||||
| static uint16_t | uint16_t | ||||
| pf_tagname2tag(const char *tagname) | pf_tagname2tag(const char *tagname) | ||||
| { | { | ||||
| return (tagname2tag(&V_pf_tags, tagname)); | return (tagname2tag(&V_pf_tags, tagname, true)); | ||||
| } | } | ||||
| static const char * | |||||
| pf_tag2tagname(uint16_t tag) | |||||
| { | |||||
| return (tag2tagname(&V_pf_tags, tag)); | |||||
| } | |||||
| static int | static int | ||||
| pf_begin_eth(uint32_t *ticket, const char *anchor) | pf_begin_eth(uint32_t *ticket, const char *anchor) | ||||
| { | { | ||||
| struct pf_keth_rule *rule, *tmp; | struct pf_keth_rule *rule, *tmp; | ||||
| struct pf_keth_ruleset *rs; | struct pf_keth_ruleset *rs; | ||||
| PF_RULES_WASSERT(); | PF_RULES_WASSERT(); | ||||
| ▲ Show 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | pf_commit_eth(uint32_t ticket, const char *anchor) | ||||
| rs->inactive.rules = rules; | rs->inactive.rules = rules; | ||||
| rs->inactive.ticket = rs->active.ticket; | rs->inactive.ticket = rs->active.ticket; | ||||
| return (pf_rollback_eth(rs->inactive.ticket, | return (pf_rollback_eth(rs->inactive.ticket, | ||||
| rs->anchor ? rs->anchor->path : "")); | rs->anchor ? rs->anchor->path : "")); | ||||
| } | } | ||||
| #ifdef ALTQ | #ifdef ALTQ | ||||
| static uint16_t | uint16_t | ||||
| pf_qname2qid(const char *qname) | pf_qname2qid(const char *qname, bool add_new) | ||||
| { | { | ||||
| return (tagname2tag(&V_pf_qids, qname)); | return (tagname2tag(&V_pf_qids, qname, add_new)); | ||||
| } | |||||
| static const char * | |||||
| pf_qid2qname(uint16_t qid) | |||||
| { | |||||
| return (tag2tagname(&V_pf_qids, qid)); | |||||
| } | } | ||||
| static void | static void | ||||
| pf_qid_unref(uint16_t qid) | pf_qid_unref(uint16_t qid) | ||||
| { | { | ||||
| tag_unref(&V_pf_qids, qid); | tag_unref(&V_pf_qids, qid); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 232 Lines • ▼ Show 20 Lines | pf_altq_ifnet_event(struct ifnet *ifp, int remove) | ||||
| TAILQ_FOREACH(a1, V_pf_altqs_active, entries) { | TAILQ_FOREACH(a1, V_pf_altqs_active, entries) { | ||||
| a2 = malloc(sizeof(*a2), M_PFALTQ, M_NOWAIT); | a2 = malloc(sizeof(*a2), M_PFALTQ, M_NOWAIT); | ||||
| if (a2 == NULL) { | if (a2 == NULL) { | ||||
| error = ENOMEM; | error = ENOMEM; | ||||
| break; | break; | ||||
| } | } | ||||
| bcopy(a1, a2, sizeof(struct pf_altq)); | bcopy(a1, a2, sizeof(struct pf_altq)); | ||||
| if ((a2->qid = pf_qname2qid(a2->qname)) == 0) { | if ((a2->qid = pf_qname2qid(a2->qname, true)) == 0) { | ||||
| error = EBUSY; | error = EBUSY; | ||||
| free(a2, M_PFALTQ); | free(a2, M_PFALTQ); | ||||
| break; | break; | ||||
| } | } | ||||
| a2->altq_disc = NULL; | a2->altq_disc = NULL; | ||||
| TAILQ_FOREACH(a3, V_pf_altq_ifs_inactive, entries) { | TAILQ_FOREACH(a3, V_pf_altq_ifs_inactive, entries) { | ||||
| if (strncmp(a3->ifname, a2->ifname, | if (strncmp(a3->ifname, a2->ifname, | ||||
| IFNAMSIZ) == 0) { | IFNAMSIZ) == 0) { | ||||
| ▲ Show 20 Lines • Show All 438 Lines • ▼ Show 20 Lines | case 0: { | ||||
| ASSIGN(qlimit); | ASSIGN(qlimit); | ||||
| ASSIGN(flags); | ASSIGN(flags); | ||||
| if (q->scheduler == ALTQT_HFSC) { | if (q->scheduler == ALTQT_HFSC) { | ||||
| #define ASSIGN_OPT(x) exported_q->pq_u.hfsc_opts.x = q->pq_u.hfsc_opts.x | #define ASSIGN_OPT(x) exported_q->pq_u.hfsc_opts.x = q->pq_u.hfsc_opts.x | ||||
| #define ASSIGN_OPT_SATU32(x) exported_q->pq_u.hfsc_opts.x = \ | #define ASSIGN_OPT_SATU32(x) exported_q->pq_u.hfsc_opts.x = \ | ||||
| SATU32(q->pq_u.hfsc_opts.x) | SATU32(q->pq_u.hfsc_opts.x) | ||||
| ASSIGN_OPT_SATU32(rtsc_m1); | ASSIGN_OPT_SATU32(rtsc_m1); | ||||
| ASSIGN_OPT(rtsc_d); | ASSIGN_OPT(rtsc_d); | ||||
| ASSIGN_OPT_SATU32(rtsc_m2); | ASSIGN_OPT_SATU32(rtsc_m2); | ||||
| ASSIGN_OPT_SATU32(lssc_m1); | ASSIGN_OPT_SATU32(lssc_m1); | ||||
| ASSIGN_OPT(lssc_d); | ASSIGN_OPT(lssc_d); | ||||
| ASSIGN_OPT_SATU32(lssc_m2); | ASSIGN_OPT_SATU32(lssc_m2); | ||||
| ASSIGN_OPT_SATU32(ulsc_m1); | ASSIGN_OPT_SATU32(ulsc_m1); | ||||
| ASSIGN_OPT(ulsc_d); | ASSIGN_OPT(ulsc_d); | ||||
| ASSIGN_OPT_SATU32(ulsc_m2); | ASSIGN_OPT_SATU32(ulsc_m2); | ||||
| ASSIGN_OPT(flags); | ASSIGN_OPT(flags); | ||||
| #undef ASSIGN_OPT | #undef ASSIGN_OPT | ||||
| #undef ASSIGN_OPT_SATU32 | #undef ASSIGN_OPT_SATU32 | ||||
| } else | } else | ||||
| COPY(pq_u); | COPY(pq_u); | ||||
| ASSIGN(qid); | ASSIGN(qid); | ||||
| break; | break; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | #define ASSIGN_OPT(x) q->pq_u.hfsc_opts.x = imported_q->pq_u.hfsc_opts.x | ||||
| ASSIGN_OPT(lssc_d); | ASSIGN_OPT(lssc_d); | ||||
| ASSIGN_OPT(lssc_m2); | ASSIGN_OPT(lssc_m2); | ||||
| ASSIGN_OPT(ulsc_m1); | ASSIGN_OPT(ulsc_m1); | ||||
| ASSIGN_OPT(ulsc_d); | ASSIGN_OPT(ulsc_d); | ||||
| ASSIGN_OPT(ulsc_m2); | ASSIGN_OPT(ulsc_m2); | ||||
| ASSIGN_OPT(flags); | ASSIGN_OPT(flags); | ||||
| #undef ASSIGN_OPT | #undef ASSIGN_OPT | ||||
| } else | } else | ||||
| COPY(pq_u); | COPY(pq_u); | ||||
| ASSIGN(qid); | ASSIGN(qid); | ||||
| break; | break; | ||||
| } | } | ||||
| case 1: { | case 1: { | ||||
| Show All 15 Lines | case 1: { | ||||
| ASSIGN(qlimit); | ASSIGN(qlimit); | ||||
| ASSIGN(flags); | ASSIGN(flags); | ||||
| COPY(pq_u); | COPY(pq_u); | ||||
| ASSIGN(qid); | ASSIGN(qid); | ||||
| break; | break; | ||||
| } | } | ||||
| default: | default: | ||||
| panic("%s: unhandled struct pfioc_altq version", __func__); | panic("%s: unhandled struct pfioc_altq version", __func__); | ||||
| break; | break; | ||||
| } | } | ||||
| #undef ASSIGN | #undef ASSIGN | ||||
| #undef COPY | #undef COPY | ||||
| return (0); | return (0); | ||||
| ▲ Show 20 Lines • Show All 414 Lines • ▼ Show 20 Lines | #endif | ||||
| } else | } else | ||||
| rule->rcv_kif = NULL; | rule->rcv_kif = NULL; | ||||
| if (rule->rtableid > 0 && rule->rtableid >= rt_numfibs) | if (rule->rtableid > 0 && rule->rtableid >= rt_numfibs) | ||||
| ERROUT(EBUSY); | ERROUT(EBUSY); | ||||
| #ifdef ALTQ | #ifdef ALTQ | ||||
| /* set queue IDs */ | /* set queue IDs */ | ||||
| if (rule->qname[0] != 0) { | if (rule->qname[0] != 0) { | ||||
| if ((rule->qid = pf_qname2qid(rule->qname)) == 0) | if ((rule->qid = pf_qname2qid(rule->qname, true)) == 0) | ||||
| ERROUT(EBUSY); | ERROUT(EBUSY); | ||||
| else if (rule->pqname[0] != 0) { | else if (rule->pqname[0] != 0) { | ||||
| if ((rule->pqid = | if ((rule->pqid = | ||||
| pf_qname2qid(rule->pqname)) == 0) | pf_qname2qid(rule->pqname, true)) == 0) | ||||
| ERROUT(EBUSY); | ERROUT(EBUSY); | ||||
| } else | } else | ||||
| rule->pqid = rule->qid; | rule->pqid = rule->qid; | ||||
| } | } | ||||
| #endif | #endif | ||||
| if (rule->tagname[0]) | if (rule->tagname[0]) | ||||
| if ((rule->tag = pf_tagname2tag(rule->tagname)) == 0) | if ((rule->tag = pf_tagname2tag(rule->tagname)) == 0) | ||||
| ERROUT(EBUSY); | ERROUT(EBUSY); | ||||
| ▲ Show 20 Lines • Show All 1,100 Lines • ▼ Show 20 Lines | if (rule->bridge_to_name[0]) { | ||||
| rule->bridge_to_name); | rule->bridge_to_name); | ||||
| pfi_kkif_ref(rule->bridge_to); | pfi_kkif_ref(rule->bridge_to); | ||||
| } else | } else | ||||
| rule->bridge_to = NULL; | rule->bridge_to = NULL; | ||||
| #ifdef ALTQ | #ifdef ALTQ | ||||
| /* set queue IDs */ | /* set queue IDs */ | ||||
| if (rule->qname[0] != 0) { | if (rule->qname[0] != 0) { | ||||
| if ((rule->qid = pf_qname2qid(rule->qname)) == 0) | if ((rule->qid = pf_qname2qid(rule->qname, true)) == 0) | ||||
| error = EBUSY; | error = EBUSY; | ||||
| else | else | ||||
| rule->qid = rule->qid; | rule->qid = rule->qid; | ||||
| } | } | ||||
| #endif | #endif | ||||
| if (rule->tagname[0]) | if (rule->tagname[0]) | ||||
| if ((rule->tag = pf_tagname2tag(rule->tagname)) == 0) | if ((rule->tag = pf_tagname2tag(rule->tagname)) == 0) | ||||
| error = EBUSY; | error = EBUSY; | ||||
| ▲ Show 20 Lines • Show All 534 Lines • ▼ Show 20 Lines | if (pcr->action != PF_CHANGE_REMOVE) { | ||||
| if (newrule->rtableid > 0 && | if (newrule->rtableid > 0 && | ||||
| newrule->rtableid >= rt_numfibs) | newrule->rtableid >= rt_numfibs) | ||||
| error = EBUSY; | error = EBUSY; | ||||
| #ifdef ALTQ | #ifdef ALTQ | ||||
| /* set queue IDs */ | /* set queue IDs */ | ||||
| if (newrule->qname[0] != 0) { | if (newrule->qname[0] != 0) { | ||||
| if ((newrule->qid = | if ((newrule->qid = | ||||
| pf_qname2qid(newrule->qname)) == 0) | pf_qname2qid(newrule->qname, true)) == 0) | ||||
| error = EBUSY; | error = EBUSY; | ||||
| else if (newrule->pqname[0] != 0) { | else if (newrule->pqname[0] != 0) { | ||||
| if ((newrule->pqid = | if ((newrule->pqid = | ||||
| pf_qname2qid(newrule->pqname)) == 0) | pf_qname2qid(newrule->pqname, true)) == 0) | ||||
| error = EBUSY; | error = EBUSY; | ||||
| } else | } else | ||||
| newrule->pqid = newrule->qid; | newrule->pqid = newrule->qid; | ||||
| } | } | ||||
| #endif /* ALTQ */ | #endif /* ALTQ */ | ||||
| if (newrule->tagname[0]) | if (newrule->tagname[0]) | ||||
| if ((newrule->tag = | if ((newrule->tag = | ||||
| pf_tagname2tag(newrule->tagname)) == 0) | pf_tagname2tag(newrule->tagname)) == 0) | ||||
| ▲ Show 20 Lines • Show All 514 Lines • ▼ Show 20 Lines | if (pa->ticket != V_ticket_altqs_inactive) { | ||||
| goto fail; | goto fail; | ||||
| } | } | ||||
| /* | /* | ||||
| * if this is for a queue, find the discipline and | * if this is for a queue, find the discipline and | ||||
| * copy the necessary fields | * copy the necessary fields | ||||
| */ | */ | ||||
| if (altq->qname[0] != 0) { | if (altq->qname[0] != 0) { | ||||
| if ((altq->qid = pf_qname2qid(altq->qname)) == 0) { | if ((altq->qid = pf_qname2qid(altq->qname, true)) == 0) { | ||||
| PF_RULES_WUNLOCK(); | PF_RULES_WUNLOCK(); | ||||
| error = EBUSY; | error = EBUSY; | ||||
| free(altq, M_PFALTQ); | free(altq, M_PFALTQ); | ||||
| goto fail; | goto fail; | ||||
| } | } | ||||
| altq->altq_disc = NULL; | altq->altq_disc = NULL; | ||||
| TAILQ_FOREACH(a, V_pf_altq_ifs_inactive, entries) { | TAILQ_FOREACH(a, V_pf_altq_ifs_inactive, entries) { | ||||
| if (strncmp(a->ifname, altq->ifname, | if (strncmp(a->ifname, altq->ifname, | ||||
| ▲ Show 20 Lines • Show All 1,306 Lines • ▼ Show 20 Lines | |||||
| #undef ERROUT_IOCTL | #undef ERROUT_IOCTL | ||||
| return (error); | return (error); | ||||
| } | } | ||||
| void | void | ||||
| pfsync_state_export(union pfsync_state_union *sp, struct pf_kstate *st, int msg_version) | pfsync_state_export(union pfsync_state_union *sp, struct pf_kstate *st, int msg_version) | ||||
| { | { | ||||
| const char *tagname; | |||||
| bzero(sp, sizeof(union pfsync_state_union)); | bzero(sp, sizeof(union pfsync_state_union)); | ||||
| /* copy from state key */ | /* copy from state key */ | ||||
| sp->pfs_1301.key[PF_SK_WIRE].addr[0] = st->key[PF_SK_WIRE]->addr[0]; | sp->pfs_1301.key[PF_SK_WIRE].addr[0] = st->key[PF_SK_WIRE]->addr[0]; | ||||
| sp->pfs_1301.key[PF_SK_WIRE].addr[1] = st->key[PF_SK_WIRE]->addr[1]; | sp->pfs_1301.key[PF_SK_WIRE].addr[1] = st->key[PF_SK_WIRE]->addr[1]; | ||||
| sp->pfs_1301.key[PF_SK_WIRE].port[0] = st->key[PF_SK_WIRE]->port[0]; | sp->pfs_1301.key[PF_SK_WIRE].port[0] = st->key[PF_SK_WIRE]->port[0]; | ||||
| sp->pfs_1301.key[PF_SK_WIRE].port[1] = st->key[PF_SK_WIRE]->port[1]; | sp->pfs_1301.key[PF_SK_WIRE].port[1] = st->key[PF_SK_WIRE]->port[1]; | ||||
| sp->pfs_1301.key[PF_SK_STACK].addr[0] = st->key[PF_SK_STACK]->addr[0]; | sp->pfs_1301.key[PF_SK_STACK].addr[0] = st->key[PF_SK_STACK]->addr[0]; | ||||
| sp->pfs_1301.key[PF_SK_STACK].addr[1] = st->key[PF_SK_STACK]->addr[1]; | sp->pfs_1301.key[PF_SK_STACK].addr[1] = st->key[PF_SK_STACK]->addr[1]; | ||||
| sp->pfs_1301.key[PF_SK_STACK].port[0] = st->key[PF_SK_STACK]->port[0]; | sp->pfs_1301.key[PF_SK_STACK].port[0] = st->key[PF_SK_STACK]->port[0]; | ||||
| sp->pfs_1301.key[PF_SK_STACK].port[1] = st->key[PF_SK_STACK]->port[1]; | sp->pfs_1301.key[PF_SK_STACK].port[1] = st->key[PF_SK_STACK]->port[1]; | ||||
| sp->pfs_1301.proto = st->key[PF_SK_WIRE]->proto; | |||||
| sp->pfs_1301.af = st->key[PF_SK_WIRE]->af; | |||||
| /* copy from state */ | /* copy from state */ | ||||
| strlcpy(sp->pfs_1301.ifname, st->kif->pfik_name, sizeof(sp->pfs_1301.ifname)); | strlcpy(sp->pfs_1301.ifname, st->kif->pfik_name, sizeof(sp->pfs_1301.ifname)); | ||||
| bcopy(&st->act.rt_addr, &sp->pfs_1301.rt_addr, sizeof(sp->pfs_1301.rt_addr)); | bcopy(&st->act.rt_addr, &sp->pfs_1301.rt_addr, sizeof(sp->pfs_1301.rt_addr)); | ||||
| sp->pfs_1301.creation = htonl(time_uptime - (st->creation / 1000)); | sp->pfs_1301.creation = htonl(time_uptime - (st->creation / 1000)); | ||||
| sp->pfs_1301.expire = pf_state_expires(st); | sp->pfs_1301.expire = pf_state_expires(st); | ||||
| if (sp->pfs_1301.expire <= time_uptime) | if (sp->pfs_1301.expire <= time_uptime) | ||||
| sp->pfs_1301.expire = htonl(0); | sp->pfs_1301.expire = htonl(0); | ||||
| else | else | ||||
| sp->pfs_1301.expire = htonl(sp->pfs_1301.expire - time_uptime); | sp->pfs_1301.expire = htonl(sp->pfs_1301.expire - time_uptime); | ||||
| sp->pfs_1301.direction = st->direction; | |||||
| sp->pfs_1301.log = st->act.log; | |||||
| sp->pfs_1301.timeout = st->timeout; | |||||
| switch (msg_version) { | switch (msg_version) { | ||||
| case PFSYNC_MSG_VERSION_1301: | case PFSYNC_MSG_VERSION_1301: | ||||
| sp->pfs_1301.state_flags = st->state_flags; | sp->pfs_1301.state_flags = st->state_flags; | ||||
| sp->pfs_1301.direction = st->direction; | |||||
| sp->pfs_1301.log = st->act.log; | |||||
| sp->pfs_1301.timeout = st->timeout; | |||||
| sp->pfs_1301.proto = st->key[PF_SK_WIRE]->proto; | |||||
| sp->pfs_1301.af = st->key[PF_SK_WIRE]->af; | |||||
| /* | |||||
| * XXX Why do we bother pfsyncing source node information if source | |||||
| * nodes are not synced? Showing users that there is source tracking | |||||
| * when there is none seems useless. | |||||
| */ | |||||
| if (st->sns[PF_SN_LIMIT] != NULL) | |||||
| sp->pfs_1301.sync_flags |= PFSYNC_FLAG_SRCNODE; | |||||
| if (st->sns[PF_SN_NAT] != NULL || st->sns[PF_SN_ROUTE]) | |||||
| sp->pfs_1301.sync_flags |= PFSYNC_FLAG_NATSRCNODE; | |||||
| break; | break; | ||||
| case PFSYNC_MSG_VERSION_1400: | case PFSYNC_MSG_VERSION_1400: | ||||
| sp->pfs_1400.state_flags = htons(st->state_flags); | sp->pfs_1400.state_flags = htons(st->state_flags); | ||||
| sp->pfs_1400.direction = st->direction; | |||||
| sp->pfs_1400.log = st->act.log; | |||||
| sp->pfs_1400.timeout = st->timeout; | |||||
| sp->pfs_1400.proto = st->key[PF_SK_WIRE]->proto; | |||||
| sp->pfs_1400.af = st->key[PF_SK_WIRE]->af; | |||||
| sp->pfs_1400.qid = htons(st->act.qid); | sp->pfs_1400.qid = htons(st->act.qid); | ||||
| sp->pfs_1400.pqid = htons(st->act.pqid); | sp->pfs_1400.pqid = htons(st->act.pqid); | ||||
| sp->pfs_1400.dnpipe = htons(st->act.dnpipe); | sp->pfs_1400.dnpipe = htons(st->act.dnpipe); | ||||
| sp->pfs_1400.dnrpipe = htons(st->act.dnrpipe); | sp->pfs_1400.dnrpipe = htons(st->act.dnrpipe); | ||||
| sp->pfs_1400.rtableid = htonl(st->act.rtableid); | sp->pfs_1400.rtableid = htonl(st->act.rtableid); | ||||
| sp->pfs_1400.min_ttl = st->act.min_ttl; | sp->pfs_1400.min_ttl = st->act.min_ttl; | ||||
| sp->pfs_1400.set_tos = st->act.set_tos; | sp->pfs_1400.set_tos = st->act.set_tos; | ||||
| sp->pfs_1400.max_mss = htons(st->act.max_mss); | sp->pfs_1400.max_mss = htons(st->act.max_mss); | ||||
| sp->pfs_1400.set_prio[0] = st->act.set_prio[0]; | sp->pfs_1400.set_prio[0] = st->act.set_prio[0]; | ||||
| sp->pfs_1400.set_prio[1] = st->act.set_prio[1]; | sp->pfs_1400.set_prio[1] = st->act.set_prio[1]; | ||||
| sp->pfs_1400.rt = st->act.rt; | sp->pfs_1400.rt = st->act.rt; | ||||
| if (st->act.rt_kif) | if (st->act.rt_kif) | ||||
| strlcpy(sp->pfs_1400.rt_ifname, | strlcpy(sp->pfs_1400.rt_ifname, | ||||
| st->act.rt_kif->pfik_name, | st->act.rt_kif->pfik_name, | ||||
| sizeof(sp->pfs_1400.rt_ifname)); | sizeof(sp->pfs_1400.rt_ifname)); | ||||
| break; | |||||
| default: | |||||
| panic("%s: Unsupported pfsync_msg_version %d", | |||||
| __func__, msg_version); | |||||
| } | |||||
| /* | /* | ||||
| * XXX Why do we bother pfsyncing source node information if source | * XXX Why do we bother pfsyncing source node information if source | ||||
| * nodes are not synced? Showing users that there is source tracking | * nodes are not synced? Showing users that there is source tracking | ||||
| * when there is none seems useless. | * when there is none seems useless. | ||||
| */ | */ | ||||
| if (st->sns[PF_SN_LIMIT] != NULL) | if (st->sns[PF_SN_LIMIT] != NULL) | ||||
| sp->pfs_1301.sync_flags |= PFSYNC_FLAG_SRCNODE; | sp->pfs_1400.sync_flags |= PFSYNC_FLAG_SRCNODE; | ||||
| if (st->sns[PF_SN_NAT] != NULL || st->sns[PF_SN_ROUTE]) | if (st->sns[PF_SN_NAT] != NULL || st->sns[PF_SN_ROUTE]) | ||||
| sp->pfs_1301.sync_flags |= PFSYNC_FLAG_NATSRCNODE; | sp->pfs_1400.sync_flags |= PFSYNC_FLAG_NATSRCNODE; | ||||
| break; | |||||
| case PFSYNC_MSG_VERSION_1500: | |||||
| sp->pfs_1500.state_flags = htons(st->state_flags); | |||||
| sp->pfs_1500.direction = st->direction; | |||||
| sp->pfs_1500.log = st->act.log; | |||||
| sp->pfs_1500.timeout = st->timeout; | |||||
| sp->pfs_1500.wire_proto = st->key[PF_SK_WIRE]->proto; | |||||
| sp->pfs_1500.wire_af = st->key[PF_SK_WIRE]->af; | |||||
| sp->pfs_1500.stack_proto = st->key[PF_SK_STACK]->proto; | |||||
| sp->pfs_1500.stack_af = st->key[PF_SK_STACK]->af; | |||||
| sp->pfs_1500.qid = htons(st->act.qid); | |||||
| sp->pfs_1500.pqid = htons(st->act.pqid); | |||||
| sp->pfs_1500.dnpipe = htons(st->act.dnpipe); | |||||
| sp->pfs_1500.dnrpipe = htons(st->act.dnrpipe); | |||||
| sp->pfs_1500.rtableid = htonl(st->act.rtableid); | |||||
| sp->pfs_1500.min_ttl = st->act.min_ttl; | |||||
| sp->pfs_1500.set_tos = st->act.set_tos; | |||||
| sp->pfs_1500.max_mss = htons(st->act.max_mss); | |||||
| sp->pfs_1500.set_prio[0] = st->act.set_prio[0]; | |||||
| sp->pfs_1500.set_prio[1] = st->act.set_prio[1]; | |||||
| sp->pfs_1500.rt = st->act.rt; | |||||
| sp->pfs_1500.rt_af = st->act.rt_af; | |||||
| if (st->act.rt_kif) | |||||
| strlcpy(sp->pfs_1500.rt_ifname, | |||||
| st->act.rt_kif->pfik_name, | |||||
| sizeof(sp->pfs_1500.rt_ifname)); | |||||
| strlcpy(sp->pfs_1500.orig_ifname, | |||||
| st->orig_kif->pfik_name, | |||||
| sizeof(sp->pfs_1500.orig_ifname)); | |||||
| if ((tagname = pf_tag2tagname(st->tag)) != NULL) | |||||
| strlcpy(sp->pfs_1500.tagname, tagname, | |||||
| sizeof(sp->pfs_1500.tagname)); | |||||
| break; | |||||
| default: | |||||
| panic("%s: Unsupported pfsync_msg_version %d", | |||||
| __func__, msg_version); | |||||
| } | |||||
| sp->pfs_1301.id = st->id; | sp->pfs_1301.id = st->id; | ||||
| sp->pfs_1301.creatorid = st->creatorid; | sp->pfs_1301.creatorid = st->creatorid; | ||||
| pf_state_peer_hton(&st->src, &sp->pfs_1301.src); | pf_state_peer_hton(&st->src, &sp->pfs_1301.src); | ||||
| pf_state_peer_hton(&st->dst, &sp->pfs_1301.dst); | pf_state_peer_hton(&st->dst, &sp->pfs_1301.dst); | ||||
| if (st->rule == NULL) | if (st->rule == NULL) | ||||
| sp->pfs_1301.rule = htonl(-1); | sp->pfs_1301.rule = htonl(-1); | ||||
| ▲ Show 20 Lines • Show All 1,034 Lines • ▼ Show 20 Lines | |||||
| static void | static void | ||||
| pf_load_vnet(void) | pf_load_vnet(void) | ||||
| { | { | ||||
| V_pf_tag_z = uma_zcreate("pf tags", sizeof(struct pf_tagname), | V_pf_tag_z = uma_zcreate("pf tags", sizeof(struct pf_tagname), | ||||
| NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0); | NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0); | ||||
| rm_init_flags(&V_pf_rules_lock, "pf rulesets", RM_RECURSE); | rm_init_flags(&V_pf_rules_lock, "pf rulesets", RM_RECURSE); | ||||
| rm_init_flags(&V_pf_tags_lock, "pf tags and queues", RM_RECURSE); | |||||
| sx_init(&V_pf_ioctl_lock, "pf ioctl"); | sx_init(&V_pf_ioctl_lock, "pf ioctl"); | ||||
| pf_init_tagset(&V_pf_tags, &pf_rule_tag_hashsize, | pf_init_tagset(&V_pf_tags, &pf_rule_tag_hashsize, | ||||
| PF_RULE_TAG_HASH_SIZE_DEFAULT); | PF_RULE_TAG_HASH_SIZE_DEFAULT); | ||||
| #ifdef ALTQ | #ifdef ALTQ | ||||
| pf_init_tagset(&V_pf_qids, &pf_queue_tag_hashsize, | pf_init_tagset(&V_pf_qids, &pf_queue_tag_hashsize, | ||||
| PF_QUEUE_TAG_HASH_SIZE_DEFAULT); | PF_QUEUE_TAG_HASH_SIZE_DEFAULT); | ||||
| #endif | #endif | ||||
| ▲ Show 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static void | static void | ||||
| vnet_pf_init(void *unused __unused) | vnet_pf_init(void *unused __unused) | ||||
| { | { | ||||
| pf_load_vnet(); | pf_load_vnet(); | ||||
| } | } | ||||
| VNET_SYSINIT(vnet_pf_init, SI_SUB_PROTO_FIREWALL, SI_ORDER_THIRD, | VNET_SYSINIT(vnet_pf_init, SI_SUB_PROTO_FIREWALL, SI_ORDER_THIRD, | ||||
| vnet_pf_init, NULL); | vnet_pf_init, NULL); | ||||
| static void | static void | ||||
| vnet_pf_uninit(const void *unused __unused) | vnet_pf_uninit(const void *unused __unused) | ||||
| { | { | ||||
| pf_unload_vnet(); | pf_unload_vnet(); | ||||
| } | } | ||||
| SYSUNINIT(pf_unload, SI_SUB_PROTO_FIREWALL, SI_ORDER_SECOND, pf_unload, NULL); | SYSUNINIT(pf_unload, SI_SUB_PROTO_FIREWALL, SI_ORDER_SECOND, pf_unload, NULL); | ||||
| VNET_SYSUNINIT(vnet_pf_uninit, SI_SUB_PROTO_FIREWALL, SI_ORDER_THIRD, | VNET_SYSUNINIT(vnet_pf_uninit, SI_SUB_PROTO_FIREWALL, SI_ORDER_THIRD, | ||||
| vnet_pf_uninit, NULL); | vnet_pf_uninit, NULL); | ||||
| static int | static int | ||||
| pf_modevent(module_t mod, int type, void *data) | pf_modevent(module_t mod, int type, void *data) | ||||
| { | { | ||||
| int error = 0; | int error = 0; | ||||
| Show All 28 Lines | |||||
return (NULL)