arp.c (38557) | arp.c (40665) |
---|---|
1/* 2 * sys-bsd.c - System-dependent procedures for setting up 3 * PPP interfaces on bsd-4.4-ish systems (including 386BSD, NetBSD, etc.) 4 * 5 * Copyright (c) 1989 Carnegie Mellon University. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms are permitted 9 * provided that the above copyright notice and this paragraph are 10 * duplicated in all such forms and that any documentation, 11 * advertising materials, and other materials related to such 12 * distribution and use acknowledge that the software was developed 13 * by Carnegie Mellon University. The name of the 14 * University may not be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19 * | 1/* 2 * sys-bsd.c - System-dependent procedures for setting up 3 * PPP interfaces on bsd-4.4-ish systems (including 386BSD, NetBSD, etc.) 4 * 5 * Copyright (c) 1989 Carnegie Mellon University. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms are permitted 9 * provided that the above copyright notice and this paragraph are 10 * duplicated in all such forms and that any documentation, 11 * advertising materials, and other materials related to such 12 * distribution and use acknowledge that the software was developed 13 * by Carnegie Mellon University. The name of the 14 * University may not be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 19 * |
20 * $Id: arp.c,v 1.29 1998/06/16 19:40:34 brian Exp $ | 20 * $Id: arp.c,v 1.30 1998/08/26 17:39:36 brian Exp $ |
21 * 22 */ 23 24/* 25 * TODO: 26 */ 27 28#include <sys/types.h> --- 53 unchanged lines hidden (view full) --- 82 */ 83static struct { 84 struct rt_msghdr hdr; 85 struct sockaddr_inarp dst; 86 struct sockaddr_dl hwa; 87 char extra[128]; 88} arpmsg; 89 | 21 * 22 */ 23 24/* 25 * TODO: 26 */ 27 28#include <sys/types.h> --- 53 unchanged lines hidden (view full) --- 82 */ 83static struct { 84 struct rt_msghdr hdr; 85 struct sockaddr_inarp dst; 86 struct sockaddr_dl hwa; 87 char extra[128]; 88} arpmsg; 89 |
90static int arpmsg_valid; 91 92int 93arp_SetProxy(struct bundle *bundle, struct in_addr addr, int s) | 90static int 91arp_ProxySub(struct bundle *bundle, struct in_addr addr, int add, int s) |
94{ 95 int routes; 96 97 /* 98 * Get the hardware address of an interface on the same subnet as our local 99 * address. 100 */ | 92{ 93 int routes; 94 95 /* 96 * Get the hardware address of an interface on the same subnet as our local 97 * address. 98 */ |
99 |
|
101 memset(&arpmsg, 0, sizeof arpmsg); 102 if (!get_ether_addr(s, addr, &arpmsg.hwa)) { | 100 memset(&arpmsg, 0, sizeof arpmsg); 101 if (!get_ether_addr(s, addr, &arpmsg.hwa)) { |
103 log_Printf(LogWARN, "Cannot determine ethernet address for proxy ARP\n"); | 102 log_Printf(LogWARN, "%s: Cannot determine ethernet address for proxy ARP\n", 103 inet_ntoa(addr)); |
104 return 0; 105 } 106 routes = ID0socket(PF_ROUTE, SOCK_RAW, AF_INET); 107 if (routes < 0) { 108 log_Printf(LogERROR, "arp_SetProxy: opening routing socket: %s\n", 109 strerror(errno)); 110 return 0; 111 } | 104 return 0; 105 } 106 routes = ID0socket(PF_ROUTE, SOCK_RAW, AF_INET); 107 if (routes < 0) { 108 log_Printf(LogERROR, "arp_SetProxy: opening routing socket: %s\n", 109 strerror(errno)); 110 return 0; 111 } |
112 arpmsg.hdr.rtm_type = RTM_ADD; | 112 arpmsg.hdr.rtm_type = add ? RTM_ADD : RTM_DELETE; |
113 arpmsg.hdr.rtm_flags = RTF_ANNOUNCE | RTF_HOST | RTF_STATIC; 114 arpmsg.hdr.rtm_version = RTM_VERSION; 115 arpmsg.hdr.rtm_seq = ++bundle->routing_seq; 116 arpmsg.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY; 117 arpmsg.hdr.rtm_inits = RTV_EXPIRE; 118 arpmsg.dst.sin_len = sizeof(struct sockaddr_inarp); 119 arpmsg.dst.sin_family = AF_INET; 120 arpmsg.dst.sin_addr.s_addr = addr.s_addr; 121 arpmsg.dst.sin_other = SIN_PROXY; 122 123 arpmsg.hdr.rtm_msglen = (char *) &arpmsg.hwa - (char *) &arpmsg 124 + arpmsg.hwa.sdl_len; | 113 arpmsg.hdr.rtm_flags = RTF_ANNOUNCE | RTF_HOST | RTF_STATIC; 114 arpmsg.hdr.rtm_version = RTM_VERSION; 115 arpmsg.hdr.rtm_seq = ++bundle->routing_seq; 116 arpmsg.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY; 117 arpmsg.hdr.rtm_inits = RTV_EXPIRE; 118 arpmsg.dst.sin_len = sizeof(struct sockaddr_inarp); 119 arpmsg.dst.sin_family = AF_INET; 120 arpmsg.dst.sin_addr.s_addr = addr.s_addr; 121 arpmsg.dst.sin_other = SIN_PROXY; 122 123 arpmsg.hdr.rtm_msglen = (char *) &arpmsg.hwa - (char *) &arpmsg 124 + arpmsg.hwa.sdl_len; |
125 if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) { 126 log_Printf(LogERROR, "Add proxy arp entry: %s\n", strerror(errno)); | 125 126 127 if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0 && 128 !(!add && errno == ESRCH)) { 129 log_Printf(LogERROR, "%s proxy arp entry %s: %s\n", 130 add ? "Add" : "Delete", inet_ntoa(addr), strerror(errno)); |
127 close(routes); 128 return 0; 129 } 130 close(routes); | 131 close(routes); 132 return 0; 133 } 134 close(routes); |
131 arpmsg_valid = 1; | |
132 return 1; 133} 134 | 135 return 1; 136} 137 |
138int 139arp_SetProxy(struct bundle *bundle, struct in_addr addr, int s) 140{ 141 142 return (arp_ProxySub(bundle, addr, 1, s)); 143} 144 |
|
135/* 136 * arp_ClearProxy - Delete the proxy ARP entry for the peer. 137 */ 138int 139arp_ClearProxy(struct bundle *bundle, struct in_addr addr, int s) 140{ | 145/* 146 * arp_ClearProxy - Delete the proxy ARP entry for the peer. 147 */ 148int 149arp_ClearProxy(struct bundle *bundle, struct in_addr addr, int s) 150{ |
141 int routes; | |
142 | 151 |
143 if (!arpmsg_valid) 144 return 0; 145 arpmsg_valid = 0; 146 147 arpmsg.hdr.rtm_type = RTM_DELETE; 148 arpmsg.hdr.rtm_seq = ++bundle->routing_seq; 149 150 routes = ID0socket(PF_ROUTE, SOCK_RAW, AF_INET); 151 if (routes < 0) { 152 log_Printf(LogERROR, "arp_SetProxy: opening routing socket: %s\n", 153 strerror(errno)); 154 return 0; 155 } 156 if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) { 157 log_Printf(LogERROR, "Delete proxy arp entry: %s\n", strerror(errno)); 158 close(routes); 159 return 0; 160 } 161 close(routes); 162 return 1; | 152 return (arp_ProxySub(bundle, addr, 0, s)); |
163} 164 165#else /* RTM_VERSION */ 166 167/* 168 * arp_SetProxy - Make a proxy ARP entry for the peer. 169 */ 170int --- 160 unchanged lines hidden --- | 153} 154 155#else /* RTM_VERSION */ 156 157/* 158 * arp_SetProxy - Make a proxy ARP entry for the peer. 159 */ 160int --- 160 unchanged lines hidden --- |