xref: /netbsd/usr.sbin/ndbootd/ndbootd.h (revision bf9ec67e)
1 /*	$NetBSD: ndbootd.h,v 1.3 2002/04/09 02:39:14 thorpej 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 
90 /* macros: */
91 #ifdef __STDC__
92 #define _NDBOOTD_P(x) x
93 #else				/* !__STDC__ */
94 #define _NDBOOTD_P(x)
95 #endif				/* !__STDC__ */
96 #undef FALSE
97 #undef TRUE
98 #define FALSE (0)
99 #define TRUE (!FALSE)
100 #ifndef HAVE_STRERROR
101 #define strerror(e) ((e) < sys_nerr ? sys_errlist[e] : "unknown error")
102 #endif				/* !HAVE_STRERROR */
103 #ifndef MAX
104 #define MAX(a, b) ((a) < (b) ? (a) : (b))
105 #endif				/* !MAX */
106 #ifndef MIN
107 #define MIN(a, b) ((a) < (b) ? (a) : (b))
108 #endif				/* !MIN */
109 #if 1
110 #define _NDBOOTD_DO_DEBUG
111 #endif
112 #ifdef _NDBOOTD_DO_DEBUG
113 #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)
114 #else				/* !_NDBOOTD_DO_DEBUG */
115 #define _NDBOOTD_DEBUG(x)
116 #endif				/* !_NDBOOTD_DO_DEBUG */
117 #define NDBOOTD_PID_FILE "/var/run/ndbootd.pid"
118 
119 #define NDBOOTD_OFFSETOF(t, m) (((char *) &(((t *) NULL)-> m)) - ((char *) ((t *) NULL)))
120 
121 #define NDBOOT_OP_READ      (0x01)
122 #define NDBOOT_OP_WRITE     (0x02)
123 #define NDBOOT_OP_ERROR     (0x03)
124 #define NDBOOT_OP_MASK      (0x07)
125 #define NDBOOT_OP_FLAG_WAIT (1 << 3)
126 #define NDBOOT_OP_FLAG_DONE (1 << 4)
127 #define NDBOOT_MAX_PACKET_DATA (1024)
128 #define NDBOOT_MAX_BYTE_COUNT  (63 * 1024)
129 #define NDBOOT_WINDOW_SIZE_DEFAULT (6)
130 #define NDBOOT_BSIZE        (512)
131 #define NDBOOT_MINOR_NDP0   (0x40)
132 #undef IPPROTO_ND
133 #define IPPROTO_ND 77
134 
135 /* structures: */
136 
137 /* our network interface: */
138 struct ndbootd_interface {
139 
140 	/* the interface: */
141 	struct ifreq *ndbootd_interface_ifreq;
142 
143 	/* our Ethernet address: */
144 	u_int8_t ndbootd_interface_ether[ETHER_ADDR_LEN];
145 
146 	/* the socket for the interface: */
147 	int ndbootd_interface_fd;
148 
149 	/* private data for the raw interface: */
150 	void *_ndbootd_interface_raw_private;
151 };
152 /* the Sun Network Disk (nd) packet format: */
153 struct ndboot_packet {
154 
155 	/* the operation code: */
156 	u_int8_t ndboot_packet_op;
157 
158 	/* the minor device: */
159 	u_int8_t ndboot_packet_minor;
160 
161 	/* any error: */
162 	int8_t ndboot_packet_error;
163 
164 	/* the disk version number: */
165 	int8_t ndboot_packet_disk_version;
166 
167 	/* the sequence number: */
168 	int32_t ndboot_packet_sequence;
169 
170 	/* the disk block number: */
171 	int32_t ndboot_packet_block_number;
172 
173 	/* the byte count: */
174 	int32_t ndboot_packet_byte_count;
175 
176 	/* the residual byte count: */
177 	int32_t ndboot_packet_residual_byte_count;
178 
179 	/* the current byte offset: */
180 	int32_t ndboot_packet_current_byte_offset;
181 
182 	/* the current byte count: */
183 	int32_t ndboot_packet_current_byte_count;
184 };
185 
186 /* prototypes: */
187 int ndbootd_raw_open _NDBOOTD_P((struct ndbootd_interface *));
188 int ndbootd_raw_read _NDBOOTD_P((struct ndbootd_interface *, void *, size_t));
189 int ndbootd_raw_write _NDBOOTD_P((struct ndbootd_interface *, void *, size_t));
190 
191 #endif				/* !_NDBOOTD_H */
192