User: Password:
|
|
Subscribe / Log in / New account

Python and ipaddr.py

Python and ipaddr.py

Posted Jun 18, 2009 2:26 UTC (Thu) by gdt (subscriber, #6284)
Parent article: Python and ipaddr.py

I am a network engineer. The conflation of IP addresses; IP routing prefixes; IP access lists masks; inverse masks; 32-bit numbers which are convenient to print in dotted-quad format (eg, OSPF areas) really annoys me. Tools which do this encourage sloppy thinking, leading to routing prefixes without lengths or firewall rules which can't ignore just part of an address (such as the subnet component of a EUI-64 address).

To see what I mean, consider a function is_multicast(). Handing that a bitmask or a 32-bit number (as opposed to an address or a routing prefix) should result in an error. But that's exactly the API bug which prevents OSPF areas starting with 224. on a certain make of router.

Similarly, a function ipv4_to_ipv4_mapped_ipv6() should only accept IPv4 addresses; not routing prefixes, OSPF areas, or bitmasks.

Another good example is Wireshark. It conflates all of these things. Which makes it difficult to add code like is_iana_allocated() to check all routing prefixes and indicate those which should not be seen in the wild. Every printing of an IP address needs to be examined, rather than updating a generic route prefix printing function.


(Log in to post comments)

Python and ipaddr.py

Posted Jun 18, 2009 12:48 UTC (Thu) by busterb (subscriber, #560) [Link]

I've been using libdnet, which is in C, for years, and it also uses the same structure to identify an
address and a subnet. http://libdnet.sourceforge.net/dnet.3.txt An individual host IP is just a /32.

I'm not sure I understand how you can deal with an IP address without also knowing its netmask,
whether you're calling it a subnet or a host IP address. In fact, Linux's tools complain if you try to
manipulate an IP address without the mask:

bcook@target4:~$ sudo ip addr add 2.0.0.1/16 dev test2
bcook@target4:~$ sudo ip addr del 2.0.0.1 dev test2
Warning: Executing wildcard deletion to stay compatible with old scripts.
Explicitly specify the prefix length (2.0.0.1/32) to avoid this warning.
This special behaviour is likely to disappear in further releases,
fix your scripts!

Python and ipaddr.py

Posted Jun 18, 2009 15:38 UTC (Thu) by johill (subscriber, #25196) [Link]

The 'ip' command behaviour outlined here is because it also conflates the IP address and the network, because it not only deletes the address but also the corresponding route.

Python and ipaddr.py

Posted Jun 18, 2009 20:32 UTC (Thu) by jengelh (subscriber, #33263) [Link]

ip does not delete routes here; the kernel does (AFAICS). You see the same behavior when doing `ip link set eth0 down`.

Python and ipaddr.py

Posted Jun 18, 2009 20:42 UTC (Thu) by johill (subscriber, #25196) [Link]

Ok, so the kernel needs to know the address and netmask and conflates it, not ip. Doesn't change much :)


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds