10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*3431Scarlsonj * Common Development and Distribution License (the "License"). 6*3431Scarlsonj * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*3431Scarlsonj * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _DHCP_IMPL_H 270Sstevel@tonic-gate #define _DHCP_IMPL_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 300Sstevel@tonic-gate 310Sstevel@tonic-gate /* 320Sstevel@tonic-gate * Common definitions used by Sun DHCP implementations 330Sstevel@tonic-gate */ 340Sstevel@tonic-gate 350Sstevel@tonic-gate #ifdef __cplusplus 360Sstevel@tonic-gate extern "C" { 370Sstevel@tonic-gate #endif 380Sstevel@tonic-gate 390Sstevel@tonic-gate #include <sys/types.h> 400Sstevel@tonic-gate #include <sys/socket.h> 410Sstevel@tonic-gate #include <netinet/in.h> 420Sstevel@tonic-gate #include <netinet/udp.h> 430Sstevel@tonic-gate #include <netinet/dhcp.h> 44*3431Scarlsonj #include <netinet/dhcp6.h> 450Sstevel@tonic-gate #include <dhcp_symbol_common.h> 460Sstevel@tonic-gate #include <sys/sunos_dhcp_class.h> 470Sstevel@tonic-gate 480Sstevel@tonic-gate /* Packet fields */ 490Sstevel@tonic-gate #define CD_PACKET_START 0 500Sstevel@tonic-gate #define CD_POPCODE 0 /* packet opcode */ 510Sstevel@tonic-gate #define CD_PHTYPE 1 /* packet header type */ 520Sstevel@tonic-gate #define CD_PHLEN 2 /* packet header len */ 530Sstevel@tonic-gate #define CD_PHOPS 3 /* packet header len */ 540Sstevel@tonic-gate #define CD_PXID 4 /* packet hops */ 550Sstevel@tonic-gate #define CD_PSECS 8 /* packet xid */ 560Sstevel@tonic-gate #define CD_PFLAGS 10 /* packet secs */ 570Sstevel@tonic-gate #define CD_PCIADDR 12 /* packet flags */ 580Sstevel@tonic-gate #define CD_YIADDR 16 /* client's ip address */ 590Sstevel@tonic-gate #define CD_SIADDR 20 /* Bootserver's ip address */ 600Sstevel@tonic-gate #define CD_GIADDR 24 /* BOOTP relay agent address */ 610Sstevel@tonic-gate #define CD_PCHADDR 28 /* BOOTP relay agent address */ 620Sstevel@tonic-gate #define CD_SNAME 44 /* Hostname of Bootserver, or opts */ 630Sstevel@tonic-gate #define CD_BOOTFILE 108 /* File to boot or opts */ 640Sstevel@tonic-gate #define CD_PCOOKIE 236 /* packet cookie */ 650Sstevel@tonic-gate #define CD_POPTIONS 240 /* packet options */ 660Sstevel@tonic-gate #define CD_PACKET_END CD_POPTIONS 670Sstevel@tonic-gate 680Sstevel@tonic-gate /* Internal server options */ 690Sstevel@tonic-gate #define CD_INTRNL_START 1024 700Sstevel@tonic-gate #define CD_BOOL_HOSTNAME 1024 /* Entry wants hostname (Nameserv) */ 710Sstevel@tonic-gate #define CD_BOOL_LEASENEG 1025 /* Entry's lease is negotiable */ 720Sstevel@tonic-gate #define CD_BOOL_ECHO_VCLASS 1026 /* Echo Vendor class back to Entry */ 730Sstevel@tonic-gate #define CD_BOOTPATH 1027 /* prefix path to File to boot */ 740Sstevel@tonic-gate #define CD_INTRNL_END 1027 750Sstevel@tonic-gate 760Sstevel@tonic-gate /* Error codes that could be generated while parsing packets */ 770Sstevel@tonic-gate #define DHCP_ERR_OFFSET 512 780Sstevel@tonic-gate #define DHCP_GARBLED_MSG_TYPE (DHCP_ERR_OFFSET+0) 790Sstevel@tonic-gate #define DHCP_WRONG_MSG_TYPE (DHCP_ERR_OFFSET+1) 800Sstevel@tonic-gate #define DHCP_BAD_OPT_OVLD (DHCP_ERR_OFFSET+2) 810Sstevel@tonic-gate 820Sstevel@tonic-gate /* 830Sstevel@tonic-gate * Arbitrary "maximum" client ID length (in bytes), used by various bits 840Sstevel@tonic-gate * of the standalone code. This needs to go away someday. 850Sstevel@tonic-gate */ 860Sstevel@tonic-gate #define DHCP_MAX_CID_LEN 64 870Sstevel@tonic-gate 880Sstevel@tonic-gate /* 890Sstevel@tonic-gate * Generic DHCP option structure. 900Sstevel@tonic-gate */ 910Sstevel@tonic-gate typedef struct { 920Sstevel@tonic-gate uint8_t code; 930Sstevel@tonic-gate uint8_t len; 940Sstevel@tonic-gate uint8_t value[1]; 950Sstevel@tonic-gate } DHCP_OPT; 960Sstevel@tonic-gate 97*3431Scarlsonj typedef union sockaddr46_s { 98*3431Scarlsonj struct sockaddr_in v4; 99*3431Scarlsonj struct sockaddr_in6 v6; 100*3431Scarlsonj } sockaddr46_t; 101*3431Scarlsonj 1020Sstevel@tonic-gate /* 1030Sstevel@tonic-gate * Generic DHCP packet list. Ensure that _REENTRANT bracketed code stays at 1040Sstevel@tonic-gate * bottom of this definition - the client doesn't include it. Scan.c in 1050Sstevel@tonic-gate * libdhcp isn't aware of it either... 106*3431Scarlsonj * 107*3431Scarlsonj * The PKT * pointer here actually points to a dhcpv6_message_t if the packet 108*3431Scarlsonj * is DHCPv6. We assume that PKT * the same or stricter alignment 109*3431Scarlsonj * requirements, and that the unused elements are not a significant burden. 1100Sstevel@tonic-gate */ 1110Sstevel@tonic-gate #define MAX_PKT_LIST 5 /* maximum list size */ 1120Sstevel@tonic-gate typedef struct dhcp_list { 113*3431Scarlsonj struct dhcp_list *next; /* keep first and in this */ 114*3431Scarlsonj struct dhcp_list *prev; /* order for insque/remque */ 115*3431Scarlsonj 1160Sstevel@tonic-gate PKT *pkt; /* client packet */ 1170Sstevel@tonic-gate uint_t len; /* packet len */ 1180Sstevel@tonic-gate int rfc1048; /* RFC1048 options - boolean */ 1190Sstevel@tonic-gate uint8_t offset; /* BOOTP packet offset */ 120*3431Scarlsonj uint8_t isv6; /* DHCPv6 packet - boolean */ 1210Sstevel@tonic-gate /* 1220Sstevel@tonic-gate * standard/site options 1230Sstevel@tonic-gate */ 1240Sstevel@tonic-gate DHCP_OPT *opts[DHCP_LAST_OPT + 1]; 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate /* 1270Sstevel@tonic-gate * Vendor specific options (client only) 1280Sstevel@tonic-gate */ 1290Sstevel@tonic-gate DHCP_OPT *vs[VS_OPTION_END - VS_OPTION_START + 1]; 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate struct in_addr off_ip; /* Address OFFERed */ 1320Sstevel@tonic-gate 133*3431Scarlsonj uint_t ifindex; /* received ifindex (if any) */ 134*3431Scarlsonj sockaddr46_t pktfrom; /* source (peer) address on input */ 135*3431Scarlsonj sockaddr46_t pktto; /* destination (local) address */ 136*3431Scarlsonj 1370Sstevel@tonic-gate } PKT_LIST; 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate extern int dhcp_options_scan(PKT_LIST *, boolean_t); 1400Sstevel@tonic-gate extern boolean_t dhcp_getinfo_pl(PKT_LIST *, uchar_t, uint16_t, uint16_t, 1410Sstevel@tonic-gate void *, size_t *); 142*3431Scarlsonj extern dhcpv6_option_t *dhcpv6_find_option(const void *, size_t, 143*3431Scarlsonj const dhcpv6_option_t *, uint16_t, uint_t *); 144*3431Scarlsonj extern dhcpv6_option_t *dhcpv6_pkt_option(const PKT_LIST *, 145*3431Scarlsonj const dhcpv6_option_t *, uint16_t, uint_t *); 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate #ifdef __cplusplus 1480Sstevel@tonic-gate } 1490Sstevel@tonic-gate #endif 1500Sstevel@tonic-gate 1510Sstevel@tonic-gate #endif /* _DHCP_IMPL_H */ 152