All of lore.kernel.org
 help / color / mirror / Atom feed
* [libsocketcan] Add can_get_link_stats() - v2
@ 2012-03-06 19:04 Reuben Dowle
  2012-03-07  9:44 ` Marc Kleine-Budde
  0 siblings, 1 reply; 4+ messages in thread
From: Reuben Dowle @ 2012-03-06 19:04 UTC (permalink / raw)
  To: linux-can@vger.kernel.org; +Cc: Marc Kleine-Budde

Add can_get_link_stats()

This function gets link_stats64 information for the can interface.
This structure can be for any interface (not just can), but it
seems logical to keep functions for getting any statistics relevant
to CAN in this library.

Signed-off-by: Reuben Dowle <reuben.dowle@navico.com>

diff --git a/include/libsocketcan.h b/include/libsocketcan.h
index dc52053..06b37d6 100644
--- a/include/libsocketcan.h
+++ b/include/libsocketcan.h
@@ -50,6 +50,7 @@ int can_get_clock(const char *name, struct can_clock *clock);
 int can_get_bittiming_const(const char *name, struct can_bittiming_const *btc);
 int can_get_berr_counter(const char *name, struct can_berr_counter *bc);
 int can_get_device_stats(const char *name, struct can_device_stats *cds);
+int can_get_link_stats(const char *name, struct rtnl_link_stats64 *ls);
 
 #ifdef __cplusplus
 }
diff --git a/src/libsocketcan.c b/src/libsocketcan.c
index 26da338..e460912 100644
--- a/src/libsocketcan.c
+++ b/src/libsocketcan.c
@@ -54,6 +54,7 @@
 #define GET_BITTIMING_CONST 6
 #define GET_BERR_COUNTER 7
 #define GET_XSTATS 8
+#define GET_LINK_STATS64 9
 
 struct get_req {
 	struct nlmsghdr n;
@@ -380,6 +381,18 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res)
 		    ((char *)RTA_DATA(tb[IFLA_IFNAME]), name,
 		     sizeof(name)) != 0)
 			continue;
+		
+		if (acquire == GET_LINK_STATS64) {
+			if (!tb[IFLA_STATS64]) {
+				fprintf(stderr, "no link_stats64 data found\n");
+			} else {
+				memcpy(res,
+				       RTA_DATA(tb[IFLA_STATS64]),
+				       sizeof(struct rtnl_link_stats64));
+				ret = 0;
+			}
+			continue;
+		}
 
 		if (tb[IFLA_LINKINFO])
 			parse_rtattr_nested(linkinfo,
@@ -1154,3 +1167,24 @@ int can_get_device_stats(const char *name, struct can_device_stats *cds)
 {
 	return get_link(name, GET_XSTATS, cds);
 }
+
+/**
+ * @ingroup extern
+ * can_get_link_stats - get the rtnl_link_stats64.
+ *
+ * @param name name of the can device. This is the netdev name, as ifconfig -a shows
+ * in your system. usually it contains prefix "can" and the numer of the can
+ * line. e.g. "can0"
+ * @param bc pointer to the error counter struct..
+ *
+ * This one gets the current rtnl_link_stats64.
+ *
+ * Please see struct rtnl_link_stats64 for more information.
+ *
+ * @return 0 if success
+ * @return -1 if failed
+ */
+int can_get_link_stats(const char *name, struct rtnl_link_stats64 *ls)
+{
+	return get_link(name, GET_LINK_STATS64, ls);
+}




^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [libsocketcan] Add can_get_link_stats() - v2
  2012-03-06 19:04 [libsocketcan] Add can_get_link_stats() - v2 Reuben Dowle
@ 2012-03-07  9:44 ` Marc Kleine-Budde
  2012-03-07 23:45   ` Reuben Dowle
  0 siblings, 1 reply; 4+ messages in thread
From: Marc Kleine-Budde @ 2012-03-07  9:44 UTC (permalink / raw)
  To: Reuben Dowle; +Cc: linux-can@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 961 bytes --]

On 03/06/2012 08:04 PM, Reuben Dowle wrote:
> Add can_get_link_stats()
> 
> This function gets link_stats64 information for the can interface.
> This structure can be for any interface (not just can), but it
> seems logical to keep functions for getting any statistics relevant
> to CAN in this library.
> 
> Signed-off-by: Reuben Dowle <reuben.dowle@navico.com>

I was at iCC2012 CAN conference, now I've some more time to look at the
code. What about naming the function after the struct? Seems more
consistent to me.

> +int can_get_link_stats(const char *name, struct rtnl_link_stats64 *ls)

I mean "can_get_link_stats64" instead of "can_get_link_stats"?

Marc

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [libsocketcan] Add can_get_link_stats() - v2
  2012-03-07  9:44 ` Marc Kleine-Budde
@ 2012-03-07 23:45   ` Reuben Dowle
  2012-03-08  8:49     ` Marc Kleine-Budde
  0 siblings, 1 reply; 4+ messages in thread
From: Reuben Dowle @ 2012-03-07 23:45 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: linux-can@vger.kernel.org

Sounds like good change. I will re-submit a patch when I have a spare moment (probably next week).

REUBEN DOWLE | DESIGN ENGINEER | NAVICO AUCKLAND
 
Confidentiality Notice | This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation


> -----Original Message-----
> From: Marc Kleine-Budde [mailto:mkl@pengutronix.de]
> Sent: Wednesday, March 07, 2012 10:45 PM
> To: Reuben Dowle
> Cc: linux-can@vger.kernel.org
> Subject: Re: [libsocketcan] Add can_get_link_stats() - v2
> 
> On 03/06/2012 08:04 PM, Reuben Dowle wrote:
> > Add can_get_link_stats()
> >
> > This function gets link_stats64 information for the can interface.
> > This structure can be for any interface (not just can), but it seems
> > logical to keep functions for getting any statistics relevant to CAN
> > in this library.
> >
> > Signed-off-by: Reuben Dowle <reuben.dowle@navico.com>
> 
> I was at iCC2012 CAN conference, now I've some more time to look at the
> code. What about naming the function after the struct? Seems more
> consistent to me.
> 
> > +int can_get_link_stats(const char *name, struct rtnl_link_stats64
> > +*ls)
> 
> I mean "can_get_link_stats64" instead of "can_get_link_stats"?
> 
> Marc
> 
> --
> Pengutronix e.K.                  | Marc Kleine-Budde           |
> Industrial Linux Solutions        | Phone: +49-231-2826-924     |
> Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
> Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [libsocketcan] Add can_get_link_stats() - v2
  2012-03-07 23:45   ` Reuben Dowle
@ 2012-03-08  8:49     ` Marc Kleine-Budde
  0 siblings, 0 replies; 4+ messages in thread
From: Marc Kleine-Budde @ 2012-03-08  8:49 UTC (permalink / raw)
  To: Reuben Dowle; +Cc: linux-can@vger.kernel.org

[-- Attachment #1: Type: text/plain, Size: 474 bytes --]

On 03/08/2012 12:45 AM, Reuben Dowle wrote:
> Sounds like good change. I will re-submit a patch when I have a spare moment (probably next week

I'm on vacation for one week, so no hurry.

Marc
-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-03-08  8:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-06 19:04 [libsocketcan] Add can_get_link_stats() - v2 Reuben Dowle
2012-03-07  9:44 ` Marc Kleine-Budde
2012-03-07 23:45   ` Reuben Dowle
2012-03-08  8:49     ` Marc Kleine-Budde

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.