xref: /netbsd-src/usr.sbin/ndbootd/ndbootd.h (revision 1ca5c1b28139779176bd5c13ad7c5f25c0bcd5f8)
1 /*	$NetBSD: ndbootd.h,v 1.2 2001/05/22 14:41:59 fredette Exp $	*/
2 
3 /* ndbootd.h - header file for the Sun Network Disk (nd) daemon: */
4 
5 /*
6  * Copyright (c) 2001 Matthew Fredette.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *   1. Redistributions of source code must retain the above copyright
12  *      notice, this list of conditions and the following disclaimer.
13  *   2. Redistributions in binary form must reproduce the above copyright
14  *      notice, this list of conditions and the following disclaimer in the
15  *      documentation and/or other materials provided with the distribution.
16  *   3. All advertising materials mentioning features or use of this software
17  *      must display the following acknowledgement:
18  *        This product includes software developed by Matthew Fredette.
19  *   4. The name of Matthew Fredette may not be used to endorse or promote
20  *      products derived from this software without specific prior written
21  *      permission.
22  *
23  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
24  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
25  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
26  */
27 
28 /* <<Header: /data/home/fredette/project/THE-WEIGHT-CVS/ndbootd/ndbootd.h,v 1.3 2001/05/22 13:13:20 fredette Exp >> */
29 
30 /*
31  * <<Log: ndbootd.h,v >>
32  * Revision 1.3  2001/05/22 13:13:20  fredette
33  * Ran indent(1) with NetBSD's KNF-approximating profile.
34  *
35  * Revision 1.2  2001/01/31 17:35:16  fredette
36  * Now include param.h.
37  *
38  * Revision 1.1  2001/01/29 15:12:13  fredette
39  * Added.
40  *
41  */
42 
43 #ifndef _NDBOOTD_H
44 #define _NDBOOTD_H
45 
46 static const char _ndbootd_h_rcsid[] = "<<Id: ndbootd.h,v 1.3 2001/05/22 13:13:20 fredette Exp >>";
47 
48 /* includes: */
49 #ifdef HAVE_CONFIG_H
50 #include "config.h"
51 #endif				/* HAVE_CONFIG_H */
52 #include <assert.h>
53 #include <unistd.h>
54 #include <stdio.h>
55 #include <stdlib.h>
56 #include <string.h>
57 #include <errno.h>
58 #include <fcntl.h>
59 #include <netdb.h>
60 #include <sys/param.h>
61 #include <sys/socket.h>
62 #include <sys/stat.h>
63 #include <net/if.h>
64 #include <netinet/in_systm.h>
65 #include <netinet/in.h>
66 #if defined(HAVE_SYS_SOCKIO_H)
67 #include <sys/sockio.h>
68 #elif defined(HAVE_SYS_SOCKETIO_H)	/* HAVE_SYS_SOCKIO_H,
69 					 * HAVE_SYS_SOCKETIO_H */
70 #include <sys/socketio.h>
71 #endif				/* HAVE_SYS_SOCKETIO_H */
72 #include <sys/ioctl.h>
73 #ifdef HAVE_IOCTLS_H
74 #include <ioctls.h>
75 #endif				/* HAVE_IOCTLS_H */
76 #ifdef HAVE_NET_IF_ETHER_H
77 #include <net/if_ether.h>
78 #endif				/* HAVE_NET_IF_ETHER_H */
79 #ifdef HAVE_NET_ETHERNET_H
80 #include <net/ethernet.h>
81 #endif				/* HAVE_NET_ETHERNET_H */
82 #include <netinet/ip.h>
83 #ifdef HAVE_NET_IF_DL_H
84 #include <net/if_dl.h>
85 #endif				/* HAVE_NET_IF_DL_H */
86 #include <arpa/inet.h>
87 
88 /* macros: */
89 #ifdef __STDC__
90 #define _NDBOOTD_P(x) x
91 #else				/* !__STDC__ */
92 #define _NDBOOTD_P(x)
93 #endif				/* !__STDC__ */
94 #undef FALSE
95 #undef TRUE
96 #define FALSE (0)
97 #define TRUE (!FALSE)
98 #ifndef HAVE_STRERROR
99 #define strerror(e) ((e) < sys_nerr ? sys_errlist[e] : "unknown error")
100 #endif				/* !HAVE_STRERROR */
101 #ifndef MAX
102 #define MAX(a, b) ((a) < (b) ? (a) : (b))
103 #endif				/* !MAX */
104 #ifndef MIN
105 #define MIN(a, b) ((a) < (b) ? (a) : (b))
106 #endif				/* !MIN */
107 #if 1
108 #define _NDBOOTD_DO_DEBUG
109 #endif
110 #ifdef _NDBOOTD_DO_DEBUG
111 #define _NDBOOTD_DEBUG(x) do { if (_ndbootd_debug) { FILE *fp; int saved_errno; fp = stderr; saved_errno = errno; fprintf(fp, "%s: ", _ndbootd_argv0); errno = saved_errno; fprintf x ; fputc('\n', fp); errno = saved_errno; } } while(0)
112 #else				/* !_NDBOOTD_DO_DEBUG */
113 #define _NDBOOTD_DEBUG(x)
114 #endif				/* !_NDBOOTD_DO_DEBUG */
115 #define NDBOOTD_PID_FILE "/var/run/ndbootd.pid"
116 
117 #define NDBOOTD_OFFSETOF(t, m) (((char *) &(((t *) NULL)-> m)) - ((char *) ((t *) NULL)))
118 
119 #define NDBOOT_OP_READ      (0x01)
120 #define NDBOOT_OP_WRITE     (0x02)
121 #define NDBOOT_OP_ERROR     (0x03)
122 #define NDBOOT_OP_MASK      (0x07)
123 #define NDBOOT_OP_FLAG_WAIT (1 << 3)
124 #define NDBOOT_OP_FLAG_DONE (1 << 4)
125 #define NDBOOT_MAX_PACKET_DATA (1024)
126 #define NDBOOT_MAX_BYTE_COUNT  (63 * 1024)
127 #define NDBOOT_WINDOW_SIZE_DEFAULT (6)
128 #define NDBOOT_BSIZE        (512)
129 #define NDBOOT_MINOR_NDP0   (0x40)
130 #undef IPPROTO_ND
131 #define IPPROTO_ND 77
132 
133 /* structures: */
134 
135 /* our network interface: */
136 struct ndbootd_interface {
137 
138 	/* the interface: */
139 	struct ifreq *ndbootd_interface_ifreq;
140 
141 	/* our Ethernet address: */
142 	u_int8_t ndbootd_interface_ether[ETHER_ADDR_LEN];
143 
144 	/* the socket for the interface: */
145 	int ndbootd_interface_fd;
146 
147 	/* private data for the raw interface: */
148 	void *_ndbootd_interface_raw_private;
149 };
150 /* the Sun Network Disk (nd) packet format: */
151 struct ndboot_packet {
152 
153 	/* the operation code: */
154 	u_int8_t ndboot_packet_op;
155 
156 	/* the minor device: */
157 	u_int8_t ndboot_packet_minor;
158 
159 	/* any error: */
160 	int8_t ndboot_packet_error;
161 
162 	/* the disk version number: */
163 	int8_t ndboot_packet_disk_version;
164 
165 	/* the sequence number: */
166 	int32_t ndboot_packet_sequence;
167 
168 	/* the disk block number: */
169 	int32_t ndboot_packet_block_number;
170 
171 	/* the byte count: */
172 	int32_t ndboot_packet_byte_count;
173 
174 	/* the residual byte count: */
175 	int32_t ndboot_packet_residual_byte_count;
176 
177 	/* the current byte offset: */
178 	int32_t ndboot_packet_current_byte_offset;
179 
180 	/* the current byte count: */
181 	int32_t ndboot_packet_current_byte_count;
182 };
183 
184 /* prototypes: */
185 int ndbootd_raw_open _NDBOOTD_P((struct ndbootd_interface *));
186 int ndbootd_raw_read _NDBOOTD_P((struct ndbootd_interface *, void *, size_t));
187 int ndbootd_raw_write _NDBOOTD_P((struct ndbootd_interface *, void *, size_t));
188 
189 #endif				/* !_NDBOOTD_H */
190