NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: bin/47101 (ipmon(8) alignment problem on 32-bit sparc)
The following reply was made to PR bin/47101; it has been noted by GNATS.
From: Takeshi Nakayama <nakayama%NetBSD.org@localhost>
To: christos%zoulas.com@localhost
Cc: jnemeth%victoria.tc.ca@localhost, gnats-bugs%NetBSD.org@localhost,
darrenr%NetBSD.org@localhost,
gnats-admin%NetBSD.org@localhost, netbsd-bugs%NetBSD.org@localhost,
martin%NetBSD.org@localhost
Subject: Re: bin/47101 (ipmon(8) alignment problem on 32-bit sparc)
Date: Thu, 25 Oct 2012 22:43:28 +0900 (JST)
----Next_Part(Thu_Oct_25_22_43_28_2012_891)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
>>> christos%zoulas.com@localhost (Christos Zoulas) wrote
> On Oct 23, 8:04am, jnemeth%victoria.tc.ca@localhost (John Nemeth) wrote:
> -- Subject: Re: bin/47101 (ipmon(8) alignment problem on 32-bit sparc)
>
> | Didn't Christos fix this? Although the path is different in
> | -current, so it might need a pullup.
>
> Yes, I fixed it.
Thanks.
I backported your fixes[*] to the netbsd-6 branch as attached. If
there are no objections, I will send a pullup request.
[*] http://mail-index.netbsd.org/source-changes/2012/10/21/msg038121.html
http://mail-index.netbsd.org/source-changes/2012/10/22/msg038125.html
http://mail-index.netbsd.org/source-changes/2012/10/22/msg038126.html
-- Takeshi Nakayama
----Next_Part(Thu_Oct_25_22_43_28_2012_891)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="ipmon-fix-nb6.diff"
Index: src/dist/ipf/ipmon.h
===================================================================
RCS file: /cvsroot/src/dist/ipf/Attic/ipmon.h,v
retrieving revision 1.2
diff -u -d -r1.2 ipmon.h
--- src/dist/ipf/ipmon.h 15 Feb 2012 17:55:04 -0000 1.2
+++ src/dist/ipf/ipmon.h 25 Oct 2012 02:08:37 -0000
@@ -84,14 +84,14 @@
#define OPT_PORTNUM 0x400
#define OPT_LOGALL (OPT_NAT|OPT_STATE|OPT_FILTER)
-#define HOSTNAME_V4(a,b) hostname((a), 4, (u_32_t *)&(b))
+#define HOSTNAME_V4(a,b) hostname((a), 4, (const void *)&(b))
#ifndef LOGFAC
#define LOGFAC LOG_LOCAL0
#endif
extern int load_config(char *);
-extern void dumphex(FILE *, int, char *, int);
-extern int check_action(char *, char *, int, int);
+extern void dumphex(FILE *, int, const void *, size_t);
+extern int check_action(const char *, const char *, int, int);
extern char *getword(int);
extern int fac_findname(char *);
Index: src/dist/ipf/tools/ipmon.c
===================================================================
RCS file: /cvsroot/src/dist/ipf/tools/Attic/ipmon.c,v
retrieving revision 1.21
diff -u -d -r1.21 ipmon.c
--- src/dist/ipf/tools/ipmon.c 15 Feb 2012 17:55:11 -0000 1.21
+++ src/dist/ipf/tools/ipmon.c 25 Oct 2012 02:08:37 -0000
@@ -140,32 +140,31 @@
static FILE *binarylog = NULL;
static char *binarylogfile = NULL;
static int donehup = 0;
-static void usage __P((char *));
-static void handlehup __P((int));
-static void flushlogs __P((char *, FILE *));
-static void print_log __P((int, FILE *, char *, int));
-static void print_ipflog __P((FILE *, char *, int));
-static void print_natlog __P((FILE *, char *, int));
-static void print_statelog __P((FILE *, char *, int));
-static int read_log __P((int, int *, char *, int));
-static void write_pid __P((char *));
-static char *icmpname __P((u_int, u_int));
-static char *icmpname6 __P((u_int, u_int));
-static icmp_type_t *find_icmptype __P((int, icmp_type_t *, size_t));
-static icmp_subtype_t *find_icmpsubtype __P((int, icmp_subtype_t *,
size_t));
+static void usage(const char *);
+static void handlehup(int);
+static void flushlogs(const char *, FILE *);
+static void print_log(int, FILE *, const void *, size_t);
+static void print_ipflog(FILE *, const void *, size_t);
+static void print_natlog(FILE *, const void *, size_t);
+static void print_statelog(FILE *, const void *, size_t);
+static int read_log(int, size_t *, void *, size_t);
+static void write_pid(const char *);
+static char *icmpname(u_int, u_int);
+static char *icmpname6(u_int, u_int);
+static icmp_type_t *find_icmptype(int, icmp_type_t *, size_t);
+static icmp_subtype_t *find_icmpsubtype(int, icmp_subtype_t *, size_t);
#ifdef __hpux
-static struct tm *get_tm __P((u_32_t));
+static struct tm *get_tm(u_32_t);
#else
-static struct tm *get_tm __P((time_t));
+static struct tm *get_tm(time_t);
#endif
-char *hostname __P((int, int, u_32_t *));
-char *portname __P((int, char *, u_int));
-int main __P((int, char *[]));
+char *hostname(int, int, const void *);
+char *portname(int, char *, u_int);
-static void logopts __P((int, char *));
-static void init_tabs __P((void));
-static char *getproto __P((u_int));
+static void logopts(int, const char *);
+static void init_tabs(void);
+static char *getproto(u_int);
static char **protocols = NULL;
static char **udp_ports = NULL;
@@ -186,7 +185,7 @@
#define OPT_LOGALL (OPT_NAT|OPT_STATE|OPT_FILTER)
#define OPT_LOGBODY 0x800
-#define HOSTNAME_V4(a,b) hostname((a), 4, (u_32_t *)&(b))
+#define HOSTNAME_V4(a,b) hostname((a), 4, (const void *)&(b))
#ifndef LOGFAC
#define LOGFAC LOG_LOCAL0
@@ -337,10 +336,8 @@
{ -2, NULL, 0, NULL }
};
-static icmp_subtype_t *find_icmpsubtype(type, table, tablesz)
-int type;
-icmp_subtype_t *table;
-size_t tablesz;
+static icmp_subtype_t *
+find_icmpsubtype(int type, icmp_subtype_t *table, size_t tablesz)
{
icmp_subtype_t *ist;
int i;
@@ -362,10 +359,8 @@
}
-static icmp_type_t *find_icmptype(type, table, tablesz)
-int type;
-icmp_type_t *table;
-size_t tablesz;
+static icmp_type_t *
+find_icmptype(int type, icmp_type_t *table, size_t tablesz)
{
icmp_type_t *it;
int i;
@@ -387,15 +382,16 @@
}
-static void handlehup(sig)
-int sig;
+static void
+handlehup(int sig)
{
signal(SIGHUP, handlehup);
donehup = 1;
}
-static void init_tabs()
+static void
+init_tabs(void)
{
struct protoent *p;
struct servent *s;
@@ -480,8 +476,8 @@
}
-static char *getproto(p)
-u_int p;
+static char *
+getproto(u_int p)
{
static char pnum[4];
char *s;
@@ -496,11 +492,10 @@
}
-static int read_log(fd, lenp, buf, bufsize)
-int fd, bufsize, *lenp;
-char *buf;
+static int
+read_log(int fd, size_t *lenp, void *buf, size_t bufsize)
{
- int nr;
+ ssize_t nr;
nr = read(fd, buf, bufsize);
if (!nr)
@@ -512,9 +507,8 @@
}
-char *hostname(res, v, ip)
-int res, v;
-u_32_t *ip;
+char *
+hostname(int res, int v, const void *ip)
{
# define MAX_INETA 16
static char hname[MAXHOSTNAMELEN + MAX_INETA + 3];
@@ -525,10 +519,10 @@
struct in_addr ipa;
if (v == 4) {
- ipa.s_addr = *ip;
+ ipa.s_addr = *(const u_32_t *)ip;
if (!res)
return inet_ntoa(ipa);
- hp = gethostbyaddr((char *)ip, sizeof(*ip), AF_INET);
+ hp = gethostbyaddr(ip, 4, AF_INET);
if (!hp)
return inet_ntoa(ipa);
sprintf(hname, "%.*s[%s]", MAXHOSTNAMELEN, hp->h_name,
@@ -545,10 +539,8 @@
}
-char *portname(res, proto, port)
-int res;
-char *proto;
-u_int port;
+char *
+portname(int res, char *proto, u_int port)
{
static char pname[8];
char *s;
@@ -569,9 +561,8 @@
}
-static char *icmpname(type, code)
-u_int type;
-u_int code;
+static char *
+icmpname(u_int type, u_int code)
{
static char name[80];
icmp_subtype_t *ist;
@@ -600,9 +591,8 @@
return name;
}
-static char *icmpname6(type, code)
-u_int type;
-u_int code;
+static char *
+icmpname6(u_int type, u_int code)
{
static char name[80];
icmp_subtype_t *ist;
@@ -632,11 +622,8 @@
}
-void dumphex(log, dopts, buf, len)
-FILE *log;
-int dopts;
-char *buf;
-int len;
+void
+dumphex(FILE *log, int dopts, const void *buf, size_t len)
{
char hline[80];
int i, j, k;
@@ -696,12 +683,14 @@
}
-static struct tm *get_tm(sec)
+static struct tm *
+get_tm(
#ifdef __hpux
-u_32_t sec;
+u_32_t sec
#else
-time_t sec;
+time_t sec
#endif
+)
{
struct tm *tm;
time_t t;
@@ -711,19 +700,17 @@
return tm;
}
-static void print_natlog(log, buf, blen)
-FILE *log;
-char *buf;
-int blen;
+static void
+print_natlog(FILE *log, const void *buf, size_t blen)
{
- struct natlog *nl;
- iplog_t *ipl = (iplog_t *)buf;
+ const struct natlog *nl;
+ const iplog_t *ipl = (const iplog_t *)buf;
char *t = line;
struct tm *tm;
int res, i, len;
char *proto;
- nl = (struct natlog *)((char *)ipl + sizeof(*ipl));
+ nl = (const struct natlog *)((const char *)ipl + sizeof(*ipl));
res = (opts & OPT_RESOLVE) ? 1 : 0;
tm = get_tm(ipl->ipl_sec);
len = sizeof(line);
@@ -795,18 +782,16 @@
}
-static void print_statelog(log, buf, blen)
-FILE *log;
-char *buf;
-int blen;
+static void
+print_statelog(FILE *log, const void *buf, size_t blen)
{
- struct ipslog *sl;
- iplog_t *ipl = (iplog_t *)buf;
+ const struct ipslog *sl;
+ const iplog_t *ipl = (const iplog_t *)buf;
char *t = line, *proto;
struct tm *tm;
int res, i, len;
- sl = (struct ipslog *)((char *)ipl + sizeof(*ipl));
+ sl = (const struct ipslog *)((const char *)ipl + sizeof(*ipl));
res = (opts & OPT_RESOLVE) ? 1 : 0;
tm = get_tm(ipl->ipl_sec);
len = sizeof(line);
@@ -935,65 +920,49 @@
}
-static void print_log(logtype, log, buf, blen)
-FILE *log;
-char *buf;
-int logtype, blen;
+static void
+print_log(int logtype, FILE *log, const void *buf, size_t blen)
{
- iplog_t *ipl;
- char *bp = NULL, *bpo = NULL;
+ iplog_t ipl;
int psize;
while (blen > 0) {
- ipl = (iplog_t *)buf;
- if ((u_long)ipl & (sizeof(long)-1)) {
- if (bp)
- bpo = bp;
- bp = (char *)malloc(blen);
- bcopy((char *)ipl, bp, blen);
- if (bpo) {
- free(bpo);
- bpo = NULL;
- }
- buf = bp;
- continue;
- }
+ if (sizeof(ipl) > blen)
+ return;
- psize = ipl->ipl_dsize;
+ memcpy(&ipl, buf, sizeof(ipl));
+ psize = ipl.ipl_dsize;
if (psize > blen)
- break;
+ return;
if (binarylog) {
fwrite(buf, psize, 1, binarylog);
fflush(binarylog);
}
- if (logtype == IPL_LOGIPF) {
- if (ipl->ipl_magic == IPL_MAGIC)
+ switch (logtype) {
+ case IPL_LOGIPF:
+ if (ipl.ipl_magic == IPL_MAGIC)
print_ipflog(log, buf, psize);
-
- } else if (logtype == IPL_LOGNAT) {
- if (ipl->ipl_magic == IPL_MAGIC_NAT)
+ break;
+ case IPL_LOGNAT:
+ if (ipl.ipl_magic == IPL_MAGIC_NAT)
print_natlog(log, buf, psize);
-
- } else if (logtype == IPL_LOGSTATE) {
- if (ipl->ipl_magic == IPL_MAGIC_STATE)
+ break;
+ case IPL_LOGSTATE:
+ if (ipl.ipl_magic == IPL_MAGIC_STATE)
print_statelog(log, buf, psize);
+ break;
}
blen -= psize;
- buf += psize;
+ buf = (const char *)buf + psize;
}
- if (bp)
- free(bp);
- return;
}
-static void print_ipflog(log, buf, blen)
-FILE *log;
-char *buf;
-int blen;
+static void
+print_ipflog(FILE *log, const void *buf, size_t blen)
{
tcphdr_t *tp;
struct icmp *ic;
@@ -1001,11 +970,11 @@
struct tm *tm;
char *t, *proto;
int i, v, lvl, res, len, off, plen, ipoff, defaction;
- ip_t *ipc, *ip;
+ const ip_t *ipc, *ip;
u_32_t *s, *d;
u_short hl, p;
- ipflog_t *ipf;
- iplog_t *ipl;
+ const ipflog_t *ipf;
+ const iplog_t *ipl;
#ifdef USE_INET6
struct ip6_ext *ehp;
u_short ehl;
@@ -1013,9 +982,9 @@
int go;
#endif
- ipl = (iplog_t *)buf;
- ipf = (ipflog_t *)((char *)buf + sizeof(*ipl));
- ip = (ip_t *)((char *)ipf + sizeof(*ipf));
+ ipl = (const iplog_t *)buf;
+ ipf = (const ipflog_t *)((const char *)buf + sizeof(*ipl));
+ ip = (const ip_t *)((const char *)ipf + sizeof(*ipf));
v = IP_V(ip);
res = (opts & OPT_RESOLVE) ? 1 : 0;
t = line;
@@ -1379,16 +1348,16 @@
}
-static void usage(prog)
-char *prog;
+static void
+usage(const char *prog)
{
fprintf(stderr, "%s: [-NFhstvxX] [-f <logfile>]\n", prog);
exit(1);
}
-static void write_pid(file)
-char *file;
+static void
+write_pid(const char *file)
{
FILE *fp = NULL;
int fd;
@@ -1407,9 +1376,8 @@
}
-static void flushlogs(file, log)
-char *file;
-FILE *log;
+static void
+flushlogs(const char *file, FILE *log)
{
int fd, flushed = 0;
@@ -1438,12 +1406,11 @@
}
-static void logopts(turnon, options)
-int turnon;
-char *options;
+static void
+logopts(int turnon, const char *options)
{
int flags = 0;
- char *s;
+ const char *s;
for (s = options; *s; s++)
{
@@ -1471,15 +1438,15 @@
}
-int main(argc, argv)
-int argc;
-char *argv[];
+int
+main(int argc, char *argv[])
{
struct stat sb;
FILE *log = stdout;
FILE *fp;
- int fd[3], doread, n, i;
- int tr, nr, regular[3], c;
+ int fd[3], doread;
+ size_t n, i, tr, nr;
+ int regular[3], c;
int fdt[3], devices = 0, make_daemon = 0;
char buf[DEFAULT_IPFLOGSIZE], *iplfile[3], *prog;
extern int optind;
Index: src/dist/ipf/tools/ipmon_y.y
===================================================================
RCS file: /cvsroot/src/dist/ipf/tools/Attic/ipmon_y.y,v
retrieving revision 1.2
diff -u -d -r1.2 ipmon_y.y
--- src/dist/ipf/tools/ipmon_y.y 15 Feb 2012 17:55:11 -0000 1.2
+++ src/dist/ipf/tools/ipmon_y.y 25 Oct 2012 02:08:38 -0000
@@ -454,7 +454,7 @@
int check_action(buf, log, opts, lvl)
-char *buf, *log;
+const char *buf, *log;
int opts, lvl;
{
ipmon_action_t *a;
----Next_Part(Thu_Oct_25_22_43_28_2012_891)----
Home |
Main Index |
Thread Index |
Old Index