Date: Tue, 29 Jul 2014 21:38:06 +0000 (UTC) From: "Alexander V. Chernikov" <melifaro@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r269265 - projects/ipfw/sys/netpfil/ipfw Message-ID: <201407292138.s6TLc6FO074228@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: melifaro Date: Tue Jul 29 21:38:06 2014 New Revision: 269265 URL: http://svnweb.freebsd.org/changeset/base/269265 Log: * Copy ta structures to stable storage to ease future extension. * Remove algo .lookup field since table lookup function is set by algo code. Modified: projects/ipfw/sys/netpfil/ipfw/ip_fw_table.c projects/ipfw/sys/netpfil/ipfw/ip_fw_table.h projects/ipfw/sys/netpfil/ipfw/ip_fw_table_algo.c Modified: projects/ipfw/sys/netpfil/ipfw/ip_fw_table.c ============================================================================== --- projects/ipfw/sys/netpfil/ipfw/ip_fw_table.c Tue Jul 29 21:22:33 2014 (r269264) +++ projects/ipfw/sys/netpfil/ipfw/ip_fw_table.c Tue Jul 29 21:38:06 2014 (r269265) @@ -1600,17 +1600,45 @@ find_table_algo(struct tables_config *tc return (NULL); } -void -ipfw_add_table_algo(struct ip_fw_chain *ch, struct table_algo *ta) +int +ipfw_add_table_algo(struct ip_fw_chain *ch, struct table_algo *ta, size_t size, + int *idx) { struct tables_config *tcfg; + struct table_algo *ta_new; + + if (size > sizeof(struct table_algo)) + return (EINVAL); + + ta_new = malloc(sizeof(struct table_algo), M_IPFW, M_WAITOK | M_ZERO); + memcpy(ta_new, ta, size); tcfg = CHAIN_TO_TCFG(ch); KASSERT(tcfg->algo_count < 255, ("Increase algo array size")); - tcfg->algo[++tcfg->algo_count] = ta; - ta->idx = tcfg->algo_count; + tcfg->algo[++tcfg->algo_count] = ta_new; + ta_new->idx = tcfg->algo_count; + + *idx = ta_new->idx; + + return (0); +} + +void +ipfw_del_table_algo(struct ip_fw_chain *ch, int idx) +{ + struct tables_config *tcfg; + struct table_algo *ta; + + tcfg = CHAIN_TO_TCFG(ch); + + KASSERT(idx <= tcfg->algo_count, ("algo idx %d out of rage 1..%d", idx, + tcfg->algo_count)); + + ta = tcfg->algo[idx]; + KASSERT(ta != NULL, ("algo idx %d is NULL", idx)); + free(ta, M_IPFW); } Modified: projects/ipfw/sys/netpfil/ipfw/ip_fw_table.h ============================================================================== --- projects/ipfw/sys/netpfil/ipfw/ip_fw_table.h Tue Jul 29 21:22:33 2014 (r269264) +++ projects/ipfw/sys/netpfil/ipfw/ip_fw_table.h Tue Jul 29 21:38:06 2014 (r269265) @@ -100,7 +100,6 @@ struct table_algo { int idx; ta_init *init; ta_destroy *destroy; - table_lookup_t *lookup; ta_prepare_add *prepare_add; ta_prepare_del *prepare_del; ta_add *add; @@ -117,7 +116,9 @@ struct table_algo { ta_change_ti *change_ti; }; -void ipfw_add_table_algo(struct ip_fw_chain *ch, struct table_algo *ta); +int ipfw_add_table_algo(struct ip_fw_chain *ch, struct table_algo *ta, + size_t size, int *idx); +void ipfw_del_table_algo(struct ip_fw_chain *ch, int idx); extern struct table_algo cidr_radix, iface_idx; void ipfw_table_algo_init(struct ip_fw_chain *chain); Modified: projects/ipfw/sys/netpfil/ipfw/ip_fw_table_algo.c ============================================================================== --- projects/ipfw/sys/netpfil/ipfw/ip_fw_table_algo.c Tue Jul 29 21:22:33 2014 (r269264) +++ projects/ipfw/sys/netpfil/ipfw/ip_fw_table_algo.c Tue Jul 29 21:38:06 2014 (r269265) @@ -516,7 +516,6 @@ ta_flush_cidr_entry(struct ip_fw_chain * struct table_algo cidr_radix = { .name = "cidr:radix", - .lookup = ta_lookup_radix, .init = ta_init_radix, .destroy = ta_destroy_radix, .prepare_add = ta_prepare_add_cidr, @@ -1195,7 +1194,6 @@ ta_flush_chash_entry(struct ip_fw_chain struct table_algo cidr_hash = { .name = "cidr:hash", - .lookup = ta_lookup_chash_slow, .init = ta_init_chash, .destroy = ta_destroy_chash, .prepare_add = ta_prepare_add_chash, @@ -1848,7 +1846,6 @@ ta_foreach_ifidx(void *ta_state, struct struct table_algo iface_idx = { .name = "iface:array", - .lookup = ta_lookup_ifidx, .init = ta_init_ifidx, .destroy = ta_destroy_ifidx, .prepare_add = ta_prepare_add_ifidx, @@ -1867,20 +1864,26 @@ struct table_algo iface_idx = { }; void -ipfw_table_algo_init(struct ip_fw_chain *chain) +ipfw_table_algo_init(struct ip_fw_chain *ch) { + size_t sz; + /* * Register all algorithms presented here. */ - ipfw_add_table_algo(chain, &cidr_radix); - ipfw_add_table_algo(chain, &cidr_hash); - ipfw_add_table_algo(chain, &iface_idx); + sz = sizeof(struct table_algo); + ipfw_add_table_algo(ch, &cidr_radix, sz, &cidr_radix.idx); + ipfw_add_table_algo(ch, &cidr_hash, sz, &cidr_hash.idx); + ipfw_add_table_algo(ch, &iface_idx, sz, &iface_idx.idx); } void -ipfw_table_algo_destroy(struct ip_fw_chain *chain) +ipfw_table_algo_destroy(struct ip_fw_chain *ch) { - /* Do nothing */ + + ipfw_del_table_algo(ch, cidr_radix.idx); + ipfw_del_table_algo(ch, cidr_hash.idx); + ipfw_del_table_algo(ch, iface_idx.idx); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201407292138.s6TLc6FO074228>