1 /* $OpenBSD: ipx.h,v 1.18 2003/10/26 17:01:11 avsm Exp $ */ 2 3 /*- 4 * 5 * Copyright (c) 1996 Michael Shalayeff 6 * Copyright (c) 1995, Mike Mitchell 7 * Copyright (c) 1984, 1985, 1986, 1987, 1993 8 * The Regents of the University of California. All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)ipx.h 35 * 36 * from FreeBSD Id: ipx.h,v 1.7 1996/01/30 22:58:48 mpp Exp 37 */ 38 39 #ifndef _NETIPX_IPX_H_ 40 #define _NETIPX_IPX_H_ 41 42 /* 43 * Constants and Structures 44 */ 45 46 /* 47 * Protocols 48 */ 49 #define IPXPROTO_UNKWN 0 /* Unknown */ 50 #define IPXPROTO_RI 1 /* RIP Routing Information */ 51 #define IPXPROTO_PXP 4 /* IPX Packet Exchange Protocol */ 52 #define IPXPROTO_SPX 5 /* SPX Sequenced Packet */ 53 #define IPXPROTO_NCP 17 /* NCP NetWare Core */ 54 #define IPXPROTO_NETBIOS 20 /* Propagated Packet */ 55 #define IPXPROTO_RAW 255 /* Placemarker*/ 56 #define IPXPROTO_MAX 256 /* Placemarker*/ 57 58 /* 59 * Port/Socket numbers: network standard functions 60 */ 61 62 #define IPXPORT_RI 1 /* NS RIP Routing Information */ 63 #define IPXPORT_ECHO 2 /* NS Echo */ 64 #define IPXPORT_RE 3 /* NS Router Error */ 65 #define IPXPORT_FSP 0x0451 /* NW NCP Core Protocol */ 66 #define IPXPORT_SAP 0x0452 /* NW SAP Service Advertising */ 67 #define IPXPORT_RIP 0x0453 /* NW RIP Routing Information */ 68 #define IPXPORT_NETBIOS 0x0455 /* NW NetBIOS */ 69 #define IPXPORT_DIAGS 0x0456 /* NW Diagnostics */ 70 #define IPXPORT_SERIAL 0x0457 /* NW Serialization */ 71 #define IPXPORT_NLSP 0x9001 /* NW NLSP */ 72 #define IPXPORT_WAN 0x9004 /* NW IPXWAN */ 73 #define IPXPORT_PING 0x9086 /* NW IPX Ping */ 74 #define IPXPORT_MOBILE 0x9088 /* NW Mobile IPX Socket */ 75 /* 76 * Ports < IPXPORT_RESERVED are reserved for privileged 77 */ 78 #define IPXPORT_RESERVED 0x4000 79 /* 80 * Ports > IPXPORT_WELLKNOWN are reserved for privileged 81 * processes (e.g. root). 82 */ 83 #define IPXPORT_WELLKNOWN 0x6000 84 85 /* flags passed to ipx_outputfl as last parameter */ 86 87 #define IPX_FORWARDING 0x1 /* most of ipx header exists */ 88 #define IPX_ROUTETOIF 0x10 /* same as SO_DONTROUTE */ 89 #define IPX_ALLOWBROADCAST SO_BROADCAST /* can send broadcast packets */ 90 91 #define IPX_MAXHOPS 15 92 93 /* flags passed to get/set socket option */ 94 #define SO_HEADERS_ON_INPUT 1 95 #define SO_HEADERS_ON_OUTPUT 2 96 #define SO_DEFAULT_HEADERS 3 97 #define SO_LAST_HEADER 4 98 #define SO_IPXIP_ROUTE 5 99 #define SO_SEQNO 6 100 #define SO_ALL_PACKETS 7 101 #define SO_MTU 8 102 #define SO_IPXTUN_ROUTE 9 103 #define SO_IPX_CHECKSUM 10 104 105 /* 106 * IPX addressing 107 */ 108 #define IPX_HOSTADDRLEN 6 109 #define IPX_NETADDRLEN 4 110 111 typedef 112 union ipx_host { 113 u_int8_t c_host[IPX_HOSTADDRLEN] __packed; 114 u_int16_t s_host[IPX_HOSTADDRLEN/2] __packed; 115 } ipx_host_t; 116 117 typedef 118 union ipx_net { 119 u_int8_t c_net[IPX_NETADDRLEN] __packed; 120 u_int16_t s_net[IPX_NETADDRLEN/2] __packed; 121 u_int32_t l_net __packed; 122 } ipx_net_t; 123 124 typedef u_int16_t ipx_port_t; 125 126 typedef 127 struct ipx_addr { 128 ipx_net_t ipx_net __packed; 129 ipx_host_t ipx_host __packed; 130 ipx_port_t ipx_port __packed; 131 } ipx_addr_t; 132 133 /* 134 * Socket address 135 */ 136 struct sockaddr_ipx { 137 u_int8_t sipx_len; 138 u_int8_t sipx_family; 139 u_int16_t sipx_type; 140 struct ipx_addr sipx_addr; 141 }; 142 #define sipx_net sipx_addr.ipx_net 143 #define sipx_network sipx_addr.ipx_net.l_net 144 #define sipx_node sipx_addr.ipx_host.c_host 145 #define sipx_port sipx_addr.ipx_port 146 147 /* 148 * Definitions for IPX Internet Datagram Protocol 149 */ 150 struct ipx { 151 u_int16_t ipx_sum __packed; /* Checksum */ 152 u_int16_t ipx_len __packed; /* Length, in bytes, including header */ 153 u_int8_t ipx_tc __packed; /* Transport Control (i.e. hop count) */ 154 u_int8_t ipx_pt __packed; /* Packet Type (i.e. lev 2 protocol) */ 155 ipx_addr_t ipx_dna __packed; /* Destination Network Address */ 156 ipx_addr_t ipx_sna __packed; /* Source Network Address */ 157 }; 158 159 #define ipx_neteqnn(a,b) \ 160 (((a).s_net[0]==(b).s_net[0]) && ((a).s_net[1]==(b).s_net[1])) 161 #define ipx_neteq(a,b) ipx_neteqnn((a).ipx_net, (b).ipx_net) 162 #define satoipx_addr(sa) (((struct sockaddr_ipx *)&(sa))->sipx_addr) 163 #define ipx_hosteqnh(s,t) ((s).s_host[0] == (t).s_host[0] && \ 164 (s).s_host[1] == (t).s_host[1] && (s).s_host[2] == (t).s_host[2]) 165 #define ipx_hosteq(s,t) (ipx_hosteqnh((s).ipx_host,(t).ipx_host)) 166 #define ipx_nullnet(x) \ 167 (((x).ipx_net.s_net[0]==0) && ((x).ipx_net.s_net[1]==0)) 168 #define ipx_nullhost(x) (((x).ipx_host.s_host[0]==0) && \ 169 ((x).ipx_host.s_host[1]==0) && ((x).ipx_host.s_host[2]==0)) 170 #define ipx_wildnet(x) (((x).ipx_net.s_net[0]==0xffff) && \ 171 ((x).ipx_net.s_net[1]==0xffff)) 172 #define ipx_wildhost(x) (((x).ipx_host.s_host[0]==0xffff) && \ 173 ((x).ipx_host.s_host[1]==0xffff) && ((x).ipx_host.s_host[2]==0xffff)) 174 175 /* 176 * Definitions for inet sysctl operations. 177 * 178 * Third level is protocol number. 179 * Fourth level is desired variable within that protocol. 180 */ 181 #define IPXPROTO_MAXID (IPXPROTO_SPX + 1) /* don't list to IPPROTO_MAX */ 182 183 #define CTL_IPXPROTO_NAMES { \ 184 { "ipx", CTLTYPE_NODE }, \ 185 { 0, 0 }, \ 186 { 0, 0 }, \ 187 { 0, 0 }, \ 188 { 0, 0 }, \ 189 { "spx", CTLTYPE_NODE }, \ 190 } 191 192 #ifdef _KERNEL 193 194 #define satosipx(a) ((struct sockaddr_ipx *)(a)) 195 #define sipxtosa(a) ((struct sockaddr *)(a)) 196 197 extern int ipxcksum; 198 extern int ipxforwarding; 199 extern int ipxnetbios; 200 extern struct domain ipxdomain; 201 extern struct sockaddr_ipx ipx_netmask; 202 extern struct sockaddr_ipx ipx_hostmask; 203 204 extern union ipx_net ipx_zeronet; 205 extern union ipx_host ipx_zerohost; 206 extern union ipx_net ipx_broadnet; 207 extern union ipx_host ipx_broadhost; 208 209 extern u_long ipx_pexseq; 210 extern u_char ipxctlerrmap[]; 211 212 struct route; 213 struct sockaddr; 214 struct socket; 215 struct ipxpcb; 216 void ipx_abort(struct ipxpcb *ipxp); 217 u_short ipx_cksum(struct mbuf *m, int len); 218 int ipx_control(struct socket *so, u_long cmd, caddr_t data, 219 struct ifnet *ifp); 220 void *ipx_ctlinput(int cmd, struct sockaddr *arg_as_sa, void *dummy); 221 int ipx_ctloutput(int req, struct socket *so, int level, int name, 222 struct mbuf **value); 223 int ipx_do_route(struct ipx_addr *src, struct route *ro); 224 void ipx_drop(struct ipxpcb *ipxp, int errno); 225 void ipx_forward(struct mbuf *m); 226 void ipx_init(void); 227 void ipx_input(struct mbuf *, ...); 228 void ipxintr(void); 229 int ipx_output(struct mbuf *m0, ...); 230 int ipx_outputfl(struct mbuf *m0, struct route *ro, int flags); 231 int ipx_output_type20(struct mbuf *m); 232 int ipx_raw_usrreq(struct socket *so, int req, struct mbuf *m, 233 struct mbuf *nam, struct mbuf *control); 234 void ipx_undo_route(struct route *ro); 235 int ipx_usrreq(struct socket *so, int req, struct mbuf *m, 236 struct mbuf *nam, struct mbuf *control); 237 void ipx_watch_output(struct mbuf *m, struct ifnet *ifp); 238 int ipx_sysctl(int *, u_int, void *, size_t *, void *, size_t); 239 void ipx_printhost(struct ipx_addr *addr); 240 241 #endif /* _KERNEL */ 242 243 #include <sys/cdefs.h> 244 245 __BEGIN_DECLS 246 struct ipx_addr ipx_addr(const char *); 247 char *ipx_ntoa(struct ipx_addr); 248 __END_DECLS 249 250 #endif /* !_NETIPX_IPX_H_ */ 251