| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: isibootd.c,v 1.1 2011/12/17 13:24:18 tsutsui Exp $ */ | | 1 | /* $NetBSD: isibootd.c,v 1.2 2011/12/18 14:45:23 tsutsui Exp $ */ |
2 | /* Id: isiboot.c,v 1.2 1999/12/26 14:33:33 nisimura Exp */ | | 2 | /* Id: isiboot.c,v 1.2 1999/12/26 14:33:33 nisimura Exp */ |
3 | | | 3 | |
4 | /*- | | 4 | /*- |
5 | * Copyright (c) 2000, 2011 The NetBSD Foundation, Inc. | | 5 | * Copyright (c) 2000, 2011 The NetBSD Foundation, Inc. |
6 | * All rights reserved. | | 6 | * All rights reserved. |
7 | * | | 7 | * |
8 | * This code is derived from software contributed to The NetBSD Foundation | | 8 | * This code is derived from software contributed to The NetBSD Foundation |
9 | * by Tohru Nishimura. | | 9 | * by Tohru Nishimura. |
10 | * | | 10 | * |
11 | * Redistribution and use in source and binary forms, with or without | | 11 | * Redistribution and use in source and binary forms, with or without |
12 | * modification, are permitted provided that the following conditions | | 12 | * modification, are permitted provided that the following conditions |
13 | * are met: | | 13 | * are met: |
14 | * 1. Redistributions of source code must retain the above copyright | | 14 | * 1. Redistributions of source code must retain the above copyright |
| @@ -52,39 +52,39 @@ | | | @@ -52,39 +52,39 @@ |
52 | #include <stdlib.h> | | 52 | #include <stdlib.h> |
53 | #include <string.h> | | 53 | #include <string.h> |
54 | #include <unistd.h> | | 54 | #include <unistd.h> |
55 | #include <util.h> | | 55 | #include <util.h> |
56 | | | 56 | |
57 | #define TRACE(l, x) if ((l) <= dbg) printf x | | 57 | #define TRACE(l, x) if ((l) <= dbg) printf x |
58 | | | 58 | |
59 | /* | | 59 | /* |
60 | * TRFS (Integrated Solutions Inc. Transparent Remote File System) frame | | 60 | * TRFS (Integrated Solutions Inc. Transparent Remote File System) frame |
61 | * | | 61 | * |
62 | * Following data format depends on m68k order, and aligned harmful | | 62 | * Following data format depends on m68k order, and aligned harmful |
63 | * to RISC processors. | | 63 | * to RISC processors. |
64 | */ | | 64 | */ |
65 | #define FRAMETYPE 0x80df | | 65 | #define TRFS_FRAMETYPE 0x80df |
66 | #define FRAMELEN 1468 | | 66 | #define TRFS_FRAMELEN 1468 |
67 | struct frame { | | 67 | struct frame { |
68 | uint8_t dst[ETHER_ADDR_LEN]; | | 68 | uint8_t dst[ETHER_ADDR_LEN]; |
69 | uint8_t src[ETHER_ADDR_LEN]; | | 69 | uint8_t src[ETHER_ADDR_LEN]; |
70 | uint16_t type; | | 70 | uint16_t type; |
71 | uint16_t pad_0; | | 71 | uint16_t pad_0; |
72 | uint16_t seqno; | | 72 | uint16_t seqno; |
73 | uint8_t opcode; | | 73 | uint8_t opcode; |
74 | uint8_t pad_1; | | 74 | uint8_t pad_1; |
75 | uint8_t pos[4]; | | 75 | uint8_t pos[4]; |
76 | uint8_t siz[4]; | | 76 | uint8_t siz[4]; |
77 | uint8_t data[FRAMELEN - 28]; | | 77 | uint8_t data[TRFS_FRAMELEN - 28]; |
78 | } __packed; | | 78 | } __packed; |
79 | | | 79 | |
80 | struct station { | | 80 | struct station { |
81 | int fd; | | 81 | int fd; |
82 | char name[MAXHOSTNAMELEN]; | | 82 | char name[MAXHOSTNAMELEN]; |
83 | char ifname[IFNAMSIZ]; | | 83 | char ifname[IFNAMSIZ]; |
84 | uint8_t addr[ETHER_ADDR_LEN]; | | 84 | uint8_t addr[ETHER_ADDR_LEN]; |
85 | } station; | | 85 | } station; |
86 | | | 86 | |
87 | struct session { | | 87 | struct session { |
88 | struct session *next; | | 88 | struct session *next; |
89 | int state; | | 89 | int state; |
90 | FILE *file; | | 90 | FILE *file; |
| @@ -102,27 +102,27 @@ static __unused const char *state[] = { | | | @@ -102,27 +102,27 @@ static __unused const char *state[] = { |
102 | #define READ 2 | | 102 | #define READ 2 |
103 | #define CLOSE 4 | | 103 | #define CLOSE 4 |
104 | static __unused const char *op[] = | | 104 | static __unused const char *op[] = |
105 | { "CONNECT", "OPEN", "READ", "WRITE", "CLOSE", "FIND" }; | | 105 | { "CONNECT", "OPEN", "READ", "WRITE", "CLOSE", "FIND" }; |
106 | | | 106 | |
107 | static void createbpfport(char *, uint8_t **, size_t *, struct station *); | | 107 | static void createbpfport(char *, uint8_t **, size_t *, struct station *); |
108 | static struct session *search(uint8_t *); | | 108 | static struct session *search(uint8_t *); |
109 | static void closedown(struct session *); | | 109 | static void closedown(struct session *); |
110 | static void makepool(void); | | 110 | static void makepool(void); |
111 | static char *etheraddr(uint8_t *); | | 111 | static char *etheraddr(uint8_t *); |
112 | static int pickif(char *, uint8_t *); | | 112 | static int pickif(char *, uint8_t *); |
113 | static __dead void usage(void); | | 113 | static __dead void usage(void); |
114 | | | 114 | |
115 | #define FRAME(buf) ((buf) + ((struct bpf_hdr *)(buf))->bh_hdrlen) | | 115 | #define TRFS_FRAME(buf) ((buf) + ((struct bpf_hdr *)(buf))->bh_hdrlen) |
116 | | | 116 | |
117 | #define PATH_DEFBOOTDIR "/tftpboot" | | 117 | #define PATH_DEFBOOTDIR "/tftpboot" |
118 | | | 118 | |
119 | int | | 119 | int |
120 | main(int argc, char *argv[]) | | 120 | main(int argc, char *argv[]) |
121 | { | | 121 | { |
122 | int cc, dbg, dflag; | | 122 | int cc, dbg, dflag; |
123 | size_t iolen; | | 123 | size_t iolen; |
124 | uint32_t pos, siz; | | 124 | uint32_t pos, siz; |
125 | size_t nread; | | 125 | size_t nread; |
126 | char *ifname, *p; | | 126 | char *ifname, *p; |
127 | const char *bootwd, *servername, *filename; | | 127 | const char *bootwd, *servername, *filename; |
128 | uint8_t *iobuf; | | 128 | uint8_t *iobuf; |
| @@ -175,27 +175,27 @@ main(int argc, char *argv[]) | | | @@ -175,27 +175,27 @@ main(int argc, char *argv[]) |
175 | #ifdef __NetBSD__ | | 175 | #ifdef __NetBSD__ |
176 | pidfile(NULL); | | 176 | pidfile(NULL); |
177 | #endif | | 177 | #endif |
178 | } | | 178 | } |
179 | | | 179 | |
180 | if (chdir(bootwd) < 0) | | 180 | if (chdir(bootwd) < 0) |
181 | err(EXIT_FAILURE, "can not chdir to %s", bootwd); | | 181 | err(EXIT_FAILURE, "can not chdir to %s", bootwd); |
182 | | | 182 | |
183 | pollfd.fd = station.fd; | | 183 | pollfd.fd = station.fd; |
184 | pollfd.events = POLLIN; | | 184 | pollfd.events = POLLIN; |
185 | for (;;) { | | 185 | for (;;) { |
186 | poll(&pollfd, 1, INFTIM); | | 186 | poll(&pollfd, 1, INFTIM); |
187 | read(pollfd.fd, iobuf, iolen); /* returns 1468 */ | | 187 | read(pollfd.fd, iobuf, iolen); /* returns 1468 */ |
188 | fp = (struct frame *)FRAME(iobuf); | | 188 | fp = (struct frame *)TRFS_FRAME(iobuf); |
189 | | | 189 | |
190 | /* ignore own TX packets */ | | 190 | /* ignore own TX packets */ |
191 | if (memcmp(fp->src, station.addr, ETHER_ADDR_LEN) == 0) | | 191 | if (memcmp(fp->src, station.addr, ETHER_ADDR_LEN) == 0) |
192 | continue; | | 192 | continue; |
193 | | | 193 | |
194 | /* check if the received Ethernet address is in ethers(5) */ | | 194 | /* check if the received Ethernet address is in ethers(5) */ |
195 | if (ether_ntohost(clientname, (struct ether_addr *)fp->src)) { | | 195 | if (ether_ntohost(clientname, (struct ether_addr *)fp->src)) { |
196 | TRACE(3, ("'%s' is not in ethers(5)\n", | | 196 | TRACE(3, ("'%s' is not in ethers(5)\n", |
197 | etheraddr(fp->src))); | | 197 | etheraddr(fp->src))); |
198 | continue; | | 198 | continue; |
199 | } | | 199 | } |
200 | /* check if the client has a valid hostname */ | | 200 | /* check if the client has a valid hostname */ |
201 | clientname[sizeof(clientname) - 1] = '\0'; | | 201 | clientname[sizeof(clientname) - 1] = '\0'; |
| @@ -259,27 +259,27 @@ main(int argc, char *argv[]) | | | @@ -259,27 +259,27 @@ main(int argc, char *argv[]) |
259 | be32enc(fp->siz, 0); /* corrupted file */ | | 259 | be32enc(fp->siz, 0); /* corrupted file */ |
260 | } | | 260 | } |
261 | TRACE(3, ("%u@%u\n", siz, pos)); | | 261 | TRACE(3, ("%u@%u\n", siz, pos)); |
262 | break; | | 262 | break; |
263 | aborting: | | 263 | aborting: |
264 | TRACE(1, ("out of phase\n")); | | 264 | TRACE(1, ("out of phase\n")); |
265 | closedown: | | 265 | closedown: |
266 | closedown(cp); | | 266 | closedown(cp); |
267 | fp->opcode = CLOSE; | | 267 | fp->opcode = CLOSE; |
268 | break; | | 268 | break; |
269 | } | | 269 | } |
270 | memcpy(fp->dst, fp->src, ETHER_ADDR_LEN); | | 270 | memcpy(fp->dst, fp->src, ETHER_ADDR_LEN); |
271 | memcpy(fp->src, station.addr, ETHER_ADDR_LEN); | | 271 | memcpy(fp->src, station.addr, ETHER_ADDR_LEN); |
272 | write(pollfd.fd, fp, FRAMELEN); | | 272 | write(pollfd.fd, fp, TRFS_FRAMELEN); |
273 | } | | 273 | } |
274 | /* NOTREACHED */ | | 274 | /* NOTREACHED */ |
275 | } | | 275 | } |
276 | | | 276 | |
277 | struct session * | | 277 | struct session * |
278 | search(uint8_t *client) | | 278 | search(uint8_t *client) |
279 | { | | 279 | { |
280 | struct session *cp; | | 280 | struct session *cp; |
281 | | | 281 | |
282 | for (cp = activelist; cp; cp = cp->next) { | | 282 | for (cp = activelist; cp; cp = cp->next) { |
283 | if (memcmp(client, cp->addr, ETHER_ADDR_LEN) == 0) | | 283 | if (memcmp(client, cp->addr, ETHER_ADDR_LEN) == 0) |
284 | return cp; | | 284 | return cp; |
285 | } | | 285 | } |
| @@ -338,28 +338,28 @@ makepool(void) | | | @@ -338,28 +338,28 @@ makepool(void) |
338 | | | 338 | |
339 | char * | | 339 | char * |
340 | etheraddr(uint8_t *e) | | 340 | etheraddr(uint8_t *e) |
341 | { | | 341 | { |
342 | static char address[sizeof("xx:xx:xx:xx:xx:xx")]; | | 342 | static char address[sizeof("xx:xx:xx:xx:xx:xx")]; |
343 | | | 343 | |
344 | snprintf(address, sizeof(address), "%02x:%02x:%02x:%02x:%02x:%02x", | | 344 | snprintf(address, sizeof(address), "%02x:%02x:%02x:%02x:%02x:%02x", |
345 | e[0], e[1], e[2], e[3], e[4], e[5]); | | 345 | e[0], e[1], e[2], e[3], e[4], e[5]); |
346 | return address; | | 346 | return address; |
347 | } | | 347 | } |
348 | | | 348 | |
349 | static struct bpf_insn bpf_insn[] = { | | 349 | static struct bpf_insn bpf_insn[] = { |
350 | { BPF_LD|BPF_H|BPF_ABS, 0, 0, offsetof(struct frame, type) }, | | 350 | { BPF_LD|BPF_H|BPF_ABS, 0, 0, offsetof(struct frame, type) }, |
351 | { BPF_JMP|BPF_JEQ|BPF_K, 0, 1, FRAMETYPE }, | | 351 | { BPF_JMP|BPF_JEQ|BPF_K, 0, 1, TRFS_FRAMETYPE }, |
352 | { BPF_RET|BPF_K, 0, 0, FRAMELEN }, | | 352 | { BPF_RET|BPF_K, 0, 0, TRFS_FRAMELEN }, |
353 | { BPF_RET|BPF_K, 0, 0, 0x0 } | | 353 | { BPF_RET|BPF_K, 0, 0, 0x0 } |
354 | }; | | 354 | }; |
355 | static struct bpf_program bpf_pgm = { | | 355 | static struct bpf_program bpf_pgm = { |
356 | sizeof(bpf_insn) / sizeof(bpf_insn[0]), | | 356 | sizeof(bpf_insn) / sizeof(bpf_insn[0]), |
357 | bpf_insn | | 357 | bpf_insn |
358 | }; | | 358 | }; |
359 | | | 359 | |
360 | void | | 360 | void |
361 | createbpfport(char *ifname, uint8_t **iobufp, size_t *iolenp, | | 361 | createbpfport(char *ifname, uint8_t **iobufp, size_t *iolenp, |
362 | struct station *st) | | 362 | struct station *st) |
363 | { | | 363 | { |
364 | struct ifreq ifr; | | 364 | struct ifreq ifr; |
365 | int fd; | | 365 | int fd; |