Date: Fri, 29 Dec 2006 18:44:16 GMT From: Paolo Pisati <piso@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 112294 for review Message-ID: <200612291844.kBTIiGnV001573@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=112294 Change 112294 by piso@piso_newluxor on 2006/12/29 18:44:01 o turn all the "int sof_foo = sizeof(struct foo)" into constants and move them into ip_fw.h o spacing Affected files ... .. //depot/projects/soc2005/libalias/sbin/ipfw/ipfw2.c#16 edit .. //depot/projects/soc2005/libalias/sys/netinet/ip_fw.h#8 edit .. //depot/projects/soc2005/libalias/sys/netinet/ip_fw2.c#35 edit Differences ... ==== //depot/projects/soc2005/libalias/sbin/ipfw/ipfw2.c#16 (text+ko) ==== @@ -3506,7 +3506,7 @@ char **av, *sep; /* Token separator. */ /* Temporary buffer used to hold server pool ip's. */ char tmp_spool_buf[NAT_BUF_LEN]; - int ac, i, space, lsnat, sof_redir, sof_spool; + int ac, i, space, lsnat; struct cfg_redir *r; struct cfg_spool *tmp; @@ -3514,15 +3514,12 @@ ac = *_ac; space = 0; lsnat = 0; - sof_redir = sizeof(struct cfg_redir); - sof_spool = sizeof(struct cfg_spool); - - if (len >= sof_redir) { + if (len >= SOF_REDIR) { r = (struct cfg_redir *)spool_buf; /* Skip cfg_redir at beginning of buf. */ - spool_buf = &spool_buf[sof_redir]; - space = sof_redir; - len -= sof_redir; + spool_buf = &spool_buf[SOF_REDIR]; + space = SOF_REDIR; + len -= SOF_REDIR; } else goto nospace; r->mode = REDIR_ADDR; @@ -3550,15 +3547,15 @@ sep = strtok(tmp_spool_buf, ","); while (sep != NULL) { tmp = (struct cfg_spool *)spool_buf; - if (len < sof_spool) + if (len < SOF_SPOOL) goto nospace; - len -= sof_spool; - space += sof_spool; + len -= SOF_SPOOL; + space += SOF_SPOOL; StrToAddr(sep, &tmp->addr); tmp->port = ~0; r->spool_cnt++; /* Point to the next possible cfg_spool. */ - spool_buf = &spool_buf[sof_spool]; + spool_buf = &spool_buf[SOF_SPOOL]; sep = strtok(NULL, ","); } } @@ -3573,7 +3570,7 @@ { char **av, *sep, *protoName; char tmp_spool_buf[NAT_BUF_LEN]; - int ac, space, lsnat, sof_redir, sof_spool; + int ac, space, lsnat; struct cfg_redir *r; struct cfg_spool *tmp; u_short numLocalPorts; @@ -3583,16 +3580,14 @@ ac = *_ac; space = 0; lsnat = 0; - sof_redir = sizeof(struct cfg_redir); - sof_spool = sizeof(struct cfg_spool); numLocalPorts = 0; - if (len >= sof_redir) { + if (len >= SOF_REDIR) { r = (struct cfg_redir *)spool_buf; /* Skip cfg_redir at beginning of buf. */ - spool_buf = &spool_buf[sof_redir]; - space = sof_redir; - len -= sof_redir; + spool_buf = &spool_buf[SOF_REDIR]; + space = SOF_REDIR; + len -= SOF_REDIR; } else goto nospace; r->mode = REDIR_PORT; @@ -3702,10 +3697,10 @@ sep = strtok(tmp_spool_buf, ","); while (sep != NULL) { tmp = (struct cfg_spool *)spool_buf; - if (len < sof_spool) + if (len < SOF_SPOOL) goto nospace; - len -= sof_spool; - space += sof_spool; + len -= SOF_SPOOL; + space += SOF_SPOOL; if (StrToAddrAndPortRange(sep, &tmp->addr, protoName, &portRange) != 0) errx(EX_DATAERR, "redirect_port:" @@ -3716,7 +3711,7 @@ tmp->port = GETLOPORT(portRange); r->spool_cnt++; /* Point to the next possible cfg_spool. */ - spool_buf = &spool_buf[sof_spool]; + spool_buf = &spool_buf[SOF_SPOOL]; sep = strtok(NULL, ","); } } @@ -3730,20 +3725,18 @@ int *_ac, char ***_av) { char **av; - int ac, i, space, sof_redir;; + int ac, i, space; struct protoent *protoent; struct cfg_redir *r; av = *_av; ac = *_ac; - sof_redir = sizeof(struct cfg_redir); - - if (len >= sof_redir) { + if (len >= SOF_REDIR) { r = (struct cfg_redir *)spool_buf; /* Skip cfg_redir at beginning of buf. */ - spool_buf = &spool_buf[sof_redir]; - space = sof_redir; - len -= sof_redir; + spool_buf = &spool_buf[SOF_REDIR]; + space = SOF_REDIR; + len -= SOF_REDIR; } else goto nospace; r->mode = REDIR_PROTO; @@ -3805,7 +3798,6 @@ print_nat_config(char *buf) { 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; @@ -3813,9 +3805,6 @@ 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); @@ -3848,7 +3837,7 @@ /* Print all the redirect's data configuration. */ for (cnt = 0; cnt < n->redir_cnt; cnt++) { t = (struct cfg_redir *)&buf[off]; - off += sof_redir; + off += SOF_REDIR; switch (t->mode) { case REDIR_ADDR: printf(" redirect_addr"); @@ -3862,7 +3851,7 @@ else printf(" "); printf("%s", inet_ntoa(s->addr)); - off += sof_spool; + off += SOF_SPOOL; } printf(" %s", inet_ntoa(t->paddr)); break; @@ -3881,7 +3870,7 @@ printf(","); printf("%s:%u", inet_ntoa(s->addr), s->port); - off += sof_spool; + off += SOF_SPOOL; } printf(" "); @@ -3924,10 +3913,9 @@ { struct cfg_nat *n; /* Nat instance configuration. */ struct in_addr ip; - int i, len, off, sof_redir, tok; + int i, len, off, 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); ==== //depot/projects/soc2005/libalias/sys/netinet/ip_fw.h#8 (text+ko) ==== @@ -340,7 +340,7 @@ LIST_HEAD(spool_chain, cfg_spool) spool_chain; }; -#define NAT_BUF_LEN 1024 +#define NAT_BUF_LEN 1024 /* Nat configuration data struct. */ struct cfg_nat { /* chain of nat instances */ @@ -356,6 +356,10 @@ LIST_HEAD(redir_chain, cfg_redir) redir_chain; }; +#define SOF_NAT sizeof(struct cfg_nat) +#define SOF_REDIR sizeof(struct cfg_redir) +#define SOF_SPOOL sizeof(struct cfg_spool) + /* Nat command. */ typedef struct _ipfw_insn_nat { ipfw_insn o; ==== //depot/projects/soc2005/libalias/sys/netinet/ip_fw2.c#35 (text+ko) ==== @@ -2142,23 +2142,18 @@ static int add_redir_spool_cfg(char *buf, struct cfg_nat *ptr) { - 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++) { + 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); - memcpy(r, ser_r, sof_redir); + r = malloc(SOF_REDIR, M_IPFW, M_WAITOK | M_ZERO); + memcpy(r, ser_r, SOF_REDIR); LIST_INIT(&r->spool_chain); - off += sof_redir; - r->alink = malloc(sof_alinkp*r->pport_cnt, + off += SOF_REDIR; + r->alink = malloc(sizeof(struct alias_link *) * r->pport_cnt, M_IPFW, M_WAITOK | M_ZERO); switch (r->mode) { case REDIR_ADDR: @@ -2195,12 +2190,12 @@ } else /* LSNAT handling. */ for (i = 0; i < r->spool_cnt; i++) { ser_s = (struct cfg_spool *)&buf[off]; - s = malloc(sof_redir, M_IPFW, + s = malloc(SOF_REDIR, M_IPFW, M_WAITOK | M_ZERO); - memcpy(s, ser_s, sof_spool); + memcpy(s, ser_s, SOF_SPOOL); LibAliasAddServer(ptr->lib, r->alink[0], s->addr, htons(s->port)); - off += sof_spool; + off += SOF_SPOOL; /* Hook spool entry. */ HOOK_SPOOL(&r->spool_chain, s); } @@ -4658,12 +4653,8 @@ struct cfg_nat *n; struct cfg_redir *r; struct cfg_spool *s; - 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); @@ -4672,23 +4663,23 @@ /* Serialize all the data. */ LIST_FOREACH(n, &layer3_chain.nat, _next) { nat_cnt++; - if (off + sof_nat < NAT_BUF_LEN) { - bcopy(n, &data[off], sof_nat); - off += sof_nat; + if (off + SOF_NAT < NAT_BUF_LEN) { + bcopy(n, &data[off], SOF_NAT); + off += SOF_NAT; LIST_FOREACH(r, &n->redir_chain, _next) { - if (off + sof_redir < NAT_BUF_LEN) { + if (off + SOF_REDIR < NAT_BUF_LEN) { bcopy(r, &data[off], - sof_redir); - off += sof_redir; + SOF_REDIR); + off += SOF_REDIR; LIST_FOREACH(s, &r->spool_chain, _next) { - if (off + sof_spool < + if (off + SOF_SPOOL < NAT_BUF_LEN) { bcopy(s, &data[off], - sof_spool); + SOF_SPOOL); off += - sof_spool; + SOF_SPOOL; } else goto nospace; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200612291844.kBTIiGnV001573>