I couldn't find an existing function to convert a prefix length to a
netmask, so I just wrote my own. Net SNMP version is 5.7.2. Here is the
patch:

--- route_ioctl.c.old   2012-10-09 18:28:58.000000000 -0400
+++ route_ioctl.c       2014-01-21 10:30:32.239381288 -0500
@@ -114,7 +114,7 @@
     DEBUGMSGTL(("access:route","    via %s\n", DEBUGSTR));
 
     mask.sin_family = AF_INET;
-    mask.sin_addr.s_addr = htonl(0);
+    mask.sin_addr.s_addr = entry->rt_pfx_len ? htonl((( ((uint32_t)1) <<
(32-entry->rt_pfx_len)) - 1) ^ 0xffffffffU) : 0;
     DEBUGSTR = inet_ntoa(mask.sin_addr);
     DEBUGMSGTL(("access:route","    mask %s\n", DEBUGSTR));


Daniel

-----Original Message-----
From: Daniel Tingstrom [mailto:dtingst...@atcorp.com] 
Sent: Tuesday, January 21, 2014 9:50 AM
To: net-snmp-coders@lists.sourceforge.net
Subject: RE: Creating inetCidrRouteTable row entries

FYI, the prefix length can be accessed by entry->rt_pfx_len in this method
(_netsnmp_ioctl_route_set_v4). I wrote a little code to convert
entry->rt_pfx_len (the prefix length) to a netmask (unsigned int) and
tried it out. Adding new routes via inetCidrRouteTable seems to work now.
If anyone's interested, I could provide a patch.

Daniel

-----Original Message-----
From: Daniel Tingstrom [mailto:dtingst...@atcorp.com] 
Sent: Friday, January 17, 2014 10:41 AM
To: net-snmp-coders@lists.sourceforge.net
Subject: Creating inetCidrRouteTable row entries

Hi, 

I need to add a static route entry in linux via SNMP. So I am using
inetCidrRouteTable. Unfortunately, the implementation of
_netsnmp_ioctl_route_set_v4() in route_ioctl.c always hardcodes the
route's netmask to 0.0.0.0, allowing only default gateway routes to be
added. 

I had to manually change the following line:

mask.sin_addr.s_addr = htonl(0);

to:

mask.sin_addr.s_addr = htonl(0xffff0000);

for the following snmpset command to work:

snmpset -l authPriv -A password -X password -a SHA -x AES -u authPrivUser
localhost
IP-FORWARD-MIB::inetCidrRouteStatus.1.4.20.20.0.0.16.2.0.0.1.4.10.10.0.1 i
4
IP-FORWARD-MIB::inetCidrRouteIfIndex.1.4.20.20.0.0.16.2.0.0.1.4.10.10.0.1
i
3
IP-FORWARD-MIB::inetCidrRouteMetric1.1.4.20.20.0.0.16.2.0.0.1.4.10.10.0.1
i 0 IP-FORWARD-MIB::inetCidrRouteType.1.4.20.20.0.0.16.2.0.0.1.4.10.10.0.1
i
4

I want to do the equivalent of: ip route add 20.20.0.0/16 via 10.10.0.1

I am new to SNMP and so I could be doing this wrong or making incorrect
assumptions. Perhaps there is an alternative method to adding static
routes that are not default gateways? Or is this simply a bug?

Thanks,
Daniel



----------------------------------------------------------------------------
--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Attachment: smime.p7s
Description: S/MIME cryptographic signature

------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to