Fix for route addition/deletion.
Originally from Darwin, found by Alexandre Anriot.
This commit is contained in:
parent
1f81dc7261
commit
305d75f0f5
@ -1,4 +1,4 @@
|
||||
# $OpenBSD: Makefile,v 1.9 2005/05/26 03:34:21 robert Exp $
|
||||
# $OpenBSD: Makefile,v 1.10 2005/06/13 22:42:00 naddy Exp $
|
||||
|
||||
SHARED_ONLY= Yes
|
||||
|
||||
@ -6,7 +6,7 @@ COMMENT= "extendable SNMP implementation"
|
||||
COMMENT-perl= "SNMP modules for Perl"
|
||||
|
||||
DISTNAME= net-snmp-5.1.2
|
||||
PKGNAME= ${DISTNAME}p1
|
||||
PKGNAME= ${DISTNAME}p2
|
||||
FULLPKGNAME-perl= p5-SNMP-5.1.2p0
|
||||
CATEGORIES= net
|
||||
MASTER_SITES= ${MASTER_SITE_SOURCEFORGE:=net-snmp/}
|
||||
|
122
net/net-snmp/patches/patch-agent_mibgroup_mibII_route_write_c
Normal file
122
net/net-snmp/patches/patch-agent_mibgroup_mibII_route_write_c
Normal file
@ -0,0 +1,122 @@
|
||||
$OpenBSD: patch-agent_mibgroup_mibII_route_write_c,v 1.1 2005/06/13 22:42:00 naddy Exp $
|
||||
--- agent/mibgroup/mibII/route_write.c.orig Fri Jul 9 02:34:30 2004
|
||||
+++ agent/mibgroup/mibII/route_write.c Mon Jun 13 23:14:23 2005
|
||||
@@ -102,7 +102,7 @@
|
||||
int
|
||||
addRoute(u_long dstip, u_long gwip, u_long iff, u_short flags)
|
||||
{
|
||||
-#ifndef dynix
|
||||
+#if !(defined dynix || defined darwin || defined __OpenBSD__)
|
||||
struct sockaddr_in dst;
|
||||
struct sockaddr_in gateway;
|
||||
int s, rc;
|
||||
@@ -141,6 +141,50 @@ addRoute(u_long dstip, u_long gwip, u_lo
|
||||
return rc;
|
||||
#endif
|
||||
|
||||
+#elif defined darwin || defined __OpenBSD__
|
||||
+
|
||||
+ int s, rc;
|
||||
+ struct {
|
||||
+ struct rt_msghdr hdr;
|
||||
+ struct sockaddr_in dst;
|
||||
+ struct sockaddr_in gateway;
|
||||
+ } rtmsg;
|
||||
+
|
||||
+ s = socket(PF_ROUTE, SOCK_RAW, 0);
|
||||
+ if (s < 0) {
|
||||
+ snmp_log_perror("socket");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ shutdown(s, SHUT_RD);
|
||||
+
|
||||
+ /* possible panic otherwise */
|
||||
+ flags |= (RTF_UP | RTF_GATEWAY);
|
||||
+
|
||||
+ bzero(&rtmsg, sizeof(rtmsg));
|
||||
+
|
||||
+ rtmsg.hdr.rtm_type = RTM_ADD;
|
||||
+ rtmsg.hdr.rtm_version = RTM_VERSION;
|
||||
+ rtmsg.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY;
|
||||
+ rtmsg.hdr.rtm_flags = RTF_GATEWAY;
|
||||
+
|
||||
+ rtmsg.dst.sin_len = sizeof(rtmsg.dst);
|
||||
+ rtmsg.dst.sin_family = AF_INET;
|
||||
+ rtmsg.dst.sin_addr.s_addr = htonl(dstip);
|
||||
+
|
||||
+ rtmsg.gateway.sin_len = sizeof(rtmsg.gateway);
|
||||
+ rtmsg.gateway.sin_family = AF_INET;
|
||||
+ rtmsg.gateway.sin_addr.s_addr = htonl(gwip);
|
||||
+
|
||||
+ rc = sizeof(rtmsg);
|
||||
+ rtmsg.hdr.rtm_msglen = rc;
|
||||
+
|
||||
+ if ((rc = write(s, &rtmsg, rc)) < 0) {
|
||||
+ snmp_log_perror("writing to routing socket");
|
||||
+ return -1;
|
||||
+ }
|
||||
+ return (rc);
|
||||
+
|
||||
#else /* dynix */
|
||||
/*
|
||||
* Throws up the following errors:
|
||||
@@ -166,7 +210,7 @@ addRoute(u_long dstip, u_long gwip, u_lo
|
||||
int
|
||||
delRoute(u_long dstip, u_long gwip, u_long iff, u_short flags)
|
||||
{
|
||||
-#ifndef dynix
|
||||
+#if !(defined dynix || defined darwin || defined __OpenBSD__)
|
||||
|
||||
struct sockaddr_in dst;
|
||||
struct sockaddr_in gateway;
|
||||
@@ -204,6 +248,49 @@ delRoute(u_long dstip, u_long gwip, u_lo
|
||||
close(s);
|
||||
return rc;
|
||||
#endif
|
||||
+#elif defined darwin || defined __OpenBSD__
|
||||
+
|
||||
+ int s, rc;
|
||||
+ struct {
|
||||
+ struct rt_msghdr hdr;
|
||||
+ struct sockaddr_in dst;
|
||||
+ struct sockaddr_in gateway;
|
||||
+ } rtmsg;
|
||||
+
|
||||
+ s = socket(PF_ROUTE, SOCK_RAW, 0);
|
||||
+ if (s < 0) {
|
||||
+ snmp_log_perror("socket");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ shutdown(s, SHUT_RD);
|
||||
+
|
||||
+ /* possible panic otherwise */
|
||||
+ flags |= (RTF_UP | RTF_GATEWAY);
|
||||
+
|
||||
+ bzero(&rtmsg, sizeof(rtmsg));
|
||||
+
|
||||
+ rtmsg.hdr.rtm_type = RTM_DELETE;
|
||||
+ rtmsg.hdr.rtm_version = RTM_VERSION;
|
||||
+ rtmsg.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY;
|
||||
+ rtmsg.hdr.rtm_flags = RTF_GATEWAY;
|
||||
+
|
||||
+ rtmsg.dst.sin_len = sizeof(rtmsg.dst);
|
||||
+ rtmsg.dst.sin_family = AF_INET;
|
||||
+ rtmsg.dst.sin_addr.s_addr = htonl(dstip);
|
||||
+
|
||||
+ rtmsg.gateway.sin_len = sizeof(rtmsg.gateway);
|
||||
+ rtmsg.gateway.sin_family = AF_INET;
|
||||
+ rtmsg.gateway.sin_addr.s_addr = htonl(gwip);
|
||||
+
|
||||
+ rc = sizeof(rtmsg);
|
||||
+ rtmsg.hdr.rtm_msglen = rc;
|
||||
+
|
||||
+ if ((rc = write(s, &rtmsg, rc)) < 0) {
|
||||
+ snmp_log_perror("writing to routing socket");
|
||||
+ return -1;
|
||||
+ }
|
||||
+ return (rc);
|
||||
|
||||
#else /* dynix */
|
||||
/*
|
Loading…
Reference in New Issue
Block a user