On Sun, Oct 30, 2011 at 14:47 +0100, Andreas Bartelt wrote:
> Hello,
>
> while playing with rdomains I've noticed that netstat(1) only
> respects the -T flag for route listings (i.e. netstat -T 1 -rn), but
> not for open socket listings (i.e. netstat -T 1 -anf inet).
>
> There are no listening services in a freshly created rdomain (i.e.
> after "ifconfig em0 rdomain1"). However, the following commands
> currently ignore this and simply return a listing of all inet
> sockets, respectively:
> # netstat -T 0 -anf inet
> # netstat -T 1 -anf inet
>
> A quick workaround would be to forbid the usage of the -T flag
> without an -r flag.
>
> A much nicer solution would be to only show open sockets from the
> currently used rdomain or the rdomain which is explicitely specified
> via -T.
>
> Best Regards
> Andreas
>
hi,
fair enough, we should properly support -T flag.
this diff achieves that and works well in my setup.
ok?
Index: inet.c
===================================================================
RCS file: /cvs/src/usr.bin/netstat/inet.c,v
retrieving revision 1.118
diff -u -p -r1.118 inet.c
--- inet.c 5 Jul 2011 05:14:41 -0000 1.118
+++ inet.c 30 Oct 2011 17:25:49 -0000
@@ -108,7 +108,7 @@ void tcpcb_dump(u_long);
* -a (all) flag is specified.
*/
void
-protopr(u_long off, char *name, int af, u_long pcbaddr)
+protopr(u_long off, char *name, int af, u_int tableid, u_long pcbaddr)
{
struct inpcbtable table;
struct inpcb *head, *next, *prev;
@@ -168,6 +168,9 @@ protopr(u_long off, char *name, int af,
}
continue;
}
+
+ if (inpcb.inp_rtableid != tableid)
+ continue;
kread((u_long)inpcb.inp_socket, &sockb, sizeof (sockb));
if (istcp) {
Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/netstat/main.c,v
retrieving revision 1.89
diff -u -p -r1.89 main.c
--- main.c 9 Jul 2011 00:45:40 -0000 1.89
+++ main.c 30 Oct 2011 17:25:51 -0000
@@ -98,7 +98,7 @@ struct nlist nl[] = {
struct protox {
u_char pr_index; /* index into nlist of cb head */
- void (*pr_cblocks)(u_long, char *, int, u_long);
+ void (*pr_cblocks)(u_long, char *, int, u_int, u_long);
/* control blocks printing routine */
void (*pr_stats)(char *); /* statistics printing routine */
char *pr_name; /* well-known name */
@@ -136,7 +136,7 @@ struct protox *protoprotox[] = {
protox, ip6protox, NULL
};
-static void printproto(struct protox *, char *, int, u_long);
+static void printproto(struct protox *, char *, int, u_int, u_long);
static void usage(void);
static struct protox *name2protox(char *);
static struct protox *knownname(char *);
@@ -357,7 +357,7 @@ main(int argc, char *argv[])
exit(0);
}
if (pflag) {
- printproto(tp, tp->pr_name, af, pcbaddr);
+ printproto(tp, tp->pr_name, af, tableid, pcbaddr);
exit(0);
}
/*
@@ -409,17 +409,18 @@ main(int argc, char *argv[])
break;
if (tp->pr_name == 0)
continue;
- printproto(tp, p->p_name, AF_INET, pcbaddr);
+ printproto(tp, p->p_name, AF_INET, tableid, pcbaddr);
}
endprotoent();
}
if (af == PF_PFLOW || af == AF_UNSPEC) {
tp = name2protox("pflow");
- printproto(tp, tp->pr_name, af, pcbaddr);
+ printproto(tp, tp->pr_name, af, tableid, pcbaddr);
}
if (af == AF_INET6 || af == AF_UNSPEC)
for (tp = ip6protox; tp->pr_name; tp++)
- printproto(tp, tp->pr_name, AF_INET6, pcbaddr);
+ printproto(tp, tp->pr_name, AF_INET6, tableid,
+ pcbaddr);
if ((af == AF_UNIX || af == AF_UNSPEC) && !sflag)
unixpr(nl[N_UNIXSW].n_value, pcbaddr);
exit(0);
@@ -431,7 +432,8 @@ main(int argc, char *argv[])
* is not in the namelist, ignore this one.
*/
static void
-printproto(struct protox *tp, char *name, int af, u_long pcbaddr)
+printproto(struct protox *tp, char *name, int af, u_int tableid,
+ u_long pcbaddr)
{
if (sflag) {
if (tp->pr_stats != NULL)
@@ -441,7 +443,8 @@ printproto(struct protox *tp, char *name
if (tp->pr_cblocks != NULL &&
i < sizeof(nl) / sizeof(nl[0]) &&
(nl[i].n_value || af != AF_UNSPEC))
- (*tp->pr_cblocks)(nl[i].n_value, name, af, pcbaddr);
+ (*tp->pr_cblocks)(nl[i].n_value, name, af, tableid,
+ pcbaddr);
}
}
Index: netstat.h
===================================================================
RCS file: /cvs/src/usr.bin/netstat/netstat.h,v
retrieving revision 1.60
diff -u -p -r1.60 netstat.h
--- netstat.h 9 Jul 2011 00:45:40 -0000 1.60
+++ netstat.h 30 Oct 2011 17:25:51 -0000
@@ -70,7 +70,7 @@ int kread(u_long addr, void *buf, int si
char *plural(u_int64_t);
char *plurales(u_int64_t);
-void protopr(u_long, char *, int, u_long);
+void protopr(u_long, char *, int, u_int, u_long);
void tcp_stats(char *);
void udp_stats(char *);
void ip_stats(char *);