PERFORCE change 112252 for review
Paolo Pisati
piso at FreeBSD.org
Thu Dec 28 14:16:46 PST 2006
http://perforce.freebsd.org/chv.cgi?CH=112252
Change 112252 by piso at piso_newluxor on 2006/12/28 22:16:40
mainly style fixes:
o in case of long line, break it and indent + 4 spaces.
o do not initialize vars during declaration.
o declare all the vars at the beginning of function.
o do not put a new line between cases in a switch statement.
o update a comment.
Affected files ...
.. //depot/projects/soc2005/libalias/sbin/ipfw/ipfw2.c#14 edit
.. //depot/projects/soc2005/libalias/sys/netinet/ip_fw2.c#33 edit
Differences ...
==== //depot/projects/soc2005/libalias/sbin/ipfw/ipfw2.c#14 (text+ko) ====
@@ -3293,7 +3293,7 @@
if (ifm->ifm_version != RTM_VERSION) {
if (verbose)
warnx("routing message version %d "
- "not understood", ifm->ifm_version);
+ "not understood", ifm->ifm_version);
continue;
}
if (ifm->ifm_type == RTM_IFINFO) {
@@ -3318,7 +3318,7 @@
if (ifam->ifam_version != RTM_VERSION) {
if (verbose)
warnx("routing message version %d "
- "not understood", ifam->ifam_version);
+ "not understood", ifam->ifam_version);
continue;
}
if (ifam->ifam_type != RTM_NEWADDR)
@@ -3327,9 +3327,10 @@
int i;
char *cp = (char *)(ifam + 1);
- for (i = 1; i < RTA_IFA; i <<= 1)
+ for (i = 1; i < RTA_IFA; i <<= 1) {
if (ifam->ifam_addrs & i)
cp += SA_SIZE((struct sockaddr *)cp);
+ }
if (((struct sockaddr *)cp)->sa_family == AF_INET) {
sin = (struct sockaddr_in *)cp;
break;
@@ -3502,12 +3503,19 @@
setup_redir_addr(char *spool_buf, int len,
int *_ac, char ***_av)
{
- char **av = *_av, *sep; /* Token separator. */
+ char **av, *sep; /* Token separator. */
/* Temporary buffer used to hold server pool ip's. */
char tmp_spool_buf[NAT_BUF_LEN];
- int ac = *_ac, i, space = 0, lsnat = 0;
- int sof_redir = sizeof(struct cfg_redir);
+ int ac, i, space, lsnat, sof_redir, sof_spool;
struct cfg_redir *r;
+ struct cfg_spool *tmp;
+
+ av = *_av;
+ ac = *_ac;
+ space = 0;
+ lsnat = 0;
+ sof_redir = sizeof(struct cfg_redir);
+ sof_spool = sizeof(struct cfg_spool);
if (len >= sof_redir) {
r = (struct cfg_redir *)spool_buf;
@@ -3539,9 +3547,6 @@
/* Setup LSNAT server pool. */
if (sep) {
- int sof_spool = sizeof(struct cfg_spool);
- struct cfg_spool *tmp;
-
sep = strtok(tmp_spool_buf, ",");
while (sep != NULL) {
tmp = (struct cfg_spool *)spool_buf;
@@ -3566,13 +3571,21 @@
setup_redir_port(char *spool_buf, int len,
int *_ac, char ***_av)
{
- char **av = *_av, *sep, *protoName;
+ char **av, *sep, *protoName;
char tmp_spool_buf[NAT_BUF_LEN];
- int ac = *_ac, space = 0, lsnat = 0;
- int sof_redir = sizeof(struct cfg_redir);
+ int ac, space, lsnat, sof_redir, sof_spool;
struct cfg_redir *r;
- u_short numLocalPorts = 0;
- port_range portRange;
+ struct cfg_spool *tmp;
+ u_short numLocalPorts;
+ port_range portRange;
+
+ av = *_av;
+ ac = *_ac;
+ space = 0;
+ lsnat = 0;
+ sof_redir = sizeof(struct cfg_redir);
+ sof_spool = sizeof(struct cfg_spool);
+ numLocalPorts = 0;
if (len >= sof_redir) {
r = (struct cfg_redir *)spool_buf;
@@ -3599,7 +3612,8 @@
errx (EX_DATAERR, "redirect_port: missing local address");
sep = strchr(*av, ',');
- if (sep) { /* LSNAT redirection syntax. */
+ /* LSNAT redirection syntax. */
+ if (sep) {
r->laddr.s_addr = INADDR_NONE;
r->lport = ~0;
numLocalPorts = 1;
@@ -3608,15 +3622,15 @@
lsnat = 1;
} else {
if (StrToAddrAndPortRange (*av, &r->laddr, protoName,
- &portRange) != 0)
+ &portRange) != 0)
errx(EX_DATAERR, "redirect_port:"
- "invalid local port range");
+ "invalid local port range");
r->lport = GETLOPORT(portRange);
numLocalPorts = GETNUMPORTS(portRange);
- }
+ }
INC_ARGCV();
-
+
/*
* Extract public port and optionally address.
*/
@@ -3626,14 +3640,14 @@
sep = strchr (*av, ':');
if (sep) {
if (StrToAddrAndPortRange (*av, &r->paddr, protoName,
- &portRange) != 0)
+ &portRange) != 0)
errx(EX_DATAERR, "redirect_port:"
- "invalid public port range");
+ "invalid public port range");
} else {
r->paddr.s_addr = INADDR_ANY;
if (StrToPortRange (*av, protoName, &portRange) != 0)
errx(EX_DATAERR, "redirect_port:"
- "invalid public port range");
+ "invalid public port range");
}
r->pport = GETLOPORT(portRange);
@@ -3651,17 +3665,17 @@
sep = strchr (*av, ':');
if (sep) {
if (StrToAddrAndPortRange (*av, &r->raddr, protoName,
- &portRange) != 0)
- errx(EX_DATAERR, "redirect_port:"
- "invalid remote port range");
+ &portRange) != 0)
+ errx(EX_DATAERR, "redirect_port:"
+ "invalid remote port range");
} else {
SETLOPORT(portRange, 0);
SETNUMPORTS(portRange, 1);
StrToAddr (*av, &r->raddr);
}
INC_ARGCV();
- } else {
- SETLOPORT(portRange, 0);
+ } else {
+ SETLOPORT(portRange, 0);
SETNUMPORTS(portRange, 1);
r->raddr.s_addr = INADDR_ANY;
}
@@ -3673,21 +3687,18 @@
*/
if (numLocalPorts != r->pport_cnt)
errx(EX_DATAERR, "redirect_port:"
- "port ranges must be equal in size");
-
+ "port ranges must be equal in size");
+
/* Remote port range is allowed to be '0' which means all ports. */
if (r->rport_cnt != numLocalPorts &&
(r->rport_cnt != 1 || r->rport != 0))
errx(EX_DATAERR, "redirect_port: remote port must"
- "be 0 or equal to local port range in size");
+ "be 0 or equal to local port range in size");
/*
* Setup LSNAT server pool.
*/
if (lsnat) {
- int sof_spool = sizeof(struct cfg_spool);
- struct cfg_spool *tmp;
-
sep = strtok(tmp_spool_buf, ",");
while (sep != NULL) {
tmp = (struct cfg_spool *)spool_buf;
@@ -3696,12 +3707,12 @@
len -= sof_spool;
space += sof_spool;
if (StrToAddrAndPortRange(sep, &tmp->addr, protoName,
- &portRange) != 0)
+ &portRange) != 0)
errx(EX_DATAERR, "redirect_port:"
- "invalid local port range");
+ "invalid local port range");
if (GETNUMPORTS(portRange) != 1)
errx(EX_DATAERR, "redirect_port: local port"
- "must be single in this context");
+ "must be single in this context");
tmp->port = GETLOPORT(portRange);
r->spool_cnt++;
/* Point to the next possible cfg_spool. */
@@ -3718,12 +3729,15 @@
setup_redir_proto(char *spool_buf, int len,
int *_ac, char ***_av)
{
- char **av = *_av;
- int ac = *_ac, i, space;
+ char **av;
+ int ac, i, space, sof_redir;;
struct protoent *protoent;
- int sof_redir = sizeof(struct cfg_redir);
struct cfg_redir *r;
+ av = *_av;
+ ac = *_ac;
+ sof_redir = sizeof(struct cfg_redir);
+
if (len >= sof_redir) {
r = (struct cfg_redir *)spool_buf;
/* Skip cfg_redir at beginning of buf. */
@@ -3789,14 +3803,19 @@
static void
print_nat_config(char *buf) {
- struct cfg_nat *n = (struct cfg_nat *)buf;
- int i, cnt, flag = 1, off = sizeof(*n);
- int sof_redir = sizeof(struct cfg_redir);
- int sof_spool = sizeof(struct cfg_spool);
+ struct cfg_nat *n;
+ int i, cnt, flag, off;
+ int sof_redir, sof_spool;
struct cfg_redir *t;
struct cfg_spool *s;
struct protoent *p;
+ n = (struct cfg_nat *)buf;
+ flag = 1;
+ off = sizeof(*n);
+ sof_redir = sizeof(struct cfg_redir);
+ sof_spool = sizeof(struct cfg_spool);
+
printf("ipfw nat %u config", n->id);
if (strlen(n->if_name) != 0)
printf(" if %s", n->if_name);
@@ -3827,7 +3846,7 @@
}
}
/* Print all the redirect's data configuration. */
- for (cnt=0; cnt < n->redir_cnt; cnt++) {
+ for (cnt = 0; cnt < n->redir_cnt; cnt++) {
t = (struct cfg_redir *)&buf[off];
off += sof_redir;
switch (t->mode) {
@@ -3836,7 +3855,7 @@
if (t->spool_cnt == 0)
printf(" %s", inet_ntoa(t->laddr));
else
- for (i=0; i < t->spool_cnt; i++) {
+ for (i = 0; i < t->spool_cnt; i++) {
s = (struct cfg_spool *)&buf[off];
if (i)
printf(",");
@@ -3854,14 +3873,14 @@
printf("%s:%u", inet_ntoa(t->laddr), t->lport);
if (t->pport_cnt > 1)
printf("-%u", t->lport +
- t->pport_cnt - 1);
+ t->pport_cnt - 1);
} else
for (i=0; i < t->spool_cnt; i++) {
s = (struct cfg_spool *)&buf[off];
if (i)
printf(",");
printf("%s:%u", inet_ntoa(s->addr),
- s->port);
+ s->port);
off += sof_spool;
}
@@ -3878,14 +3897,14 @@
printf(":%u", t->rport);
if (!t->spool_cnt && t->rport_cnt > 1)
printf("-%u", t->rport +
- t->rport_cnt - 1);
+ t->rport_cnt - 1);
}
}
break;
case REDIR_PROTO:
p = getprotobynumber(t->proto);
printf(" redirect_proto %s %s", p->p_name,
- inet_ntoa(t->laddr));
+ inet_ntoa(t->laddr));
if (t->paddr.s_addr != 0) {
printf(" %s", inet_ntoa(t->paddr));
if (t->raddr.s_addr)
@@ -3905,11 +3924,13 @@
{
struct cfg_nat *n; /* Nat instance configuration. */
struct in_addr ip;
- int i, len = NAT_BUF_LEN;
- /* Offset in buf: save space for n at the beginning. */
- int off = sizeof(*n);
+ int i, len, off, sof_redir, tok;
char *id, buf[NAT_BUF_LEN]; /* Buffer for serialized data. */
+ sof_redir = sizeof(struct cfg_redir);
+ len = NAT_BUF_LEN;
+ /* Offset in buf: save space for n at the beginning. */
+ off = sizeof(*n);
memset(buf, 0, sizeof(buf));
n = (struct cfg_nat *)buf;
@@ -3926,81 +3947,67 @@
errx(EX_DATAERR, "missing option");
while (ac > 0) {
- int tok = match_token(nat_params, *av);
- int sof_redir = sizeof(struct cfg_redir);
-
- ac--; av++;
-
- switch (tok) {
- case TOK_IP:
- if (ac == 0)
- errx(EX_DATAERR, "missing option");
- if (!inet_aton(av[0], &(n->ip)))
- errx(EX_DATAERR, "bad ip address ``%s''", av[0]);
- ac--; av++;
- break;
-
- case TOK_IF:
- set_addr_dynamic(av[0], n);
- ac--; av++;
- break;
-
- case TOK_ALOG:
- n->mode |= PKT_ALIAS_LOG;
- break;
-
- case TOK_DENY_INC:
- n->mode |= PKT_ALIAS_DENY_INCOMING;
- break;
-
- case TOK_SAME_PORTS:
- n->mode |= PKT_ALIAS_SAME_PORTS;
- break;
-
- case TOK_UNREG_ONLY:
- n->mode |= PKT_ALIAS_UNREGISTERED_ONLY;
- break;
-
- case TOK_RESET_ADDR:
- n->mode |= PKT_ALIAS_RESET_ON_ADDR_CHANGE;
- break;
-
- case TOK_ALIAS_REV:
- n->mode |= PKT_ALIAS_REVERSE;
- break;
-
- case TOK_PROXY_ONLY:
- n->mode |= PKT_ALIAS_PROXY_ONLY;
- break;
-
- /*
- * All the setup_redir_* functions work directly in the final
- * buffer, see above for details.
- */
- case TOK_REDIR_ADDR:
- case TOK_REDIR_PORT:
- case TOK_REDIR_PROTO:
- switch (tok) {
- case TOK_REDIR_ADDR:
- i = setup_redir_addr(&buf[off], len, &ac, &av);
- break;
-
- case TOK_REDIR_PORT:
- i = setup_redir_port(&buf[off], len, &ac, &av);
- break;
-
- case TOK_REDIR_PROTO:
- i = setup_redir_proto(&buf[off], len, &ac, &av);
- break;
- }
- n->redir_cnt++;
- off += i;
- len -= i;
- break;
-
- default:
- errx(EX_DATAERR, "unrecognised option ``%s''", av[-1]);
- }
+ tok = match_token(nat_params, *av);
+ ac--; av++;
+ switch (tok) {
+ case TOK_IP:
+ if (ac == 0)
+ errx(EX_DATAERR, "missing option");
+ if (!inet_aton(av[0], &(n->ip)))
+ errx(EX_DATAERR, "bad ip address ``%s''",
+ av[0]);
+ ac--; av++;
+ break;
+ case TOK_IF:
+ set_addr_dynamic(av[0], n);
+ ac--; av++;
+ break;
+ case TOK_ALOG:
+ n->mode |= PKT_ALIAS_LOG;
+ break;
+ case TOK_DENY_INC:
+ n->mode |= PKT_ALIAS_DENY_INCOMING;
+ break;
+ case TOK_SAME_PORTS:
+ n->mode |= PKT_ALIAS_SAME_PORTS;
+ break;
+ case TOK_UNREG_ONLY:
+ n->mode |= PKT_ALIAS_UNREGISTERED_ONLY;
+ break;
+ case TOK_RESET_ADDR:
+ n->mode |= PKT_ALIAS_RESET_ON_ADDR_CHANGE;
+ break;
+ case TOK_ALIAS_REV:
+ n->mode |= PKT_ALIAS_REVERSE;
+ break;
+ case TOK_PROXY_ONLY:
+ n->mode |= PKT_ALIAS_PROXY_ONLY;
+ break;
+ /*
+ * All the setup_redir_* functions work directly in the final
+ * buffer, see above for details.
+ */
+ case TOK_REDIR_ADDR:
+ case TOK_REDIR_PORT:
+ case TOK_REDIR_PROTO:
+ switch (tok) {
+ case TOK_REDIR_ADDR:
+ i = setup_redir_addr(&buf[off], len, &ac, &av);
+ break;
+ case TOK_REDIR_PORT:
+ i = setup_redir_port(&buf[off], len, &ac, &av);
+ break;
+ case TOK_REDIR_PROTO:
+ i = setup_redir_proto(&buf[off], len, &ac, &av);
+ break;
+ }
+ n->redir_cnt++;
+ off += i;
+ len -= i;
+ break;
+ default:
+ errx(EX_DATAERR, "unrecognised option ``%s''", av[-1]);
+ }
}
i = do_cmd(IP_FW_NAT_CFG, buf, off);
@@ -5851,12 +5858,16 @@
show_nat(int ac, char **av) {
struct cfg_nat *n;
struct cfg_redir *e;
- int cmd, i, nbytes, do_cfg, do_rule = 0, frule, lrule, nalloc = 1024,
- size = 0, nat_cnt, r;
- u_int8_t *data = NULL, *p;
+ int cmd, i, nbytes, do_cfg, do_rule, frule, lrule, nalloc, size;
+ int nat_cnt, r;
+ u_int8_t *data, *p;
char **lav, *endptr;
- ac--; av++;
+ do_rule = 0;
+ nalloc = 1024;
+ size = 0;
+ data = NULL;
+ ac--; av++;
/* Parse parameters. */
for (cmd = IP_FW_NAT_GET_LOG, do_cfg = 0; ac != 0; ac--, av++) {
@@ -5883,22 +5894,23 @@
err(EX_OSERR, "getsockopt(IP_FW_GET_%s)",
(cmd == IP_FW_NAT_GET_LOG) ? "LOG" : "CONFIG");
}
- if (nbytes == 0)
+ if (nbytes == 0)
exit(0);
if (do_cfg) {
nat_cnt = *((int *)data);
for (i = sizeof(nat_cnt); nat_cnt; nat_cnt--) {
n = (struct cfg_nat *)&data[i];
- if (do_rule)
- if (!(frule <= n->id && lrule >= n->id))
+ if (do_rule) {
+ if (!(frule <= n->id && lrule >= n->id))
continue;
+ }
print_nat_config(&data[i]);
i += sizeof(struct cfg_nat);
e = (struct cfg_redir *)&data[i];
if (e->mode == REDIR_ADDR || e->mode == REDIR_PORT ||
e->mode == REDIR_PROTO)
i += sizeof(struct cfg_redir) + e->spool_cnt *
- sizeof(struct cfg_spool);
+ sizeof(struct cfg_spool);
}
} else {
for (i = 0; 1; i += LIBALIAS_BUF_SIZE + sizeof(int)) {
@@ -5906,9 +5918,10 @@
if (p == data + nbytes)
break;
bcopy(p, &r, sizeof(int));
- if (do_rule)
+ if (do_rule) {
if (!(frule <= r && lrule >= r))
continue;
+ }
printf("nat %u: %s\n", r, p+sizeof(int));
}
}
==== //depot/projects/soc2005/libalias/sys/netinet/ip_fw2.c#33 (text+ko) ====
@@ -2055,7 +2055,7 @@
if (ifa->ifa_addr->sa_family != AF_INET)
continue;
ptr->ip = ((struct sockaddr_in *)
- (ifa->ifa_addr))->sin_addr;
+ (ifa->ifa_addr))->sin_addr;
LibAliasSetAddress(ptr->lib, ptr->ip);
}
mtx_unlock(&ifp->if_addr_mtx);
@@ -2071,9 +2071,8 @@
IPFW_WLOCK_ASSERT(&layer3_chain);
for (rule = layer3_chain.rules; rule; rule = rule->next) {
ipfw_insn_nat *cmd = (ipfw_insn_nat *)ACTION_PTR(rule);
-
if (cmd->o.opcode != O_NAT)
- continue;
+ continue;
if (cmd->nat != NULL && cmd->nat->id == i)
cmd->nat = NULL;
}
@@ -2084,7 +2083,7 @@
struct cfg_nat *ptr;
LIST_FOREACH(ptr, &layer3_chain.nat, _next)
- if (ptr->id == i)
+ if (ptr->id == i)
return(ptr);
return (NULL);
}
@@ -2118,12 +2117,12 @@
switch (r->mode) {
case REDIR_PORT:
num = r->pport_cnt;
+ /* FALLTHROUGH */
case REDIR_ADDR:
case REDIR_PROTO:
/* Delete all libalias redirect entry. */
for (i = 0; i < num; i++)
- LibAliasRedirectDelete(n->lib,
- r->alink[i]);
+ LibAliasRedirectDelete(n->lib, r->alink[i]);
/* Del spool cfg if any. */
LIST_FOREACH_SAFE(s, &r->spool_chain, _next, tmp_s) {
LIST_REMOVE(s, _next);
@@ -2133,7 +2132,7 @@
LIST_REMOVE(r, _next);
free(r, M_IPFW);
break;
- default:
+ default:
printf("unknown redirect mode: %u\n", r->mode);
/* XXX - panic?!?!? */
break;
@@ -2143,14 +2142,16 @@
static int
add_redir_spool_cfg(char *buf, struct cfg_nat *ptr) {
- int sof_alinkp = sizeof(struct alias_link *);
- int sof_redir = sizeof(struct cfg_redir);
- int sof_spool = sizeof(struct cfg_spool);
+ int sof_alinkp, sof_redir, sof_spool;
struct cfg_redir *r, *ser_r;
struct cfg_spool *s, *ser_s;
int cnt, off, i;
char *panic_err;
+ sof_alinkp = sizeof(struct alias_link *);
+ sof_redir = sizeof(struct cfg_redir);
+ sof_spool = sizeof(struct cfg_spool);
+
for(cnt = 0, off = 0; cnt < ptr->redir_cnt; cnt++) {
ser_r = (struct cfg_redir *)&buf[off];
r = malloc(sof_redir, M_IPFW, M_WAITOK | M_ZERO);
@@ -2158,12 +2159,11 @@
LIST_INIT(&r->spool_chain);
off += sof_redir;
r->alink = malloc(sof_alinkp*r->pport_cnt,
- M_IPFW, M_WAITOK | M_ZERO);
+ M_IPFW, M_WAITOK | M_ZERO);
switch (r->mode) {
case REDIR_ADDR:
- r->alink[0] = LibAliasRedirectAddr(ptr->lib,
- r->laddr,
- r->paddr);
+ r->alink[0] = LibAliasRedirectAddr(ptr->lib, r->laddr,
+ r->paddr);
break;
case REDIR_PORT:
for (i = 0 ; i < r->pport_cnt; i++) {
@@ -2171,16 +2171,10 @@
u_short remotePortCopy = r->rport + i;
if (r->rport_cnt == 1 && r->rport == 0)
remotePortCopy = 0;
- r->alink[i] =
- LibAliasRedirectPort(
- ptr->lib,
- r->laddr,
- htons(r->lport + i),
- r->raddr,
- htons(remotePortCopy),
- r->paddr,
- htons(r->pport + i),
- r->proto);
+ r->alink[i] = LibAliasRedirectPort(ptr->lib,
+ r->laddr, htons(r->lport + i), r->raddr,
+ htons(remotePortCopy), r->paddr,
+ htons(r->pport + i), r->proto);
if (r->alink[i] == NULL) {
r->alink[0] = NULL;
break;
@@ -2188,13 +2182,10 @@
}
break;
case REDIR_PROTO:
- r->alink[0] = LibAliasRedirectProto(ptr->lib,
- r->laddr,
- r->raddr,
- r->paddr,
- r->proto);
+ r->alink[0] = LibAliasRedirectProto(ptr->lib ,r->laddr,
+ r->raddr, r->paddr, r->proto);
break;
- default:
+ default:
printf("unknown redirect mode: %u\n", r->mode);
break;
}
@@ -2205,11 +2196,10 @@
for (i = 0; i < r->spool_cnt; i++) {
ser_s = (struct cfg_spool *)&buf[off];
s = malloc(sof_redir, M_IPFW,
- M_WAITOK | M_ZERO);
+ M_WAITOK | M_ZERO);
memcpy(s, ser_s, sof_spool);
LibAliasAddServer(ptr->lib, r->alink[0],
- s->addr,
- htons(s->port));
+ s->addr, htons(s->port));
off += sof_spool;
/* Hook spool entry. */
HOOK_SPOOL(&r->spool_chain, s);
@@ -3456,9 +3446,10 @@
struct cfg_nat *t;
struct mbuf *mcl;
/* XXX - libalias duct tape */
- int ldt = 0;
+ int ldt;
char *c;
+ ldt = 0;
args->rule = f; /* Report matching rule. */
retval = 0;
t = ((ipfw_insn_nat *)cmd)->nat;
@@ -3469,7 +3460,7 @@
goto done;
} else
((ipfw_insn_nat *)cmd)->nat =
- t;
+ t;
}
if ((mcl = m_megapullup(m, m->m_pkthdr.len)) ==
NULL)
@@ -3525,7 +3516,7 @@
* too.
*
* TODO: -make libalias mbuf aware (so
- * it can handle delayed checksum)
+ * it can handle delayed checksum and tso)
*/
if (mcl->m_pkthdr.rcvif == NULL &&
@@ -3536,10 +3527,10 @@
c = mtod(mcl, char *);
if (oif == NULL)
retval = LibAliasIn(t->lib, c,
- MCLBYTES);
+ MCLBYTES);
else
retval = LibAliasOut(t->lib, c,
- MCLBYTES);
+ MCLBYTES);
if (retval != PKT_ALIAS_OK) {
/* XXX - should i add some logging? */
m_free(mcl);
@@ -3549,7 +3540,7 @@
goto done;
}
mcl->m_pkthdr.len = mcl->m_len =
- ntohs(ip->ip_len);
+ ntohs(ip->ip_len);
/*
* XXX - libalias checksum offload
@@ -3575,7 +3566,7 @@
ip->ip_src.s_addr,
ip->ip_dst.s_addr,
htons(ip->ip_p + ip->ip_len -
- (ip->ip_hl << 2))
+ (ip->ip_hl << 2))
);
switch (ip->ip_p) {
@@ -3588,17 +3579,16 @@
th->th_x2 = 0;
th->th_sum = cksum;
mcl->m_pkthdr.csum_data =
- offsetof(struct tcphdr,
- th_sum);
+ offsetof(struct tcphdr,
+ th_sum);
break;
case IPPROTO_UDP:
uh = (struct udphdr *)(ip + 1);
uh->uh_sum = cksum;
mcl->m_pkthdr.csum_data =
- offsetof(struct udphdr,
- uh_sum);
- break;
-
+ offsetof(struct udphdr,
+ uh_sum);
+ break;
}
/*
* No hw checksum offloading: do it
@@ -3608,7 +3598,7 @@
CSUM_DELAY_DATA) == 0) {
in_delayed_cksum(mcl);
mcl->m_pkthdr.csum_flags &=
- ~CSUM_DELAY_DATA;
+ ~CSUM_DELAY_DATA;
}
ip->ip_len = htons(ip->ip_len);
}
@@ -4577,11 +4567,10 @@
char *buf;
buf = malloc(NAT_BUF_LEN, M_IPFW, M_WAITOK | M_ZERO);
-
error = sooptcopyin(sopt, buf, NAT_BUF_LEN,
- sizeof(struct cfg_nat));
+ sizeof(struct cfg_nat));
ser_n = (struct cfg_nat *)buf;
-
+
/*
* Find/create nat rule.
*/
@@ -4590,7 +4579,7 @@
if (ptr == NULL) {
/* New rule: allocate and init new instance. */
ptr = malloc(sizeof(struct cfg_nat),
- M_IPFW, M_NOWAIT | M_ZERO);
+ M_IPFW, M_NOWAIT | M_ZERO);
if (ptr == NULL) {
free(buf, M_IPFW);
IPFW_WUNLOCK(&layer3_chain);
@@ -4604,7 +4593,7 @@
return(EINVAL);
}
LIST_INIT(&ptr->redir_chain);
- } else {
+ } else {
/* Entry already present: temporarly unhook it. */
UNHOOK_NAT(ptr);
flush_nat_ptrs(ser_n->id);
@@ -4669,13 +4658,16 @@
struct cfg_nat *n;
struct cfg_redir *r;
struct cfg_spool *s;
- int sof_nat = sizeof(struct cfg_nat);
- int sof_redir = sizeof(struct cfg_redir);
- int sof_spool = sizeof(struct cfg_spool);
- int nat_cnt = 0, off = sizeof(nat_cnt);
+ int sof_nat, sof_redir, sof_spool;
+ int nat_cnt, off;
+ sof_nat = sizeof(struct cfg_nat);
+ sof_redir = sizeof(struct cfg_redir);
+ sof_spool = sizeof(struct cfg_spool);
+ nat_cnt = 0;
+ off = sizeof(nat_cnt);
+
data = malloc(NAT_BUF_LEN, M_IPFW, M_WAITOK | M_ZERO);
-
IPFW_RLOCK(&layer3_chain);
/* Serialize all the data. */
LIST_FOREACH(n, &layer3_chain.nat, _next) {
@@ -4686,18 +4678,19 @@
LIST_FOREACH(r, &n->redir_chain, _next) {
if (off + sof_redir < NAT_BUF_LEN) {
bcopy(r, &data[off],
- sof_redir);
+ sof_redir);
off += sof_redir;
- LIST_FOREACH(s,
- &r->spool_chain,
- _next) {
- if (off + sof_spool <
- NAT_BUF_LEN) {
- bcopy(s, &data[off],
- sof_spool);
- off += sof_spool;
- } else
- goto nospace;
+ LIST_FOREACH(s, &r->spool_chain,
+ _next) {
+ if (off + sof_spool <
+ NAT_BUF_LEN) {
+ bcopy(s,
+ &data[off],
+ sof_spool);
+ off +=
+ sof_spool;
+ } else
+ goto nospace;
}
} else
goto nospace;
@@ -4713,17 +4706,20 @@
nospace:
IPFW_RUNLOCK(&layer3_chain);
printf("serialized data buffer not big enough:"
- "please increase NAT_BUF_LEN\n");
+ "please increase NAT_BUF_LEN\n");
free(data, M_IPFW);
}
break;
case IP_FW_NAT_GET_LOG:
{
- u_int8_t *data = NULL;
+ u_int8_t *data;
struct cfg_nat *ptr;
- int sof = LIBALIAS_BUF_SIZE;
- int i, size, cnt = 0;
+ int i, size, cnt, sof;
+
+ data = NULL;
+ sof = LIBALIAS_BUF_SIZE;
+ cnt = 0;
IPFW_RLOCK(&layer3_chain);
size = i = 0;
@@ -4922,7 +4918,7 @@
callout_reset(&ipfw_timeout, hz, ipfw_tick, NULL);
LIST_INIT(&layer3_chain.nat);
ifaddr_event_tag = EVENTHANDLER_REGISTER(ifaddr_event, ifaddr_change,
- NULL, EVENTHANDLER_PRI_ANY);
+ NULL, EVENTHANDLER_PRI_ANY);
return (0);
}
More information about the p4-projects
mailing list