Deleted Added
full compact
arp.c (24940) arp.c (26516)
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.10 1997/02/25 14:04:50 brian Exp $
20 * $Id: arp.c,v 1.11 1997/04/15 00:03:35 brian Exp $
21 *
22 */
23
24/*
25 * TODO:
26 */
27
28#include <sys/ioctl.h>

--- 21 unchanged lines hidden (view full) ---

50#include "log.h"
51
52#if RTM_VERSION >= 3
53#include <netinet/if_ether.h>
54#endif
55
56static int rtm_seq;
57
21 *
22 */
23
24/*
25 * TODO:
26 */
27
28#include <sys/ioctl.h>

--- 21 unchanged lines hidden (view full) ---

50#include "log.h"
51
52#if RTM_VERSION >= 3
53#include <netinet/if_ether.h>
54#endif
55
56static int rtm_seq;
57
58static int get_ether_addr __P((int, u_long, struct sockaddr_dl *));
58static int get_ether_addr(int, u_long, struct sockaddr_dl *);
59
60#define BCOPY(s, d, l) memcpy(d, s, l)
61#define BZERO(s, n) memset(s, 0, n)
62/*
63 * SET_SA_FAMILY - set the sa_family field of a struct sockaddr,
64 * if it exists.
65 */
66#define SET_SA_FAMILY(addr, family) \

--- 24 unchanged lines hidden (view full) ---

91 int routes;
92
93 /*
94 * Get the hardware address of an interface on the same subnet
95 * as our local address.
96 */
97 memset(&arpmsg, 0, sizeof(arpmsg));
98 if (!get_ether_addr(unit, hisaddr, &arpmsg.hwa)) {
59
60#define BCOPY(s, d, l) memcpy(d, s, l)
61#define BZERO(s, n) memset(s, 0, n)
62/*
63 * SET_SA_FAMILY - set the sa_family field of a struct sockaddr,
64 * if it exists.
65 */
66#define SET_SA_FAMILY(addr, family) \

--- 24 unchanged lines hidden (view full) ---

91 int routes;
92
93 /*
94 * Get the hardware address of an interface on the same subnet
95 * as our local address.
96 */
97 memset(&arpmsg, 0, sizeof(arpmsg));
98 if (!get_ether_addr(unit, hisaddr, &arpmsg.hwa)) {
99 logprintf("Cannot determine ethernet address for proxy ARP\n");
99 LogPrintf(LogERROR, "Cannot determine ethernet address"
100 " for proxy ARP\n");
100 return 0;
101 }
102
103 if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {
101 return 0;
102 }
103
104 if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {
104 logprintf("sifproxyarp: opening routing socket: \n");
105 LogPrintf(LogERROR, "sifproxyarp: opening routing socket: %s\n",
106 strerror(errno));
105 return 0;
106 }
107
108 arpmsg.hdr.rtm_type = RTM_ADD;
109 arpmsg.hdr.rtm_flags = RTF_ANNOUNCE | RTF_HOST | RTF_STATIC;
110 arpmsg.hdr.rtm_version = RTM_VERSION;
111 arpmsg.hdr.rtm_seq = ++rtm_seq;
112 arpmsg.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY;
113 arpmsg.hdr.rtm_inits = RTV_EXPIRE;
114 arpmsg.dst.sin_len = sizeof(struct sockaddr_inarp);
115 arpmsg.dst.sin_family = AF_INET;
116 arpmsg.dst.sin_addr.s_addr = hisaddr;
117 arpmsg.dst.sin_other = SIN_PROXY;
118
119 arpmsg.hdr.rtm_msglen = (char *) &arpmsg.hwa - (char *) &arpmsg
120 + arpmsg.hwa.sdl_len;
121 if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) {
107 return 0;
108 }
109
110 arpmsg.hdr.rtm_type = RTM_ADD;
111 arpmsg.hdr.rtm_flags = RTF_ANNOUNCE | RTF_HOST | RTF_STATIC;
112 arpmsg.hdr.rtm_version = RTM_VERSION;
113 arpmsg.hdr.rtm_seq = ++rtm_seq;
114 arpmsg.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY;
115 arpmsg.hdr.rtm_inits = RTV_EXPIRE;
116 arpmsg.dst.sin_len = sizeof(struct sockaddr_inarp);
117 arpmsg.dst.sin_family = AF_INET;
118 arpmsg.dst.sin_addr.s_addr = hisaddr;
119 arpmsg.dst.sin_other = SIN_PROXY;
120
121 arpmsg.hdr.rtm_msglen = (char *) &arpmsg.hwa - (char *) &arpmsg
122 + arpmsg.hwa.sdl_len;
123 if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) {
122 logprintf("add proxy arp entry: \n");
124 LogPrintf(LogERROR, "Add proxy arp entry: %s\n", strerror(errno));
123 close(routes);
124 return 0;
125 }
126
127 close(routes);
128 arpmsg_valid = 1;
129 return 1;
130}

--- 11 unchanged lines hidden (view full) ---

142 if (!arpmsg_valid)
143 return 0;
144 arpmsg_valid = 0;
145
146 arpmsg.hdr.rtm_type = RTM_DELETE;
147 arpmsg.hdr.rtm_seq = ++rtm_seq;
148
149 if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {
125 close(routes);
126 return 0;
127 }
128
129 close(routes);
130 arpmsg_valid = 1;
131 return 1;
132}

--- 11 unchanged lines hidden (view full) ---

144 if (!arpmsg_valid)
145 return 0;
146 arpmsg_valid = 0;
147
148 arpmsg.hdr.rtm_type = RTM_DELETE;
149 arpmsg.hdr.rtm_seq = ++rtm_seq;
150
151 if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {
150 logprintf("sifproxyarp: opening routing socket: \n");
152 LogPrintf(LogERROR, "sifproxyarp: opening routing socket: %s\n",
153 strerror(errno));
151 return 0;
152 }
153
154 if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) {
154 return 0;
155 }
156
157 if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) {
155 logprintf("delete proxy arp entry: \n");
158 LogPrintf(LogERROR, "Delete proxy arp entry: %s\n", strerror(errno));
156 close(routes);
157 return 0;
158 }
159
160 close(routes);
161 return 1;
162}
163

--- 26 unchanged lines hidden (view full) ---

190
191 arpreq.arp_ha.sa_len = sizeof(struct sockaddr);
192 arpreq.arp_ha.sa_family = AF_UNSPEC;
193 BCOPY(LLADDR(&dls.sdl), arpreq.arp_ha.sa_data, dls.sdl.sdl_alen);
194 SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
195 ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
196 arpreq.arp_flags = ATF_PERM | ATF_PUBL;
197 if (ioctl(unit, SIOCSARP, (caddr_t)&arpreq) < 0) {
159 close(routes);
160 return 0;
161 }
162
163 close(routes);
164 return 1;
165}
166

--- 26 unchanged lines hidden (view full) ---

193
194 arpreq.arp_ha.sa_len = sizeof(struct sockaddr);
195 arpreq.arp_ha.sa_family = AF_UNSPEC;
196 BCOPY(LLADDR(&dls.sdl), arpreq.arp_ha.sa_data, dls.sdl.sdl_alen);
197 SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
198 ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
199 arpreq.arp_flags = ATF_PERM | ATF_PUBL;
200 if (ioctl(unit, SIOCSARP, (caddr_t)&arpreq) < 0) {
198 fprintf(stderr, "ioctl(SIOCSARP): \n");
201 LogPrintf(LogERROR, "sifproxyarp: ioctl(SIOCSARP): \n");
199 return 0;
200 }
201
202 return 1;
203}
204
205/*
206 * cifproxyarp - Delete the proxy ARP entry for the peer.

--- 4 unchanged lines hidden (view full) ---

211 u_long hisaddr;
212{
213 struct arpreq arpreq;
214
215 BZERO(&arpreq, sizeof(arpreq));
216 SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
217 ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
218 if (ioctl(unit, SIOCDARP, (caddr_t)&arpreq) < 0) {
202 return 0;
203 }
204
205 return 1;
206}
207
208/*
209 * cifproxyarp - Delete the proxy ARP entry for the peer.

--- 4 unchanged lines hidden (view full) ---

214 u_long hisaddr;
215{
216 struct arpreq arpreq;
217
218 BZERO(&arpreq, sizeof(arpreq));
219 SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
220 ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
221 if (ioctl(unit, SIOCDARP, (caddr_t)&arpreq) < 0) {
219 fprintf(stderr, "ioctl(SIOCDARP): \n");
222 LogPrintf(LogERROR, "cifproxyarp: ioctl(SIOCDARP): \n");
220 return 0;
221 }
222 return 1;
223}
224#endif /* RTM_VERSION */
225
226
227/*

--- 13 unchanged lines hidden (view full) ---

241 struct sockaddr_dl *dla;
242 struct ifreq ifreq;
243 struct ifconf ifc;
244 struct ifreq ifs[MAX_IFS];
245
246 ifc.ifc_len = sizeof(ifs);
247 ifc.ifc_req = ifs;
248 if (ioctl(s, SIOCGIFCONF, &ifc) < 0) {
223 return 0;
224 }
225 return 1;
226}
227#endif /* RTM_VERSION */
228
229
230/*

--- 13 unchanged lines hidden (view full) ---

244 struct sockaddr_dl *dla;
245 struct ifreq ifreq;
246 struct ifconf ifc;
247 struct ifreq ifs[MAX_IFS];
248
249 ifc.ifc_len = sizeof(ifs);
250 ifc.ifc_req = ifs;
251 if (ioctl(s, SIOCGIFCONF, &ifc) < 0) {
249 fprintf(stderr, "ioctl(SIOCGIFCONF): \n");
252 LogPrintf(LogERROR, "get_ether_addr: ioctl(SIOCGIFCONF): \n");
250 return 0;
251 }
252
253 /*
254 * Scan through looking for an interface with an Internet
255 * address on the same subnet as `ipaddr'.
256 */
257 ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);

--- 24 unchanged lines hidden (view full) ---

282 break;
283 }
284nextif:
285 ifr = (struct ifreq *) ((char *)&ifr->ifr_addr + ifr->ifr_addr.sa_len);
286 }
287
288 if (ifr >= ifend)
289 return 0;
253 return 0;
254 }
255
256 /*
257 * Scan through looking for an interface with an Internet
258 * address on the same subnet as `ipaddr'.
259 */
260 ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);

--- 24 unchanged lines hidden (view full) ---

285 break;
286 }
287nextif:
288 ifr = (struct ifreq *) ((char *)&ifr->ifr_addr + ifr->ifr_addr.sa_len);
289 }
290
291 if (ifr >= ifend)
292 return 0;
290 LogPrintf(LOG_PHASE_BIT, "found interface %s for proxy arp\n", ifr->ifr_name);
293 LogPrintf(LogPHASE, "Found interface %s for proxy arp\n", ifr->ifr_name);
291
292 /*
293 * Now scan through again looking for a link-level address
294 * for this interface.
295 */
296 ifp = ifr;
297 for (ifr = ifc.ifc_req; ifr < ifend; ) {
298 if (strcmp(ifp->ifr_name, ifr->ifr_name) == 0

--- 31 unchanged lines hidden (view full) ---

330 * Read kernel memory, return 0 on success.
331 */
332int
333kread(addr, buf, size)
334 u_long addr;
335 char *buf;
336 int size;
337{
294
295 /*
296 * Now scan through again looking for a link-level address
297 * for this interface.
298 */
299 ifp = ifr;
300 for (ifr = ifc.ifc_req; ifr < ifend; ) {
301 if (strcmp(ifp->ifr_name, ifr->ifr_name) == 0

--- 31 unchanged lines hidden (view full) ---

333 * Read kernel memory, return 0 on success.
334 */
335int
336kread(addr, buf, size)
337 u_long addr;
338 char *buf;
339 int size;
340{
338
339 if (kvm_read(kvmd, addr, buf, size) != size) {
340 /* XXX this duplicates kvm_read's error printout */
341 (void)fprintf(stderr, "kvm_read %s\n",
342 kvm_geterr(kvmd));
343 return (-1);
344 }
345 return (0);
341 if (kvm_read(kvmd, addr, buf, size) != size) {
342 /* XXX this duplicates kvm_read's error printout */
343 LogPrintf(LogERROR, "kvm_read %s\n", kvm_geterr(kvmd));
344 return -1;
345 }
346 return 0;
346}
347
348kmemgetether(ifname, dlo)
349char *ifname;
350struct sockaddr_dl *dlo;
351{
352 struct ifnet ifnet;
353 int n;

--- 75 unchanged lines hidden ---
347}
348
349kmemgetether(ifname, dlo)
350char *ifname;
351struct sockaddr_dl *dlo;
352{
353 struct ifnet ifnet;
354 int n;

--- 75 unchanged lines hidden ---