Use copyout() directly instead of updating various fields

before/after each sooptcopyout() call.

Found by:	luigi
Sponsored by:	Yandex LLC
This commit is contained in:
Alexander V. Chernikov 2014-10-20 11:21:07 +00:00
parent 7e67dfc9e1
commit 54b38fcf03

View File

@ -2535,30 +2535,33 @@ ipfw_del_sopt_handler(struct ipfw_sopt_handler *sh, size_t count)
static int
ipfw_flush_sopt_data(struct sockopt_data *sd)
{
#define RULE_MAXSIZE (512*sizeof(u_int32_t))
struct sockopt *sopt;
int error;
size_t sz;
if ((sz = sd->koff) == 0)
sz = sd->koff;
if (sz == 0)
return (0);
if (sd->sopt->sopt_dir == SOPT_GET) {
error = sooptcopyout(sd->sopt, sd->kbuf, sz);
sopt = sd->sopt;
if (sopt->sopt_dir == SOPT_GET) {
error = copyout(sd->kbuf, sopt->sopt_val, sz);
if (error != 0)
return (error);
}
memset(sd->kbuf, 0, sd->ksize);
sd->ktotal += sd->koff;
sd->ktotal += sz;
sd->koff = 0;
if (sd->ktotal + sd->ksize < sd->valsize)
sd->kavail = sd->ksize;
else
sd->kavail = sd->valsize - sd->ktotal;
/* Update sopt buffer */
sd->sopt->sopt_valsize = sd->ktotal;
sd->sopt->sopt_val = sd->sopt_val + sd->ktotal;
/* Update sopt buffer data */
sopt->sopt_valsize = sd->ktotal;
sopt->sopt_val = sd->sopt_val + sd->ktotal;
return (0);
}