Date: Sun, 16 May 2010 12:59:55 GMT From: Gabor Pali <pgj@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 178324 for review Message-ID: <201005161259.o4GCxtVa024258@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@178324?ac=10 Change 178324 by pgj@csupor on 2010/05/16 12:59:01 - Simplify code of accessors by introducing macros - Fixing up discrepancies in function names - Chasing the changes in netstat(1) - Bump copyright year where applicable Affected files ... .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.h#68 edit .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_if.c#7 edit .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_internal.h#66 edit .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_mroute.c#3 edit .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_route.c#8 edit .. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_util.c#75 edit .. //depot/projects/soc2009/pgj_libstat/src/usr.bin/netstat/mbuf.c#6 edit Differences ... ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.h#68 (text+ko) ==== @@ -363,7 +363,7 @@ /* "Memory buffers" */ struct mbuf_type *netstat_mbt_alloc(void); void netstat_mbt_free(struct mbuf_type *); -int netstat_mbt_geterror(const struct mbuf_type *); +int netstat_mbt_get_error(const struct mbuf_type *); int netstat_mbuf(const struct session_type *, struct mbuf_type *stats, int flags); ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_if.c#7 (text+ko) ==== @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009 Gabor Pali + * Copyright (c) 2009, 2010 Gabor Pali * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -155,9 +155,9 @@ if (domain != PF_UNSPEC && domain != ifmultiaddr.ifma_addr->sa_family) continue; - if (itp->it_maddrcnt >= IFTYPE_MAXADDRCNT) + if (itp->it_mcast_addrcnt >= IFTYPE_MAXADDRCNT) continue; - itp->it_maddress[itp->it_maddrcnt++] = + itp->it_maddress[itp->it_mcast_addrcnt++] = extract_if_address(NETSTAT_IF_IFMULTIADDR, &ifmultiaddr, ifmultiaddr.ifma_addr, itp); } ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_internal.h#66 (text+ko) ==== @@ -274,7 +274,7 @@ /* Multicast addresses. */ struct intfaddr_type *it_maddress[IFTYPE_MAXADDRCNT]; - int it_maddrcnt; + int it_mcast_addrcnt; TAILQ_ENTRY(interface_type) it_list; }; @@ -455,7 +455,7 @@ int rmt_bit; u_int64_t rmt_address; u_int64_t rmt_refs; - struct routeaddr_type *rmt_mask; + struct routeaddr_type *rmt_netmask; }; struct routenode_type { @@ -466,7 +466,7 @@ u_int64_t rnt_right; u_int64_t rnt_key; u_int64_t rnt_dupedkey; - struct routeaddr_type *rnt_mask; + struct routeaddr_type *rnt_netmask; int rnt_mkcnt; struct routemask_type *rnt_mklist; }; @@ -507,8 +507,8 @@ u_int32_t mit_limit; /* threshold/rate limit */ struct routeaddr_type *mit_address; struct routeaddr_type *mit_remote_address; - u_int64_t mit_pkts_in; - u_int64_t mit_pkts_out; + u_int64_t mit_packets_in; + u_int64_t mit_packets_out; u_int64_t mit_bytes_in; u_int64_t mit_bytes_out; char mit_ifname[MIFTYPE_MAXNAME]; @@ -533,9 +533,9 @@ struct mroute_type { struct routeaddr_type *mrt_origin; struct routeaddr_type *mrt_group; - u_int64_t mrt_pkt_cnt; - u_int64_t mrt_byte_cnt; - u_int64_t mrt_nstall; + u_int64_t mrt_packets; + u_int64_t mrt_bytes; + u_int64_t mrt_waitings; u_int32_t mrt_parent; u_int8_t mrt_ttls[MRTTYPE_MAXVIFS]; struct if_set mrt_ifset; ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_mroute.c#3 (text+ko) ==== @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009 Gabor Pali + * Copyright (c) 2009, 2010 Gabor Pali * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -396,8 +396,8 @@ sa_in.sin_addr = v->v_rmt_addr; mitp->mit_remote_address = extract_address(&sa_in, NULL, 0); } - mitp->mit_pkts_in = v->v_pkt_in; - mitp->mit_pkts_out = v->v_pkt_out; + mitp->mit_packets_in = v->v_pkt_in; + mitp->mit_packets_out = v->v_pkt_out; mitp->mit_bytes_in = v->v_bytes_in; mitp->mit_bytes_out = v->v_bytes_out; if (v->v_flags & VIFF_REGISTER) @@ -432,8 +432,8 @@ sa_in.sin_addr.s_addr = v->vd_rmt_addr; mitp->mit_remote_address = extract_address(&sa_in, NULL, 0); } - mitp->mit_pkts_in = v->vd_pkt_in; - mitp->mit_pkts_out = v->vd_pkt_out; + mitp->mit_packets_in = v->vd_pkt_in; + mitp->mit_packets_out = v->vd_pkt_out; mitp->mit_bytes_in = v->vd_bytes_in; mitp->mit_bytes_out = v->vd_bytes_out; if (v->vd_flags & VIFF_REGISTER) @@ -463,8 +463,8 @@ CNV_FLAG(MIFF_REGISTER, NETSTAT_MIF_REGISTER); mitp->mit_limit = m->m6_rate_limit; mitp->mit_address = extract_address(&sa_in6, NULL, 0); - mitp->mit_pkts_in = m->m6_pkt_in; - mitp->mit_pkts_out = m->m6_pkt_out; + mitp->mit_packets_in = m->m6_pkt_in; + mitp->mit_packets_out = m->m6_pkt_out; if (m->m6_flags & MIFF_REGISTER) strlcpy(mitp->mit_ifname, "reg0", sizeof(mitp->mit_ifname)); else if (m->m6_ifp != NULL) @@ -491,8 +491,8 @@ CNV_FLAG(MIFF_REGISTER, NETSTAT_MIF_REGISTER); mitp->mit_limit = m->md_rate_limit; mitp->mit_address = extract_address(&sa_in6, NULL, 0); - mitp->mit_pkts_in = m->md_pkt_in; - mitp->mit_pkts_out = m->md_pkt_out; + mitp->mit_packets_in = m->md_pkt_in; + mitp->mit_packets_out = m->md_pkt_out; if (m->md_flags & MIFF_REGISTER) strlcpy(mitp->mit_ifname, "reg0", sizeof(mitp->mit_ifname)); else @@ -777,9 +777,9 @@ mrtp->mrt_origin = extract_address(&sa_in, NULL, 0); sa_in.sin_addr = m->mfc_mcastgrp; mrtp->mrt_group = extract_address(&sa_in, NULL, 0); - mrtp->mrt_pkt_cnt = m->mfc_pkt_cnt; - mrtp->mrt_byte_cnt = m->mfc_byte_cnt; - mrtp->mrt_nstall = m->mfc_nstall; + mrtp->mrt_packets = m->mfc_pkt_cnt; + mrtp->mrt_bytes = m->mfc_byte_cnt; + mrtp->mrt_waitings = m->mfc_nstall; mrtp->mrt_parent = m->mfc_parent; for (i = 0; i < MAXVIFS; i++) mrtp->mrt_ttls[i] = m->mfc_ttls[i]; @@ -798,9 +798,9 @@ mrtp->mrt_origin = extract_address(&sa_in, NULL, 0); sa_in.sin_addr.s_addr = md->md_mcastgrp; mrtp->mrt_group = extract_address(&sa_in, NULL, 0); - mrtp->mrt_pkt_cnt = md->md_pkt_cnt; - mrtp->mrt_byte_cnt = md->md_byte_cnt; - mrtp->mrt_nstall = md->md_nstall; + mrtp->mrt_packets = md->md_pkt_cnt; + mrtp->mrt_bytes = md->md_byte_cnt; + mrtp->mrt_waitings = md->md_nstall; mrtp->mrt_parent = md->md_parent; bcopy(md->md_ttls, mrtp->mrt_ttls, sizeof(md->md_ttls)); } @@ -811,9 +811,9 @@ { mrtp->mrt_origin = extract_address(&m->mf6c_origin, NULL, 0); mrtp->mrt_group = extract_address(&m->mf6c_mcastgrp, NULL, 0); - mrtp->mrt_pkt_cnt = m->mf6c_pkt_cnt; - mrtp->mrt_byte_cnt = m->mf6c_byte_cnt; - mrtp->mrt_nstall = nstall; + mrtp->mrt_packets = m->mf6c_pkt_cnt; + mrtp->mrt_bytes = m->mf6c_byte_cnt; + mrtp->mrt_waitings = nstall; mrtp->mrt_parent = m->mf6c_parent; mrtp->mrt_ifset = m->mf6c_ifset; } @@ -831,9 +831,9 @@ mrtp->mrt_origin = extract_address(&sa_in6, NULL, 0); sa_in6.sin6_addr = *((struct in6_addr *)md->md_mcastgrp); mrtp->mrt_group = extract_address(&sa_in6, NULL, 0); - mrtp->mrt_pkt_cnt = md->md_pkt_cnt; - mrtp->mrt_byte_cnt = md->md_byte_cnt; - mrtp->mrt_nstall = md->md_nstall; + mrtp->mrt_packets = md->md_pkt_cnt; + mrtp->mrt_bytes = md->md_byte_cnt; + mrtp->mrt_waitings = md->md_nstall; mrtp->mrt_parent = md->md_parent; bcopy(&md->md_ifs_bits, &mrtp->mrt_ifset, sizeof(md->md_ifs_bits)); } ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_route.c#8 (text+ko) ==== @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009 Gabor Pali + * Copyright (c) 2009, 2010 Gabor Pali * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -249,7 +249,7 @@ rtp = _netstat_rt_allocate(list); PTR2INT(rtp->rt_node.rnt_address, rn); - rtp->rt_node.rnt_mask = + rtp->rt_node.rnt_netmask = extract_address(rnode->rn_mask, NULL, 0); extract_rtentry_data(&rtentry, rtp); extract_node(rnode, &rtp->rt_node, cnt); @@ -554,7 +554,7 @@ rnp->rnt_mklist[i].rmt_bit = rmp->rm_bit; rnp->rnt_mklist[i].rmt_refs = rmp->rm_refs; rnode = rmp->rm_leaf; - rnp->rnt_mklist[i].rmt_mask = + rnp->rnt_mklist[i].rmt_netmask = (rmp->rm_flags & RNF_NORMAL && rnode->rn_mask != NULL) ? extract_address(rnode->rn_mask, NULL, 0) : extract_address(rmp->rm_mask, NULL, 0); ==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_util.c#75 (text+ko) ==== @@ -451,109 +451,49 @@ free(satp); } -/* Accessor functions. */ -int -netstat_st_get_family(const struct socket_type *stp) -{ - return (stp->st_family); -} -int -netstat_st_get_protocol(const struct socket_type *stp) -{ - return (stp->st_protocol); -} +/* Accessor macros. */ -const char * -netstat_st_get_name(const struct socket_type *stp) -{ - return (stp->st_name); +#define ACCESSOR(returns, tp, type, field) \ +returns \ +netstat_##tp##t_get_##field(const struct type##_type *a) \ +{ \ + return (a->tp##t_##field); \ } -const char * -netstat_st_get_extname(const struct socket_type *stp) -{ - return (stp->st_extname); +#define ACCESSORP(returns, tp, type, field) \ +returns \ +netstat_##tp##t_get_##field(const struct type##_type *a) \ +{ \ + return (&a->tp##t_##field); \ } -const struct sockbuf_type * -netstat_st_get_snd(const struct socket_type *stp) -{ - return (&stp->st_snd); -} -const struct sockbuf_type * -netstat_st_get_rcv(const struct socket_type *stp) -{ - return (&stp->st_rcv); -} +/* Accessor functions. */ -u_int16_t -netstat_st_get_qlen(const struct socket_type *stp) -{ - return (stp->st_qlen); -} +#define SOCKET_ACC(returns, field) \ + ACCESSOR(returns, s, socket, field) -u_int16_t -netstat_st_get_incqlen(const struct socket_type *stp) -{ - return (stp->st_incqlen); -} +#define SOCKET_ACCP(returns, field) \ + ACCESSORP(returns, s, socket, field) -u_int16_t -netstat_st_get_qlimit(const struct socket_type *stp) -{ - return (stp->st_qlimit); -} - -u_int64_t -netstat_st_get_pcb(const struct socket_type *stp) -{ - return (stp->st_pcb); -} - -u_int64_t -netstat_st_get_vnode(const struct socket_type *stp) -{ - return (stp->st_vnode); -} - -u_int64_t -netstat_st_get_conn(const struct socket_type *stp) -{ - return (stp->st_conn); -} - -u_int64_t -netstat_st_get_refs(const struct socket_type *stp) -{ - return (stp->st_refs); -} - -u_int64_t -netstat_st_get_reflink(const struct socket_type *stp) -{ - return (stp->st_reflink); -} - -const char * -netstat_st_get_tcpstate(const struct socket_type *stp) -{ - return (stp->st_tcpstate); -} - -enum tcp_state -netstat_st_get_tcps(const struct socket_type *stp) -{ - return (stp->st_tcps); -} - -int -netstat_st_get_addrcnt(const struct socket_type *stp) -{ - - return (stp->st_addrcnt); -} +SOCKET_ACC (int, family); +SOCKET_ACC (int, protocol); +SOCKET_ACC (const char *, name); +SOCKET_ACC (const char *, extname); +SOCKET_ACCP(const struct sockbuf_type *, snd); +SOCKET_ACCP(const struct sockbuf_type *, rcv); +SOCKET_ACC (u_int16_t, qlen); +SOCKET_ACC (u_int16_t, incqlen); +SOCKET_ACC (u_int16_t, qlimit); +SOCKET_ACC (u_int64_t, pcb); +SOCKET_ACC (u_int64_t, vnode); +SOCKET_ACC (u_int64_t, conn); +SOCKET_ACC (u_int64_t, refs); +SOCKET_ACC (u_int64_t, reflink); +SOCKET_ACC (const char *, tcpstate); +SOCKET_ACC (enum tcp_state, tcps); +SOCKET_ACC (int, addrcnt); struct sockaddr_type * netstat_st_get_address(const struct socket_type *stp, @@ -566,6 +506,15 @@ return (NULL); } +#undef SOCKET_ACC +#undef SOCKET_ACCP + +#define SOCKADDR_ACC(returns, field) \ + ACCESSOR(returns, sa, sockaddr, field) + +SOCKADDR_ACC(const char *, numeric); +SOCKADDR_ACC(u_int16_t, port); + const char * netstat_sat_get_name(struct sockaddr_type *satp) { @@ -575,12 +524,6 @@ return (satp->sat_name); } -const char * -netstat_sat_get_numeric(const struct sockaddr_type *satp) -{ - return (satp->sat_numeric); -} - int netstat_sat_get_address(const struct sockaddr_type *satp, char *addr, int size) { @@ -593,12 +536,6 @@ return (0); } -u_int16_t -netstat_sat_get_port(const struct sockaddr_type *satp) -{ - return (satp->sat_port); -} - const char * netstat_sat_get_portname(struct sockaddr_type *satp) { @@ -608,48 +545,21 @@ return (satp->sat_portname); } -u_int32_t -netstat_sbt_get_cc(const struct sockbuf_type *sbtp) -{ - return (sbtp->sbt_cc); -} +#undef SOCKADDR_ACC -u_int32_t -netstat_sbt_get_hiwat(const struct sockbuf_type *sbtp) -{ - return (sbtp->sbt_hiwat); -} +#define SOCKBUF_ACC(returns, field) \ + ACCESSOR(returns, sb, sockbuf, field) -u_int32_t -netstat_sbt_get_lowat(const struct sockbuf_type *sbtp) -{ - return (sbtp->sbt_lowat); -} +SOCKBUF_ACC(u_int32_t, cc); +SOCKBUF_ACC(u_int32_t, hiwat); +SOCKBUF_ACC(u_int32_t, lowat); +SOCKBUF_ACC(u_int32_t, mbcnt); +SOCKBUF_ACC(u_int32_t, mcnt); +SOCKBUF_ACC(u_int32_t, ccnt); +SOCKBUF_ACC(u_int32_t, mbmax); -u_int32_t -netstat_sbt_get_mbcnt(const struct sockbuf_type *sbtp) -{ - return (sbtp->sbt_mbcnt); -} - -u_int32_t -netstat_sbt_get_mcnt(const struct sockbuf_type *sbtp) -{ - return (sbtp->sbt_mcnt); -} - -u_int32_t -netstat_sbt_get_ccnt(const struct sockbuf_type *sbtp) -{ - return (sbtp->sbt_ccnt); -} +#undef SOCKBUF_ACC -u_int32_t -netstat_sbt_get_mbmax(const struct sockbuf_type *sbtp) -{ - return (sbtp->sbt_mbmax); -} - /* Memory buffer type */ struct mbuf_type * netstat_mbt_alloc(void) @@ -668,151 +578,48 @@ free(mbtp); } -int -netstat_mbt_geterror(const struct mbuf_type *mbtp) -{ - return (mbtp->mbt_error); -} +#define MBUF_ACC(returns, field) \ + ACCESSOR(returns, mb, mbuf, field) -const struct buffer_type * -netstat_mbt_get_mbuf(const struct mbuf_type *mbtp) -{ - return (&mbtp->mbt_mbuf); -} +#define MBUF_ACCP(returns, field) \ + ACCESSORP(returns, mb, mbuf, field) -const struct buffer_type * -netstat_mbt_get_cluster(const struct mbuf_type *mbtp) -{ - return (&mbtp->mbt_cluster); -} +MBUF_ACC (int, error); +MBUF_ACCP(const struct buffer_type *, mbuf); +MBUF_ACCP(const struct buffer_type *, cluster); +MBUF_ACCP(const struct buffer_type *, packet); +MBUF_ACCP(const struct buffer_type *, tag); +MBUF_ACCP(const struct buffer_type *, jumbop); +MBUF_ACCP(const struct buffer_type *, jumbo9); +MBUF_ACCP(const struct buffer_type *, jumbo16); +MBUF_ACC (u_int64_t, bytes_inuse); +MBUF_ACC (u_int64_t, bytes_incache); +MBUF_ACC (u_int64_t, bytes_total); +MBUF_ACC (u_int64_t, drain); +MBUF_ACC (u_int64_t, sf_bufs); +MBUF_ACC (u_int64_t, sf_bufs_peak); +MBUF_ACC (u_int64_t, sf_bufs_inuse); +MBUF_ACC (u_int64_t, sf_iocnt); +MBUF_ACC (u_int64_t, sf_allocfail); +MBUF_ACC (u_int64_t, sf_allocwait); -const struct buffer_type * -netstat_mbt_get_packet(const struct mbuf_type *mbtp) -{ - return (&mbtp->mbt_packet); -} - -const struct buffer_type * -netstat_mbt_get_tag(const struct mbuf_type *mbtp) -{ - return (&mbtp->mbt_tag); -} - -const struct buffer_type * -netstat_mbt_get_jumbop(const struct mbuf_type *mbtp) -{ - return (&mbtp->mbt_jumbop); -} - -const struct buffer_type * -netstat_mbt_get_jumbo9(const struct mbuf_type *mbtp) -{ - return (&mbtp->mbt_jumbo9); -} - -const struct buffer_type * -netstat_mbt_get_jumbo16(const struct mbuf_type *mbtp) -{ - return (&mbtp->mbt_jumbo16); -} - -u_int64_t -netstat_mbt_get_bytes_inuse(const struct mbuf_type *mbtp) -{ - return (mbtp->mbt_bytes_inuse); -} - -u_int64_t -netstat_mbt_get_bytes_incache(const struct mbuf_type *mbtp) -{ - return (mbtp->mbt_bytes_incache); -} - -u_int64_t -netstat_mbt_get_bytes_total(const struct mbuf_type *mbtp) -{ - return (mbtp->mbt_bytes_total); -} - -u_int64_t -netstat_mbt_get_drain(const struct mbuf_type *mbtp) -{ - return (mbtp->mbt_drain); -} - -u_int64_t -netstat_mbt_get_sf_bufs(const struct mbuf_type *mbtp) -{ - return (mbtp->mbt_sf_bufs); -} - -u_int64_t -netstat_mbt_get_sf_bufs_peak(const struct mbuf_type *mbtp) -{ - return (mbtp->mbt_sf_bufs_peak); -} +#undef MBUF_ACC +#undef MBUF_ACCP -u_int64_t -netstat_mbt_get_sf_bufs_inuse(const struct mbuf_type *mbtp) -{ - return (mbtp->mbt_sf_bufs_inuse); -} - -u_int64_t -netstat_mbt_get_sf_iocnt(const struct mbuf_type *mbtp) -{ - return (mbtp->mbt_sf_iocnt); -} - -u_int64_t -netstat_mbt_get_sf_allocfail(const struct mbuf_type *mbtp) -{ - return (mbtp->mbt_sf_allocfail); -} - -u_int64_t -netstat_mbt_get_sf_allocwait(const struct mbuf_type *mbtp) -{ - return (mbtp->mbt_sf_allocwait); -} - /* Buffer type */ -u_int64_t -netstat_bt_get_count(const struct buffer_type *btp) -{ - return (btp->bt_count); -} -u_int64_t -netstat_bt_get_bytes(const struct buffer_type *btp) -{ - return (btp->bt_bytes); -} +#define BUFFER_ACC(returns, field) \ + ACCESSOR(returns, b, buffer, field) -u_int64_t -netstat_bt_get_free(const struct buffer_type *btp) -{ - return (btp->bt_free); -} +BUFFER_ACC(u_int64_t, count); +BUFFER_ACC(u_int64_t, bytes); +BUFFER_ACC(u_int64_t, free); +BUFFER_ACC(u_int64_t, failures); +BUFFER_ACC(u_int64_t, size); +BUFFER_ACC(u_int64_t, limit); -u_int64_t -netstat_bt_get_failures(const struct buffer_type *btp) -{ - return (btp->bt_failures); -} +#undef BUFFER_ACC -u_int64_t -netstat_bt_get_size(const struct buffer_type *btp) -{ - return (btp->bt_size); -} - -u_int64_t -netstat_bt_get_limit(const struct buffer_type *btp) -{ - return (btp->bt_limit); -} - struct interface_type * _netstat_it_allocate(struct interface_type_list *list, int type, int physical, const char *name) @@ -957,54 +764,23 @@ free(iatp); } -const char * -netstat_it_get_name(const struct interface_type *itp) -{ - return (itp->it_name); -} -u_int64_t -netstat_it_get_mtu(const struct interface_type *itp) -{ - return (itp->it_mtu); -} +#define INTERFACE_ACC(returns, field) \ + ACCESSOR(returns, i, interface, field) -int -netstat_it_get_flags(const struct interface_type *itp) -{ - return (itp->it_flags); -} +#define INTERFACE_ACCP(returns, field) \ + ACCESSORP(returns, i, interface, field) -u_int64_t -netstat_it_get_collisions(const struct interface_type *itp) -{ - return (itp->it_collisions); -} - -u_int64_t -netstat_it_get_drops(const struct interface_type *itp) -{ - return (itp->it_drops); -} - -const struct face_type * -netstat_it_get_in(const struct interface_type *itp) -{ - return (&itp->it_in); -} +INTERFACE_ACC (const char *, name); +INTERFACE_ACC (u_int64_t, mtu); +INTERFACE_ACC (int, flags); +INTERFACE_ACC (u_int64_t, collisions); +INTERFACE_ACC (u_int64_t, drops); +INTERFACE_ACCP(const struct face_type *, in); +INTERFACE_ACCP(const struct face_type *, out); +INTERFACE_ACC (int, addrcnt); +INTERFACE_ACC (int, mcast_addrcnt); -const struct face_type * -netstat_it_get_out(const struct interface_type *itp) -{ - return (&itp->it_out); -} - -int -netstat_it_get_addrcnt(const struct interface_type *itp) -{ - return (itp->it_addrcnt); -} - const struct intfaddr_type * netstat_it_get_address(const struct interface_type *itp, int index) { @@ -1013,55 +789,41 @@ return (NULL); } -int -netstat_it_get_mcast_addrcnt(const struct interface_type *itp) -{ - return (itp->it_maddrcnt); -} - const struct intfaddr_type * netstat_it_get_mcast_address(const struct interface_type *itp, int index) { - if (0 <= index && index < itp->it_maddrcnt) + if (0 <= index && index < itp->it_mcast_addrcnt) return (itp->it_maddress[index]); return (NULL); } -u_int64_t -netstat_ft_get_packets(const struct face_type *ftp) -{ - return (ftp->ft_packets); -} +#undef INTERFACE_ACC +#undef INTERFACE_ACCP + +#define FACE_ACC(returns, field) \ + ACCESSOR(returns, f, face, field) -u_int64_t -netstat_ft_get_bytes(const struct face_type *ftp) -{ - return (ftp->ft_bytes); -} +FACE_ACC(u_int64_t, packets); +FACE_ACC(u_int64_t, bytes); +FACE_ACC(u_int64_t, mcasts); +FACE_ACC(u_int64_t, errors); +FACE_ACC(u_int64_t, drops); -u_int64_t -netstat_ft_get_mcasts(const struct face_type *ftp) -{ - return (ftp->ft_mcasts); -} +#undef FACE_ACC -u_int64_t -netstat_ft_get_errors(const struct face_type *ftp) -{ - return (ftp->ft_errors); -} +#define INTFADDR_ACC(returns, field) \ + ACCESSOR(returns, ia, intfaddr, field) -u_int64_t -netstat_ft_get_drops(const struct face_type *ftp) -{ - return (ftp->ft_drops); -} +#define INTFADDR_ACCP(returns, field) \ + ACCESSORP(returns, ia, intfaddr, field) -int -netstat_iat_get_family(const struct intfaddr_type *iatp) -{ - return (iatp->iat_family); -} +INTFADDR_ACC(int, family); +INTFADDR_ACC(enum intfaddr_layer, layer); +INTFADDR_ACC(u_int64_t, ipackets); +INTFADDR_ACC(u_int64_t, ibytes); +INTFADDR_ACC(u_int64_t, opackets); +INTFADDR_ACC(u_int64_t, obytes); +INTFADDR_ACC(u_int32_t, refcount); const char * netstat_iat_get_address(const struct intfaddr_type *iatp, int numeric) @@ -1079,42 +841,9 @@ return (iatp->iat_network); } -enum intfaddr_layer -netstat_iat_get_layer(const struct intfaddr_type *iatp) -{ - return (iatp->iat_layer); -} - -u_int64_t -netstat_iat_get_ipackets(const struct intfaddr_type *iatp) -{ - return (iatp->iat_ipackets); -} +#undef INTFADDR_ACC +#undef INTFADDR_ACCP -u_int64_t -netstat_iat_get_ibytes(const struct intfaddr_type *iatp) -{ - return (iatp->iat_ibytes); -} - -u_int64_t -netstat_iat_get_opackets(const struct intfaddr_type *iatp) -{ - return (iatp->iat_opackets); -} - -u_int64_t -netstat_iat_get_obytes(const struct intfaddr_type *iatp) -{ - return (iatp->iat_obytes); -} - -u_int32_t -netstat_iat_get_refcount(const struct intfaddr_type *iatp) -{ - return (iatp->iat_refcount); -} - void _netstat_bptl_empty(struct bpf_type_list *list) { @@ -1224,66 +953,22 @@ free(btp); } -int -netstat_bpt_get_flags(const struct bpf_type *btp) -{ - return (btp->bpt_flags); -} +#define BPF_ACC(returns, field) \ + ACCESSOR(returns, bp, bpf, field) -enum bpf_dir -netstat_bpt_get_direction(const struct bpf_type *btp) -{ - return (btp->bpt_direction); -} +BPF_ACC(int, flags); +BPF_ACC(enum bpf_dir, direction); +BPF_ACC(u_int32_t, pid); +BPF_ACC(const char *, ifname); +BPF_ACC(u_int64_t, recv); +BPF_ACC(u_int64_t, drop); +BPF_ACC(u_int64_t, match); +BPF_ACC(u_int64_t, slen); +BPF_ACC(u_int64_t, hlen); +BPF_ACC(const char *, pidname); -u_int32_t -netstat_bpt_get_pid(const struct bpf_type *btp) -{ - return (btp->bpt_pid); -} - -const char * -netstat_bpt_get_ifname(const struct bpf_type *btp) -{ - return (btp->bpt_ifname); -} - -u_int64_t -netstat_bpt_get_recv(const struct bpf_type *btp) -{ - return (btp->bpt_recv); -} - -u_int64_t -netstat_bpt_get_drop(const struct bpf_type *btp) -{ - return (btp->bpt_drop); -} - -u_int64_t -netstat_bpt_get_match(const struct bpf_type *btp) -{ - return (btp->bpt_match); -} +#undef BPF_ACC -u_int64_t -netstat_bpt_get_slen(const struct bpf_type *btp) -{ - return (btp->bpt_slen); -} - -u_int64_t -netstat_bpt_get_hlen(const struct bpf_type *btp) -{ - return (btp->bpt_hlen); -} - -const char * -netstat_bpt_get_pidname(const struct bpf_type *btp) -{ - return (btp->bpt_pidname); -} - struct stat_type * netstat_stat_alloc(void) { @@ -2295,7 +1980,7 @@ _netstat_rat_free(rtp->rt_destination); _netstat_rat_free(rtp->rt_gateway); for (i = 0; i < rtp->rt_node.rnt_mkcnt; i++) - _netstat_rat_free(rtp->rt_node.rnt_mklist[i].rmt_mask); + _netstat_rat_free(rtp->rt_node.rnt_mklist[i].rmt_netmask); if (rtp->rt_node.rnt_mklist != NULL) free(rtp->rt_node.rnt_mklist); free(rtp->rt_interface); @@ -2422,114 +2107,38 @@ free(rtip); } -int -netstat_rt_get_fib(const struct route_type *rtp) -{ - return (rtp->rt_fib); -} +#define ROUTE_ACC(returns, field) \ + ACCESSOR(returns, r, route, field) -int -netstat_rt_get_family(const struct route_type *rtp) -{ - return (rtp->rt_family); -} +#define ROUTE_ACCP(returns, field) \ + ACCESSORP(returns, r, route, field) -const struct routeaddr_type * -netstat_rt_get_destination(const struct route_type *rtp) -{ - return (rtp->rt_destination); -} +ROUTE_ACC (int, fib); +ROUTE_ACC (int, family); +ROUTE_ACC (const struct routeaddr_type *, destination); +ROUTE_ACC (const struct routeaddr_type *, gateway); +ROUTE_ACC (int, flags); +ROUTE_ACC (u_int64_t, refs); +ROUTE_ACC (u_int64_t, used); +ROUTE_ACC (const char *, interface); +ROUTE_ACC (u_int64_t, expire); +ROUTE_ACC (u_int32_t, mtu); +ROUTE_ACCP(const struct routenode_type *, node); -const struct routeaddr_type * -netstat_rt_get_gateway(const struct route_type *rtp) -{ - return (rtp->rt_gateway); -} +#undef ROUTE_ACC +#undef ROUTE_ACCP -int >>> TRUNCATED FOR MAIL (1000 lines) <<<
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201005161259.o4GCxtVa024258>