xref: /netbsd-src/usr.sbin/ndbootd/ndbootd.h (revision 0d0f4c1fddd8931fdfdcac0725fa8bfeb958f42c)
1 /*	$NetBSD: ndbootd.h,v 1.5 2004/01/06 23:02:55 wiz 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 #if 0
47 static const char _ndbootd_h_rcsid[] = "<<Id: ndbootd.h,v 1.3 2001/05/22 13:13:20 fredette Exp >>";
48 #endif
49 
50 /* includes: */
51 #ifdef HAVE_CONFIG_H
52 #include "config.h"
53 #endif				/* HAVE_CONFIG_H */
54 #include <assert.h>
55 #include <unistd.h>
56 #include <stdio.h>
57 #include <stdlib.h>
58 #include <string.h>
59 #include <errno.h>
60 #include <fcntl.h>
61 #include <netdb.h>
62 #include <sys/param.h>
63 #include <sys/socket.h>
64 #include <sys/stat.h>
65 #include <net/if.h>
66 #include <netinet/in_systm.h>
67 #include <netinet/in.h>
68 #if defined(HAVE_SYS_SOCKIO_H)
69 #include <sys/sockio.h>
70 #elif defined(HAVE_SYS_SOCKETIO_H)	/* HAVE_SYS_SOCKIO_H,
71 					 * HAVE_SYS_SOCKETIO_H */
72 #include <sys/socketio.h>
73 #endif				/* HAVE_SYS_SOCKETIO_H */
74 #include <sys/ioctl.h>
75 #ifdef HAVE_IOCTLS_H
76 #include <ioctls.h>
77 #endif				/* HAVE_IOCTLS_H */
78 #ifdef HAVE_NET_IF_ETHER_H
79 #include <net/if_ether.h>
80 #endif				/* HAVE_NET_IF_ETHER_H */
81 #ifdef HAVE_NET_ETHERNET_H
82 #include <net/ethernet.h>
83 #endif				/* HAVE_NET_ETHERNET_H */
84 #include <netinet/ip.h>
85 #ifdef HAVE_NET_IF_DL_H
86 #include <net/if_dl.h>
87 #endif				/* HAVE_NET_IF_DL_H */
88 #include <arpa/inet.h>
89 #include <ifaddrs.h>
90 
91 /* macros: */
92 #ifdef __STDC__
93 #define _NDBOOTD_P(x) x
94 #else				/* !__STDC__ */
95 #define _NDBOOTD_P(x)
96 #endif				/* !__STDC__ */
97 #undef FALSE
98 #undef TRUE
99 #define FALSE (0)
100 #define TRUE (!FALSE)
101 #ifndef HAVE_STRERROR
102 #define strerror(e) ((e) < sys_nerr ? sys_errlist[e] : "unknown error")
103 #endif				/* !HAVE_STRERROR */
104 #ifndef MAX
105 #define MAX(a, b) ((a) > (b) ? (a) : (b))
106 #endif				/* !MAX */
107 #ifndef MIN
108 #define MIN(a, b) ((a) < (b) ? (a) : (b))
109 #endif				/* !MIN */
110 #if 1
111 #define _NDBOOTD_DO_DEBUG
112 #endif
113 #ifdef _NDBOOTD_DO_DEBUG
114 #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)
115 #else				/* !_NDBOOTD_DO_DEBUG */
116 #define _NDBOOTD_DEBUG(x)
117 #endif				/* !_NDBOOTD_DO_DEBUG */
118 #define NDBOOTD_PID_FILE "/var/run/ndbootd.pid"
119 
120 #define NDBOOTD_OFFSETOF(t, m) (((char *) &(((t *) NULL)-> m)) - ((char *) ((t *) NULL)))
121 
122 #define NDBOOT_OP_READ      (0x01)
123 #define NDBOOT_OP_WRITE     (0x02)
124 #define NDBOOT_OP_ERROR     (0x03)
125 #define NDBOOT_OP_MASK      (0x07)
126 #define NDBOOT_OP_FLAG_WAIT (1 << 3)
127 #define NDBOOT_OP_FLAG_DONE (1 << 4)
128 #define NDBOOT_MAX_PACKET_DATA (1024)
129 #define NDBOOT_MAX_BYTE_COUNT  (63 * 1024)
130 #define NDBOOT_WINDOW_SIZE_DEFAULT (6)
131 #define NDBOOT_BSIZE        (512)
132 #define NDBOOT_MINOR_NDP0   (0x40)
133 #undef IPPROTO_ND
134 #define IPPROTO_ND 77
135 
136 /* structures: */
137 
138 /* our network interface: */
139 struct ndbootd_interface {
140 
141 	/* the interface: */
142 	struct ifreq *ndbootd_interface_ifreq;
143 
144 	/* our Ethernet address: */
145 	u_int8_t ndbootd_interface_ether[ETHER_ADDR_LEN];
146 
147 	/* the socket for the interface: */
148 	int ndbootd_interface_fd;
149 
150 	/* private data for the raw interface: */
151 	void *_ndbootd_interface_raw_private;
152 };
153 /* the Sun Network Disk (nd) packet format: */
154 struct ndboot_packet {
155 
156 	/* the operation code: */
157 	u_int8_t ndboot_packet_op;
158 
159 	/* the minor device: */
160 	u_int8_t ndboot_packet_minor;
161 
162 	/* any error: */
163 	int8_t ndboot_packet_error;
164 
165 	/* the disk version number: */
166 	int8_t ndboot_packet_disk_version;
167 
168 	/* the sequence number: */
169 	int32_t ndboot_packet_sequence;
170 
171 	/* the disk block number: */
172 	int32_t ndboot_packet_block_number;
173 
174 	/* the byte count: */
175 	int32_t ndboot_packet_byte_count;
176 
177 	/* the residual byte count: */
178 	int32_t ndboot_packet_residual_byte_count;
179 
180 	/* the current byte offset: */
181 	int32_t ndboot_packet_current_byte_offset;
182 
183 	/* the current byte count: */
184 	int32_t ndboot_packet_current_byte_count;
185 };
186 
187 /* prototypes: */
188 int ndbootd_raw_open _NDBOOTD_P((struct ndbootd_interface *));
189 int ndbootd_raw_read _NDBOOTD_P((struct ndbootd_interface *, void *, size_t));
190 int ndbootd_raw_write _NDBOOTD_P((struct ndbootd_interface *, void *, size_t));
191 
192 #endif				/* !_NDBOOTD_H */
193