Merge buffer-printing changes from from projects/ipfw as preparation
for branch merge. Requested by: luigi
This commit is contained in:
parent
2e7d7bb294
commit
912430f6f0
@ -137,15 +137,15 @@ altq_qid_to_name(u_int32_t qid)
|
||||
}
|
||||
|
||||
void
|
||||
print_altq_cmd(ipfw_insn_altq *altqptr)
|
||||
print_altq_cmd(struct buf_pr *bp, ipfw_insn_altq *altqptr)
|
||||
{
|
||||
if (altqptr) {
|
||||
const char *qname;
|
||||
|
||||
qname = altq_qid_to_name(altqptr->qid);
|
||||
if (qname == NULL)
|
||||
printf(" altq ?<%u>", altqptr->qid);
|
||||
bprintf(bp, " altq ?<%u>", altqptr->qid);
|
||||
else
|
||||
printf(" altq %s", qname);
|
||||
bprintf(bp, " altq %s", qname);
|
||||
}
|
||||
}
|
||||
|
@ -174,48 +174,44 @@ print_header(struct ipfw_flow_id *id)
|
||||
}
|
||||
|
||||
static void
|
||||
list_flow(struct dn_flow *ni, int *print)
|
||||
list_flow(struct buf_pr *bp, struct dn_flow *ni)
|
||||
{
|
||||
char buff[255];
|
||||
struct protoent *pe = NULL;
|
||||
struct in_addr ina;
|
||||
struct ipfw_flow_id *id = &ni->fid;
|
||||
|
||||
if (*print) {
|
||||
print_header(&ni->fid);
|
||||
*print = 0;
|
||||
}
|
||||
pe = getprotobynumber(id->proto);
|
||||
/* XXX: Should check for IPv4 flows */
|
||||
printf("%3u%c", (ni->oid.id) & 0xff,
|
||||
bprintf(bp, "%3u%c", (ni->oid.id) & 0xff,
|
||||
id->extra ? '*' : ' ');
|
||||
if (!IS_IP6_FLOW_ID(id)) {
|
||||
if (pe)
|
||||
printf("%-4s ", pe->p_name);
|
||||
bprintf(bp, "%-4s ", pe->p_name);
|
||||
else
|
||||
printf("%4u ", id->proto);
|
||||
bprintf(bp, "%4u ", id->proto);
|
||||
ina.s_addr = htonl(id->src_ip);
|
||||
printf("%15s/%-5d ",
|
||||
bprintf(bp, "%15s/%-5d ",
|
||||
inet_ntoa(ina), id->src_port);
|
||||
ina.s_addr = htonl(id->dst_ip);
|
||||
printf("%15s/%-5d ",
|
||||
bprintf(bp, "%15s/%-5d ",
|
||||
inet_ntoa(ina), id->dst_port);
|
||||
} else {
|
||||
/* Print IPv6 flows */
|
||||
if (pe != NULL)
|
||||
printf("%9s ", pe->p_name);
|
||||
bprintf(bp, "%9s ", pe->p_name);
|
||||
else
|
||||
printf("%9u ", id->proto);
|
||||
printf("%7d %39s/%-5d ", id->flow_id6,
|
||||
bprintf(bp, "%9u ", id->proto);
|
||||
bprintf(bp, "%7d %39s/%-5d ", id->flow_id6,
|
||||
inet_ntop(AF_INET6, &(id->src_ip6), buff, sizeof(buff)),
|
||||
id->src_port);
|
||||
printf(" %39s/%-5d ",
|
||||
bprintf(bp, " %39s/%-5d ",
|
||||
inet_ntop(AF_INET6, &(id->dst_ip6), buff, sizeof(buff)),
|
||||
id->dst_port);
|
||||
}
|
||||
pr_u64(&ni->tot_pkts, 4);
|
||||
pr_u64(&ni->tot_bytes, 8);
|
||||
printf("%2u %4u %3u\n",
|
||||
pr_u64(bp, &ni->tot_pkts, 4);
|
||||
pr_u64(bp, &ni->tot_bytes, 8);
|
||||
bprintf(bp, "%2u %4u %3u",
|
||||
ni->length, ni->len_bytes, ni->drops);
|
||||
}
|
||||
|
||||
@ -303,8 +299,10 @@ list_pipes(struct dn_id *oid, struct dn_id *end)
|
||||
{
|
||||
char buf[160]; /* pending buffer */
|
||||
int toPrint = 1; /* print header */
|
||||
struct buf_pr bp;
|
||||
|
||||
buf[0] = '\0';
|
||||
bp_alloc(&bp, 4096);
|
||||
for (; oid != end; oid = O_NEXT(oid, oid->len)) {
|
||||
if (oid->len < sizeof(*oid))
|
||||
errx(1, "invalid oid len %d\n", oid->len);
|
||||
@ -346,7 +344,12 @@ list_pipes(struct dn_id *oid, struct dn_id *end)
|
||||
break;
|
||||
|
||||
case DN_FLOW:
|
||||
list_flow((struct dn_flow *)oid, &toPrint);
|
||||
if (toPrint != 0) {
|
||||
print_header(&((struct dn_flow *)oid)->fid);
|
||||
toPrint = 0;
|
||||
}
|
||||
list_flow(&bp, (struct dn_flow *)oid);
|
||||
printf("%s\n", bp.buf);
|
||||
break;
|
||||
|
||||
case DN_LINK: {
|
||||
@ -384,6 +387,8 @@ list_pipes(struct dn_id *oid, struct dn_id *end)
|
||||
}
|
||||
flush_buf(buf); // XXX does it really go here ?
|
||||
}
|
||||
|
||||
bp_free(&bp);
|
||||
}
|
||||
|
||||
/*
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -71,6 +71,8 @@ struct _s_x {
|
||||
int x;
|
||||
};
|
||||
|
||||
extern struct _s_x f_ipdscp[];
|
||||
|
||||
enum tokens {
|
||||
TOK_NULL=0,
|
||||
|
||||
@ -213,7 +215,19 @@ enum tokens {
|
||||
#define NEED(_p, msg) {if (!_p) errx(EX_USAGE, msg);}
|
||||
#define NEED1(msg) {if (!(*av)) errx(EX_USAGE, msg);}
|
||||
|
||||
int pr_u64(uint64_t *pd, int width);
|
||||
struct buf_pr {
|
||||
char *buf; /* allocated buffer */
|
||||
char *ptr; /* current pointer */
|
||||
size_t size; /* total buffer size */
|
||||
size_t avail; /* available storage */
|
||||
size_t needed; /* length needed */
|
||||
};
|
||||
|
||||
int pr_u64(struct buf_pr *bp, uint64_t *pd, int width);
|
||||
int bp_alloc(struct buf_pr *b, size_t size);
|
||||
void bp_free(struct buf_pr *b);
|
||||
int bprintf(struct buf_pr *b, char *format, ...);
|
||||
|
||||
|
||||
/* memory allocation support */
|
||||
void *safe_calloc(size_t number, size_t size);
|
||||
@ -273,7 +287,7 @@ void ipfw_list(int ac, char *av[], int show_counters);
|
||||
/* altq.c */
|
||||
void altq_set_enabled(int enabled);
|
||||
u_int32_t altq_name_to_qid(const char *name);
|
||||
void print_altq_cmd(struct _ipfw_insn_altq *altqptr);
|
||||
void print_altq_cmd(struct buf_pr *bp, struct _ipfw_insn_altq *altqptr);
|
||||
#else
|
||||
#define NO_ALTQ
|
||||
#endif
|
||||
@ -285,10 +299,10 @@ int ipfw_delete_pipe(int pipe_or_queue, int n);
|
||||
|
||||
/* ipv6.c */
|
||||
void print_unreach6_code(uint16_t code);
|
||||
void print_ip6(struct _ipfw_insn_ip6 *cmd, char const *s);
|
||||
void print_flow6id(struct _ipfw_insn_u32 *cmd);
|
||||
void print_icmp6types(struct _ipfw_insn_u32 *cmd);
|
||||
void print_ext6hdr(struct _ipfw_insn *cmd );
|
||||
void print_ip6(struct buf_pr *bp, struct _ipfw_insn_ip6 *cmd, char const *s);
|
||||
void print_flow6id(struct buf_pr *bp, struct _ipfw_insn_u32 *cmd);
|
||||
void print_icmp6types(struct buf_pr *bp, struct _ipfw_insn_u32 *cmd);
|
||||
void print_ext6hdr(struct buf_pr *bp, struct _ipfw_insn *cmd );
|
||||
|
||||
struct _ipfw_insn *add_srcip6(struct _ipfw_insn *cmd, char *av, int cblen);
|
||||
struct _ipfw_insn *add_dstip6(struct _ipfw_insn *cmd, char *av, int cblen);
|
||||
|
@ -85,21 +85,21 @@ print_unreach6_code(uint16_t code)
|
||||
* Print the ip address contained in a command.
|
||||
*/
|
||||
void
|
||||
print_ip6(ipfw_insn_ip6 *cmd, char const *s)
|
||||
print_ip6(struct buf_pr *bp, ipfw_insn_ip6 *cmd, char const *s)
|
||||
{
|
||||
struct hostent *he = NULL;
|
||||
int len = F_LEN((ipfw_insn *) cmd) - 1;
|
||||
struct in6_addr *a = &(cmd->addr6);
|
||||
char trad[255];
|
||||
|
||||
printf("%s%s ", cmd->o.len & F_NOT ? " not": "", s);
|
||||
bprintf(bp, "%s%s ", cmd->o.len & F_NOT ? " not": "", s);
|
||||
|
||||
if (cmd->o.opcode == O_IP6_SRC_ME || cmd->o.opcode == O_IP6_DST_ME) {
|
||||
printf("me6");
|
||||
bprintf(bp, "me6");
|
||||
return;
|
||||
}
|
||||
if (cmd->o.opcode == O_IP6) {
|
||||
printf(" ip6");
|
||||
bprintf(bp, " ip6");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -117,21 +117,21 @@ print_ip6(ipfw_insn_ip6 *cmd, char const *s)
|
||||
if (mb == 128 && co.do_resolv)
|
||||
he = gethostbyaddr((char *)a, sizeof(*a), AF_INET6);
|
||||
if (he != NULL) /* resolved to name */
|
||||
printf("%s", he->h_name);
|
||||
bprintf(bp, "%s", he->h_name);
|
||||
else if (mb == 0) /* any */
|
||||
printf("any");
|
||||
bprintf(bp, "any");
|
||||
else { /* numeric IP followed by some kind of mask */
|
||||
if (inet_ntop(AF_INET6, a, trad, sizeof( trad ) ) == NULL)
|
||||
printf("Error ntop in print_ip6\n");
|
||||
printf("%s", trad );
|
||||
bprintf(bp, "Error ntop in print_ip6\n");
|
||||
bprintf(bp, "%s", trad );
|
||||
if (mb < 0) /* XXX not really legal... */
|
||||
printf(":%s",
|
||||
bprintf(bp, ":%s",
|
||||
inet_ntop(AF_INET6, &a[1], trad, sizeof(trad)));
|
||||
else if (mb < 128)
|
||||
printf("/%d", mb);
|
||||
bprintf(bp, "/%d", mb);
|
||||
}
|
||||
if (len > 2)
|
||||
printf(",");
|
||||
bprintf(bp, ",");
|
||||
}
|
||||
}
|
||||
|
||||
@ -165,32 +165,32 @@ fill_icmp6types(ipfw_insn_icmp6 *cmd, char *av, int cblen)
|
||||
|
||||
|
||||
void
|
||||
print_icmp6types(ipfw_insn_u32 *cmd)
|
||||
print_icmp6types(struct buf_pr *bp, ipfw_insn_u32 *cmd)
|
||||
{
|
||||
int i, j;
|
||||
char sep= ' ';
|
||||
|
||||
printf(" ip6 icmp6types");
|
||||
bprintf(bp, " ip6 icmp6types");
|
||||
for (i = 0; i < 7; i++)
|
||||
for (j=0; j < 32; ++j) {
|
||||
if ( (cmd->d[i] & (1 << (j))) == 0)
|
||||
continue;
|
||||
printf("%c%d", sep, (i*32 + j));
|
||||
bprintf(bp, "%c%d", sep, (i*32 + j));
|
||||
sep = ',';
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
print_flow6id( ipfw_insn_u32 *cmd)
|
||||
print_flow6id(struct buf_pr *bp, ipfw_insn_u32 *cmd)
|
||||
{
|
||||
uint16_t i, limit = cmd->o.arg1;
|
||||
char sep = ',';
|
||||
|
||||
printf(" flow-id ");
|
||||
bprintf(bp, " flow-id ");
|
||||
for( i=0; i < limit; ++i) {
|
||||
if (i == limit - 1)
|
||||
sep = ' ';
|
||||
printf("%d%c", cmd->d[i], sep);
|
||||
bprintf(bp, "%d%c", cmd->d[i], sep);
|
||||
}
|
||||
}
|
||||
|
||||
@ -265,41 +265,41 @@ fill_ext6hdr( ipfw_insn *cmd, char *av)
|
||||
}
|
||||
|
||||
void
|
||||
print_ext6hdr( ipfw_insn *cmd )
|
||||
print_ext6hdr(struct buf_pr *bp, ipfw_insn *cmd )
|
||||
{
|
||||
char sep = ' ';
|
||||
|
||||
printf(" extension header:");
|
||||
bprintf(bp, " extension header:");
|
||||
if (cmd->arg1 & EXT_FRAGMENT ) {
|
||||
printf("%cfragmentation", sep);
|
||||
bprintf(bp, "%cfragmentation", sep);
|
||||
sep = ',';
|
||||
}
|
||||
if (cmd->arg1 & EXT_HOPOPTS ) {
|
||||
printf("%chop options", sep);
|
||||
bprintf(bp, "%chop options", sep);
|
||||
sep = ',';
|
||||
}
|
||||
if (cmd->arg1 & EXT_ROUTING ) {
|
||||
printf("%crouting options", sep);
|
||||
bprintf(bp, "%crouting options", sep);
|
||||
sep = ',';
|
||||
}
|
||||
if (cmd->arg1 & EXT_RTHDR0 ) {
|
||||
printf("%crthdr0", sep);
|
||||
bprintf(bp, "%crthdr0", sep);
|
||||
sep = ',';
|
||||
}
|
||||
if (cmd->arg1 & EXT_RTHDR2 ) {
|
||||
printf("%crthdr2", sep);
|
||||
bprintf(bp, "%crthdr2", sep);
|
||||
sep = ',';
|
||||
}
|
||||
if (cmd->arg1 & EXT_DSTOPTS ) {
|
||||
printf("%cdestination options", sep);
|
||||
bprintf(bp, "%cdestination options", sep);
|
||||
sep = ',';
|
||||
}
|
||||
if (cmd->arg1 & EXT_AH ) {
|
||||
printf("%cauthentication header", sep);
|
||||
bprintf(bp, "%cauthentication header", sep);
|
||||
sep = ',';
|
||||
}
|
||||
if (cmd->arg1 & EXT_ESP ) {
|
||||
printf("%cencapsulated security payload", sep);
|
||||
bprintf(bp, "%cencapsulated security payload", sep);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user