Date: Fri, 6 May 2016 03:18:51 +0000 (UTC) From: "Andrey V. Elsukov" <ae@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r299152 - head/sys/netpfil/ipfw Message-ID: <201605060318.u463IpOU081125@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ae Date: Fri May 6 03:18:51 2016 New Revision: 299152 URL: https://svnweb.freebsd.org/changeset/base/299152 Log: Change the type of objhash_cb_t callback function to be able return an error code. Use it to interrupt the loop in ipfw_objhash_foreach(). Obtained from: Yandex LLC Sponsored by: Yandex LLC Modified: head/sys/netpfil/ipfw/ip_fw_iface.c head/sys/netpfil/ipfw/ip_fw_private.h head/sys/netpfil/ipfw/ip_fw_sockopt.c head/sys/netpfil/ipfw/ip_fw_table.c head/sys/netpfil/ipfw/ip_fw_table_algo.c head/sys/netpfil/ipfw/ip_fw_table_value.c Modified: head/sys/netpfil/ipfw/ip_fw_iface.c ============================================================================== --- head/sys/netpfil/ipfw/ip_fw_iface.c Fri May 6 03:11:34 2016 (r299151) +++ head/sys/netpfil/ipfw/ip_fw_iface.c Fri May 6 03:18:51 2016 (r299152) @@ -249,13 +249,14 @@ vnet_ipfw_iface_init(struct ip_fw_chain } } -static void +static int destroy_iface(struct namedobj_instance *ii, struct named_object *no, void *arg) { /* Assume all consumers have been already detached */ free(no, M_IPFW); + return (0); } /* @@ -460,7 +461,7 @@ struct dump_iface_args { struct sockopt_data *sd; }; -static void +static int export_iface_internal(struct namedobj_instance *ii, struct named_object *no, void *arg) { @@ -481,6 +482,7 @@ export_iface_internal(struct namedobj_in i->ifindex = iif->ifindex; i->refcnt = iif->no.refcnt; i->gencnt = iif->gencnt; + return (0); } /* Modified: head/sys/netpfil/ipfw/ip_fw_private.h ============================================================================== --- head/sys/netpfil/ipfw/ip_fw_private.h Fri May 6 03:11:34 2016 (r299151) +++ head/sys/netpfil/ipfw/ip_fw_private.h Fri May 6 03:18:51 2016 (r299152) @@ -649,7 +649,7 @@ caddr_t ipfw_get_sopt_header(struct sock } while(0) struct namedobj_instance; -typedef void (objhash_cb_t)(struct namedobj_instance *ni, struct named_object *, +typedef int (objhash_cb_t)(struct namedobj_instance *ni, struct named_object *, void *arg); typedef uint32_t (objhash_hash_f)(struct namedobj_instance *ni, const void *key, uint32_t kopt); @@ -675,7 +675,7 @@ int ipfw_objhash_same_name(struct namedo void ipfw_objhash_add(struct namedobj_instance *ni, struct named_object *no); void ipfw_objhash_del(struct namedobj_instance *ni, struct named_object *no); uint32_t ipfw_objhash_count(struct namedobj_instance *ni); -void ipfw_objhash_foreach(struct namedobj_instance *ni, objhash_cb_t *f, +int ipfw_objhash_foreach(struct namedobj_instance *ni, objhash_cb_t *f, void *arg); int ipfw_objhash_free_idx(struct namedobj_instance *ni, uint16_t idx); int ipfw_objhash_alloc_idx(void *n, uint16_t *pidx); Modified: head/sys/netpfil/ipfw/ip_fw_sockopt.c ============================================================================== --- head/sys/netpfil/ipfw/ip_fw_sockopt.c Fri May 6 03:11:34 2016 (r299151) +++ head/sys/netpfil/ipfw/ip_fw_sockopt.c Fri May 6 03:18:51 2016 (r299152) @@ -3009,7 +3009,7 @@ ipfw_del_obj_rewriter(struct opcode_obj_ return (0); } -static void +static int export_objhash_ntlv_internal(struct namedobj_instance *ni, struct named_object *no, void *arg) { @@ -3019,8 +3019,9 @@ export_objhash_ntlv_internal(struct name sd = (struct sockopt_data *)arg; ntlv = (ipfw_obj_ntlv *)ipfw_get_sopt_space(sd, sizeof(*ntlv)); if (ntlv == NULL) - return; + return (ENOMEM); ipfw_export_obj_ntlv(no, ntlv); + return (0); } /* @@ -4249,16 +4250,20 @@ ipfw_objhash_count(struct namedobj_insta * Runs @func for each found named object. * It is safe to delete objects from callback */ -void +int ipfw_objhash_foreach(struct namedobj_instance *ni, objhash_cb_t *f, void *arg) { struct named_object *no, *no_tmp; - int i; + int i, ret; for (i = 0; i < ni->nn_size; i++) { - TAILQ_FOREACH_SAFE(no, &ni->names[i], nn_next, no_tmp) - f(ni, no, arg); + TAILQ_FOREACH_SAFE(no, &ni->names[i], nn_next, no_tmp) { + ret = f(ni, no, arg); + if (ret != 0) + return (ret); + } } + return (0); } /* Modified: head/sys/netpfil/ipfw/ip_fw_table.c ============================================================================== --- head/sys/netpfil/ipfw/ip_fw_table.c Fri May 6 03:11:34 2016 (r299151) +++ head/sys/netpfil/ipfw/ip_fw_table.c Fri May 6 03:18:51 2016 (r299152) @@ -2119,7 +2119,7 @@ struct dump_table_args { struct sockopt_data *sd; }; -static void +static int export_table_internal(struct namedobj_instance *ni, struct named_object *no, void *arg) { @@ -2132,6 +2132,7 @@ export_table_internal(struct namedobj_in KASSERT(i != NULL, ("previously checked buffer is not enough")); export_table_info(dta->ch, (struct table_config *)no, i); + return (0); } /* @@ -3123,7 +3124,7 @@ struct swap_table_args { * Ensure we dispatch each table once by setting/checking ochange * fields. */ -static void +static int swap_table_set(struct namedobj_instance *ni, struct named_object *no, void *arg) { @@ -3134,10 +3135,10 @@ swap_table_set(struct namedobj_instance sta = (struct swap_table_args *)arg; if (no->set != sta->set && (no->set != sta->new_set || sta->mv != 0)) - return; + return (0); if (tc->ochanged != 0) - return; + return (0); tc->ochanged = 1; ipfw_objhash_del(ni, no); @@ -3146,12 +3147,13 @@ swap_table_set(struct namedobj_instance else no->set = sta->set; ipfw_objhash_add(ni, no); + return (0); } /* * Cleans up ochange field for all tables. */ -static void +static int clean_table_set_data(struct namedobj_instance *ni, struct named_object *no, void *arg) { @@ -3162,6 +3164,7 @@ clean_table_set_data(struct namedobj_ins sta = (struct swap_table_args *)arg; tc->ochanged = 0; + return (0); } /* @@ -3318,7 +3321,7 @@ static struct ipfw_sopt_handler scodes[] { IP_FW_TABLE_XGETSIZE, 0, HDIR_GET, get_table_size }, }; -static void +static int destroy_table_locked(struct namedobj_instance *ni, struct named_object *no, void *arg) { @@ -3328,6 +3331,7 @@ destroy_table_locked(struct namedobj_ins printf("Error unlinking kidx %d from table %s\n", no->kidx, no->name); free_table_config(ni, (struct table_config *)no); + return (0); } /* Modified: head/sys/netpfil/ipfw/ip_fw_table_algo.c ============================================================================== --- head/sys/netpfil/ipfw/ip_fw_table_algo.c Fri May 6 03:11:34 2016 (r299151) +++ head/sys/netpfil/ipfw/ip_fw_table_algo.c Fri May 6 03:18:51 2016 (r299152) @@ -1941,7 +1941,7 @@ static int ta_lookup_ifidx(struct table_ static int ta_init_ifidx(struct ip_fw_chain *ch, void **ta_state, struct table_info *ti, char *data, uint8_t tflags); static void ta_change_ti_ifidx(void *ta_state, struct table_info *ti); -static void destroy_ifidx_locked(struct namedobj_instance *ii, +static int destroy_ifidx_locked(struct namedobj_instance *ii, struct named_object *no, void *arg); static void ta_destroy_ifidx(void *ta_state, struct table_info *ti); static void ta_dump_ifidx_tinfo(void *ta_state, struct table_info *ti, @@ -1969,7 +1969,7 @@ static int ta_dump_ifidx_tentry(void *ta ipfw_obj_tentry *tent); static int ta_find_ifidx_tentry(void *ta_state, struct table_info *ti, ipfw_obj_tentry *tent); -static void foreach_ifidx(struct namedobj_instance *ii, struct named_object *no, +static int foreach_ifidx(struct namedobj_instance *ii, struct named_object *no, void *arg); static void ta_foreach_ifidx(void *ta_state, struct table_info *ti, ta_foreach_f *f, void *arg); @@ -2126,7 +2126,7 @@ ta_change_ti_ifidx(void *ta_state, struc icfg->ti = ti; } -static void +static int destroy_ifidx_locked(struct namedobj_instance *ii, struct named_object *no, void *arg) { @@ -2139,6 +2139,7 @@ destroy_ifidx_locked(struct namedobj_ins ipfw_iface_del_notify(ch, &ife->ic); ipfw_iface_unref(ch, &ife->ic); free(ife, M_IPFW_TBL); + return (0); } @@ -2560,7 +2561,7 @@ struct wa_ifidx { void *arg; }; -static void +static int foreach_ifidx(struct namedobj_instance *ii, struct named_object *no, void *arg) { @@ -2571,6 +2572,7 @@ foreach_ifidx(struct namedobj_instance * wa = (struct wa_ifidx *)arg; wa->f(ife, wa->arg); + return (0); } static void Modified: head/sys/netpfil/ipfw/ip_fw_table_value.c ============================================================================== --- head/sys/netpfil/ipfw/ip_fw_table_value.c Fri May 6 03:11:34 2016 (r299151) +++ head/sys/netpfil/ipfw/ip_fw_table_value.c Fri May 6 03:18:51 2016 (r299152) @@ -147,7 +147,7 @@ get_value_ptrs(struct ip_fw_chain *ch, s /* * Update pointers to real vaues after @pval change. */ -static void +static int update_tvalue(struct namedobj_instance *ni, struct named_object *no, void *arg) { struct vdump_args *da; @@ -160,7 +160,7 @@ update_tvalue(struct namedobj_instance * pval = da->pval; ptv->pval = &pval[ptv->no.kidx]; ptv->no.name = (char *)&pval[ptv->no.kidx]; - + return (0); } /* @@ -693,7 +693,7 @@ ipfw_export_table_value_v1(struct table_ * Exports real value data into ipfw_table_value structure. * Utilizes "spare1" field to store kernel index. */ -static void +static int dump_tvalue(struct namedobj_instance *ni, struct named_object *no, void *arg) { struct vdump_args *da; @@ -707,11 +707,12 @@ dump_tvalue(struct namedobj_instance *ni /* Out of memory, returning */ if (v == NULL) { da->error = ENOMEM; - return; + return (ENOMEM); } memcpy(v, ptv->pval, sizeof(*v)); v->spare1 = ptv->no.kidx; + return (0); } /* @@ -785,12 +786,13 @@ ipfw_table_value_init(struct ip_fw_chain IPFW_ADD_SOPT_HANDLER(first, scodes); } -static void +static int destroy_value(struct namedobj_instance *ni, struct named_object *no, void *arg) { free(no, M_IPFW); + return (0); } void
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605060318.u463IpOU081125>