Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Aug 2009 03:02:02 GMT
From:      Gabor Pali <pgj@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 167460 for review
Message-ID:  <200908180302.n7I322qY069738@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=167460

Change 167460 by pgj@petymeg-current on 2009/08/18 03:01:07

	- Add mcastif_type, an abstraction for multicast (or "virtual")
	  interfaces.  This type connects to the previously created
	  routeaddr_type to represent routing addresses.
	- Add netstat_mif() function that returns active multicast
	  interfaces in the system.
	- Implement information extraction for both PF_INET and PF_INET6
	  protocols, and for both sysctl(3) and kvm(3).

Affected files ...

.. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/Makefile#18 edit
.. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.h#63 edit
.. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_internal.h#59 edit
.. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_mroute.c#1 add
.. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_route.c#6 edit
.. //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_util.c#68 edit

Differences ...

==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/Makefile#18 (text+ko) ====

@@ -4,7 +4,7 @@
 
 LIB=	netstat
 SRCS=	netstat_socket.c netstat_mbuf.c netstat_if.c netstat_bpf.c \
-	netstat_stat.c netstat_route.c netstat_util.c
+	netstat_stat.c netstat_route.c netstat_mroute.c netstat_util.c
 
 INCS=	netstat.h
 

==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat.h#63 (text+ko) ====

@@ -49,6 +49,7 @@
 #define	IFTYPE_MAXADDRCNT	    8
 
 #define BPFTYPE_MAXNAME		    IFNAMSIZ
+#define MIFTYPE_MAXNAME		    IFNAMSIZ
 
 #define NETSTAT_ERROR_UNDEFINED	    0
 #define NETSTAT_ERROR_NOMEMORY	    1
@@ -125,6 +126,11 @@
 /* Testing flags for routemask_type: */
 #define NETSTAT_RTM_NORMAL	0x01
 
+/* Testing flags for mcastif_type: */
+#define	NETSTAT_MIF_TUNNEL	0x01
+#define NETSTAT_MIF_SRCRT	0x02
+#define NETSTAT_MIF_REGISTER	0x04
+
 /* Enum for TCP states: */
 enum tcp_state {
     tcps_Closed,
@@ -268,6 +274,10 @@
 struct route_type_list;
 struct route_type_iterator;
 
+struct mcastif_type;
+struct mcastif_type_list;
+struct mcastif_type_iterator;
+
 __BEGIN_DECLS
 const char		    *netstat_strerror(int);
 const char		    *netstat_kvmerror(const struct session_type *);
@@ -1267,4 +1277,30 @@
 const char  *netstat_rat_get_name(const struct routeaddr_type *, int);
 size_t	    netstat_rat_get_address(const struct routeaddr_type *, void *, size_t);
 int	    netstat_rat_get_family(const struct routeaddr_type *);
+
+/* Multicast interfaces: */
+struct mcastif_type_list	*netstat_mitl_alloc(void);
+void	netstat_mitl_free(struct mcastif_type_list *);
+int	netstat_mitl_geterror(const struct mcastif_type_list *);
+int	netstat_mitl_length(const struct mcastif_type_list *);
+
+int	netstat_miti_alloc(struct mcastif_type_list *list,
+	    struct mcastif_type_iterator **iterator);
+const struct mcastif_type *netstat_miti_first(struct mcastif_type_iterator *);
+const struct mcastif_type *netstat_miti_next(struct mcastif_type_iterator *);
+void	netstat_miti_free(struct mcastif_type_iterator *);
+
+int	netstat_mif(const struct session_type *, int domain,
+	    struct mcastif_type_list *list, int flags);
+
+u_int32_t   netstat_mit_get_index(const struct mcastif_type *);
+int	    netstat_mit_get_flags(const struct mcastif_type *);
+u_int32_t   netstat_mit_get_limit(const struct mcastif_type *);
+const struct routeaddr_type *netstat_mit_get_address(const struct mcastif_type *);
+const struct routeaddr_type *netstat_mit_get_remote_address(const struct mcastif_type *);
+u_int64_t   netstat_mit_get_packets_in(const struct mcastif_type *);
+u_int64_t   netstat_mit_get_packets_out(const struct mcastif_type *);
+u_int64_t   netstat_mit_get_bytes_in(const struct mcastif_type *);
+u_int64_t   netstat_mit_get_bytes_out(const struct mcastif_type *);
+const char  *netstat_mit_get_ifname(const struct mcastif_type *);
 #endif /* !_NETSTAT_H_ */

==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_internal.h#59 (text+ko) ====

@@ -500,6 +500,34 @@
 };
 
 
+/* Multicast interface type. */
+struct mcastif_type {
+	u_int32_t		    mit_index;
+	int			    mit_flags;
+	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_bytes_in;
+	u_int64_t		    mit_bytes_out;
+	char			    mit_ifname[MIFTYPE_MAXNAME];
+
+	TAILQ_ENTRY(mcastif_type)   mit_list;
+};
+
+struct mcastif_type_list {
+	TAILQ_HEAD(, mcastif_type)  mitl_list;
+	int			    mitl_length;
+	int			    mitl_error;
+};
+
+struct mcastif_type_iterator {
+	struct mcastif_type_list    *miti_list;
+	struct mcastif_type	    *miti_first;
+	struct mcastif_type	    *miti_next;
+};
+
 int kread_data(kvm_t *kvm, u_long kvm_pointer, void *address, size_t size);
 int kread_string(kvm_t *kvm, u_long kvm_pointer, char *buffer, int buflen);
 
@@ -531,6 +559,11 @@
 struct route_type *_netstat_rt_allocate(struct route_type_list *);
 struct routeaddr_type *_netstat_rat_allocate(int, void *, size_t);
 
+void _netstat_mitl_empty(struct mcastif_type_list *);
+void _netstat_mit_free(struct mcastif_type *);
+struct mcastif_type *_netstat_mit_allocate(struct mcastif_type_list *);
+
+struct routeaddr_type *extract_address(void *, void *, int);
 const char  *resolve_val2str_name(int, const struct val2str *);
 /* XXX: merge these into a common address resolution routine. */
 const char	*routename(in_addr_t in, int numeric);

==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_route.c#6 (text+ko) ====

@@ -61,7 +61,6 @@
 static void process_tree(kvm_t *, struct route_type_list *,
 	    struct radix_node *, int, int);
 static void extract_rtentry_data(struct rtentry *, struct route_type *);
-static struct routeaddr_type *extract_address(void *, void *, int);
 static void extract_node(struct radix_node *, struct routenode_type *, int);
 
 int

==== //depot/projects/soc2009/pgj_libstat/src/lib/libnetstat/netstat_util.c#68 (text+ko) ====

@@ -2562,6 +2562,183 @@
 }
 
 
+void
+_netstat_mitl_empty(struct mcastif_type_list *list)
+{
+	struct mcastif_type *mitp;
+
+	while ((mitp = TAILQ_FIRST(&list->mitl_list)) ) {
+		TAILQ_REMOVE(&list->mitl_list, mitp, mit_list);
+		_netstat_mit_free(mitp);
+	}
+
+	list->mitl_length = 0;
+}
+
+void
+_netstat_mit_free(struct mcastif_type *mitp)
+{
+	_netstat_rat_free(mitp->mit_address);
+	if (mitp->mit_remote_address != NULL)
+		_netstat_rat_free(mitp->mit_remote_address);
+	free(mitp);
+}
+
+struct mcastif_type *
+_netstat_mit_allocate(struct mcastif_type_list *list)
+{
+	struct mcastif_type *mitp;
+
+	mitp = malloc(sizeof(*mitp));
+	if (mitp == NULL)
+		return (NULL);
+
+	bzero(mitp, sizeof(*mitp));
+	TAILQ_INSERT_TAIL(&list->mitl_list, mitp, mit_list);
+	list->mitl_length += 1;
+	return (mitp);
+}
+
+struct mcastif_type_list *
+netstat_mitl_alloc(void)
+{
+	struct mcastif_type_list *mitlp;
+
+	mitlp = malloc(sizeof(*mitlp));
+	if (mitlp == NULL)
+		return (NULL);
+
+	TAILQ_INIT(&mitlp->mitl_list);
+	mitlp->mitl_error = NETSTAT_ERROR_UNDEFINED;
+	mitlp->mitl_length = 0;
+	return (mitlp);
+}
+
+void
+netstat_mitl_free(struct mcastif_type_list *mitlp)
+{
+	_netstat_mitl_empty(mitlp);
+	free(mitlp);
+}
+
+int
+netstat_mitl_geterror(const struct mcastif_type_list *mitlp)
+{
+	return (mitlp->mitl_error);
+}
+
+int
+netstat_mitl_length(const struct mcastif_type_list *mitlp)
+{
+	return (mitlp->mitl_length);
+}
+
+int
+netstat_miti_alloc(struct mcastif_type_list *list,
+    struct mcastif_type_iterator **iterator)
+{
+	struct mcastif_type_iterator *mitip;
+
+	mitip = malloc(sizeof(*mitip));
+	if (mitip == NULL)
+		return (-1);
+
+	bzero(mitip, sizeof(*mitip));
+	mitip->miti_list = list;
+	mitip->miti_first = TAILQ_FIRST(&list->mitl_list);
+	if (mitip->miti_first != NULL)
+		mitip->miti_next = TAILQ_NEXT(mitip->miti_first, mit_list);
+	*iterator = mitip;
+	return (0);
+}
+
+const struct mcastif_type *
+netstat_miti_first(struct mcastif_type_iterator *mitip)
+{
+	if (mitip->miti_first != NULL)
+		mitip->miti_next = TAILQ_NEXT(mitip->miti_first, mit_list);
+	return (mitip->miti_first);
+}
+
+const struct mcastif_type *
+netstat_miti_next(struct mcastif_type_iterator *mitip)
+{
+	const struct mcastif_type *mitp;
+
+	mitp = mitip->miti_next;
+	if (mitip->miti_next != NULL)
+		mitip->miti_next = TAILQ_NEXT(mitip->miti_next, mit_list);
+
+	return (mitp);
+}
+
+void
+netstat_miti_free(struct mcastif_type_iterator *mitip)
+{
+	free(mitip);
+}
+
+u_int32_t
+netstat_mit_get_index(const struct mcastif_type *mitp)
+{
+	return (mitp->mit_index);
+}
+
+int
+netstat_mit_get_flags(const struct mcastif_type *mitp)
+{
+	return (mitp->mit_flags);
+}
+
+u_int32_t
+netstat_mit_get_limit(const struct mcastif_type *mitp)
+{
+	return (mitp->mit_limit);
+}
+
+const struct routeaddr_type *
+netstat_mit_get_address(const struct mcastif_type *mitp)
+{
+	return (mitp->mit_address);
+}
+
+const struct routeaddr_type *
+netstat_mit_get_remote_address(const struct mcastif_type *mitp)
+{
+	return (mitp->mit_remote_address);
+}
+
+u_int64_t
+netstat_mit_get_packets_in(const struct mcastif_type *mitp)
+{
+	return (mitp->mit_pkts_in);
+}
+
+u_int64_t
+netstat_mit_get_packets_out(const struct mcastif_type *mitp)
+{
+	return (mitp->mit_pkts_out);
+}
+
+u_int64_t
+netstat_mit_get_bytes_in(const struct mcastif_type *mitp)
+{
+	return (mitp->mit_bytes_in);
+}
+
+u_int64_t
+netstat_mit_get_bytes_out(const struct mcastif_type *mitp)
+{
+	return (mitp->mit_bytes_out);
+}
+
+const char *
+netstat_mit_get_ifname(const struct mcastif_type *mitp)
+{
+	return (mitp->mit_ifname);
+}
+
+
 static	const char *icmpnames[ICMP_MAXTYPE + 1] = {
 	"echo reply",			/* RFC 792 */
 	"#1",



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200908180302.n7I322qY069738>