How to get the preferred and valid lifetimes via pyroute2.IPDB?

21 views
Skip to first unread message

TheDiveO

unread,
Sep 16, 2017, 11:55:42 AM9/16/17
to pyroute2-dev
How do I retrieve the preferred and valid lifetimes of the IPv6 addresses of an IPv6 node? When pretty-printing the interfaces[''ipaddr'] element of an IPDB() instance, I only see the addresses and the Linux-specific address "prefix length" settings. I would like to retrieve the lifetimes associated with every IPv6 address that is assigned to a network interface for diagnosis. How to...?

Best regards,
TheDiveO


Peter Saveliev

unread,
Sep 16, 2017, 1:00:33 PM9/16/17
to TheDiveO, pyroute2-dev
IPDB currently doesn't store IFA_CACHEINFO — currently you can get this info via ipdb.nl.get_addr() interface or an IPRoute instance.

If you believe it would be useful to have that cached in IPDB, I can implement that as well.


--
You received this message because you are subscribed to the Google Groups "pyroute2-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyroute2-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

TheDiveO

unread,
Sep 16, 2017, 1:25:24 PM9/16/17
to pyroute2-dev
Peter, thank you very much for your quick response! Getting cached access would help me with tracking IPv6 address changes without the need to regularly poll, avoiding unnecessary cpu load.

Since these lifetimes, the cached lifetimes should have a reference timestamp that indicates when the lifetimes were read and stored.

Best regards,
TheDiveO

PS, the RFCs constantly use the spelling "preferred" with two "r". From reading some sources of pyroute2 I noticed that the lib users "prefered".

Peter Saveliev

unread,
Sep 16, 2017, 1:36:50 PM9/16/17
to TheDiveO, pyroute2-dev
Ok, than the support will be done asap.

Thanks for the notice about «preferred» — that's a typo and will be fixed.

TheDiveO

unread,
Sep 16, 2017, 1:40:38 PM9/16/17
to pyroute2-dev
Peter, thank you very much!

Peter Saveliev

unread,
Sep 17, 2017, 1:31:36 PM9/17/17
to TheDiveO, pyroute2-dev
In the master:

In [1]: from pyroute2 import IPDB
In [2]: ip = IPDB()
In [3]: ip.interfaces.wlp4s0.ipaddr[('fe80::7552:c31a:60c6:a427', 64)]['cacheinfo']
Out[3]:
{'cstamp': 35003367,
 'ifa_preferred': 4294967295,
 'ifa_valid': 4294967295,
 'tstamp': 35003472}

In [4]: ip.interfaces.wlp4s0.ipaddr['fe80::7552:c31a:60c6:a427/64']['cacheinfo']
Out[4]:
{'cstamp': 35003367,
 'ifa_preferred': 4294967295,
 'ifa_valid': 4294967295,
 'tstamp': 35003472}


2017-09-16 19:40 GMT+02:00 TheDiveO <harald....@gmx.net>:
Peter, thank you very much!

TheDiveO

unread,
Sep 17, 2017, 1:48:15 PM9/17/17
to pyroute2-dev
Cool! Just installed from git and gave it a try, works like a charm. Peter, many, many thanks for adding this!

What is the difference between the cstamp and the tstamp?

Best regards,
TheDiveO

Peter Saveliev

unread,
Sep 17, 2017, 3:31:27 PM9/17/17
to TheDiveO, pyroute2-dev
> What is the difference between the cstamp and the tstamp?

cstamp — is the address creation timestamp
tstamp — meaningful for temporary addresses, but I didn't look deeply into the kernel code.

--
Reply all
Reply to author
Forward
0 new messages