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