17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*d04ccbb3Scarlsonj * Common Development and Distribution License (the "License"). 6*d04ccbb3Scarlsonj * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*d04ccbb3Scarlsonj * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _DHCP_IMPL_H 277c478bd9Sstevel@tonic-gate #define _DHCP_IMPL_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate /* 327c478bd9Sstevel@tonic-gate * Common definitions used by Sun DHCP implementations 337c478bd9Sstevel@tonic-gate */ 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #ifdef __cplusplus 367c478bd9Sstevel@tonic-gate extern "C" { 377c478bd9Sstevel@tonic-gate #endif 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #include <sys/types.h> 407c478bd9Sstevel@tonic-gate #include <sys/socket.h> 417c478bd9Sstevel@tonic-gate #include <netinet/in.h> 427c478bd9Sstevel@tonic-gate #include <netinet/udp.h> 437c478bd9Sstevel@tonic-gate #include <netinet/dhcp.h> 44*d04ccbb3Scarlsonj #include <netinet/dhcp6.h> 457c478bd9Sstevel@tonic-gate #include <dhcp_symbol_common.h> 467c478bd9Sstevel@tonic-gate #include <sys/sunos_dhcp_class.h> 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate /* Packet fields */ 497c478bd9Sstevel@tonic-gate #define CD_PACKET_START 0 507c478bd9Sstevel@tonic-gate #define CD_POPCODE 0 /* packet opcode */ 517c478bd9Sstevel@tonic-gate #define CD_PHTYPE 1 /* packet header type */ 527c478bd9Sstevel@tonic-gate #define CD_PHLEN 2 /* packet header len */ 537c478bd9Sstevel@tonic-gate #define CD_PHOPS 3 /* packet header len */ 547c478bd9Sstevel@tonic-gate #define CD_PXID 4 /* packet hops */ 557c478bd9Sstevel@tonic-gate #define CD_PSECS 8 /* packet xid */ 567c478bd9Sstevel@tonic-gate #define CD_PFLAGS 10 /* packet secs */ 577c478bd9Sstevel@tonic-gate #define CD_PCIADDR 12 /* packet flags */ 587c478bd9Sstevel@tonic-gate #define CD_YIADDR 16 /* client's ip address */ 597c478bd9Sstevel@tonic-gate #define CD_SIADDR 20 /* Bootserver's ip address */ 607c478bd9Sstevel@tonic-gate #define CD_GIADDR 24 /* BOOTP relay agent address */ 617c478bd9Sstevel@tonic-gate #define CD_PCHADDR 28 /* BOOTP relay agent address */ 627c478bd9Sstevel@tonic-gate #define CD_SNAME 44 /* Hostname of Bootserver, or opts */ 637c478bd9Sstevel@tonic-gate #define CD_BOOTFILE 108 /* File to boot or opts */ 647c478bd9Sstevel@tonic-gate #define CD_PCOOKIE 236 /* packet cookie */ 657c478bd9Sstevel@tonic-gate #define CD_POPTIONS 240 /* packet options */ 667c478bd9Sstevel@tonic-gate #define CD_PACKET_END CD_POPTIONS 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate /* Internal server options */ 697c478bd9Sstevel@tonic-gate #define CD_INTRNL_START 1024 707c478bd9Sstevel@tonic-gate #define CD_BOOL_HOSTNAME 1024 /* Entry wants hostname (Nameserv) */ 717c478bd9Sstevel@tonic-gate #define CD_BOOL_LEASENEG 1025 /* Entry's lease is negotiable */ 727c478bd9Sstevel@tonic-gate #define CD_BOOL_ECHO_VCLASS 1026 /* Echo Vendor class back to Entry */ 737c478bd9Sstevel@tonic-gate #define CD_BOOTPATH 1027 /* prefix path to File to boot */ 747c478bd9Sstevel@tonic-gate #define CD_INTRNL_END 1027 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate /* Error codes that could be generated while parsing packets */ 777c478bd9Sstevel@tonic-gate #define DHCP_ERR_OFFSET 512 787c478bd9Sstevel@tonic-gate #define DHCP_GARBLED_MSG_TYPE (DHCP_ERR_OFFSET+0) 797c478bd9Sstevel@tonic-gate #define DHCP_WRONG_MSG_TYPE (DHCP_ERR_OFFSET+1) 807c478bd9Sstevel@tonic-gate #define DHCP_BAD_OPT_OVLD (DHCP_ERR_OFFSET+2) 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate /* 837c478bd9Sstevel@tonic-gate * Arbitrary "maximum" client ID length (in bytes), used by various bits 847c478bd9Sstevel@tonic-gate * of the standalone code. This needs to go away someday. 857c478bd9Sstevel@tonic-gate */ 867c478bd9Sstevel@tonic-gate #define DHCP_MAX_CID_LEN 64 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate /* 897c478bd9Sstevel@tonic-gate * Generic DHCP option structure. 907c478bd9Sstevel@tonic-gate */ 917c478bd9Sstevel@tonic-gate typedef struct { 927c478bd9Sstevel@tonic-gate uint8_t code; 937c478bd9Sstevel@tonic-gate uint8_t len; 947c478bd9Sstevel@tonic-gate uint8_t value[1]; 957c478bd9Sstevel@tonic-gate } DHCP_OPT; 967c478bd9Sstevel@tonic-gate 97*d04ccbb3Scarlsonj typedef union sockaddr46_s { 98*d04ccbb3Scarlsonj struct sockaddr_in v4; 99*d04ccbb3Scarlsonj struct sockaddr_in6 v6; 100*d04ccbb3Scarlsonj } sockaddr46_t; 101*d04ccbb3Scarlsonj 1027c478bd9Sstevel@tonic-gate /* 1037c478bd9Sstevel@tonic-gate * Generic DHCP packet list. Ensure that _REENTRANT bracketed code stays at 1047c478bd9Sstevel@tonic-gate * bottom of this definition - the client doesn't include it. Scan.c in 1057c478bd9Sstevel@tonic-gate * libdhcp isn't aware of it either... 106*d04ccbb3Scarlsonj * 107*d04ccbb3Scarlsonj * The PKT * pointer here actually points to a dhcpv6_message_t if the packet 108*d04ccbb3Scarlsonj * is DHCPv6. We assume that PKT * the same or stricter alignment 109*d04ccbb3Scarlsonj * requirements, and that the unused elements are not a significant burden. 1107c478bd9Sstevel@tonic-gate */ 1117c478bd9Sstevel@tonic-gate #define MAX_PKT_LIST 5 /* maximum list size */ 1127c478bd9Sstevel@tonic-gate typedef struct dhcp_list { 113*d04ccbb3Scarlsonj struct dhcp_list *next; /* keep first and in this */ 114*d04ccbb3Scarlsonj struct dhcp_list *prev; /* order for insque/remque */ 115*d04ccbb3Scarlsonj 1167c478bd9Sstevel@tonic-gate PKT *pkt; /* client packet */ 1177c478bd9Sstevel@tonic-gate uint_t len; /* packet len */ 1187c478bd9Sstevel@tonic-gate int rfc1048; /* RFC1048 options - boolean */ 1197c478bd9Sstevel@tonic-gate uint8_t offset; /* BOOTP packet offset */ 120*d04ccbb3Scarlsonj uint8_t isv6; /* DHCPv6 packet - boolean */ 1217c478bd9Sstevel@tonic-gate /* 1227c478bd9Sstevel@tonic-gate * standard/site options 1237c478bd9Sstevel@tonic-gate */ 1247c478bd9Sstevel@tonic-gate DHCP_OPT *opts[DHCP_LAST_OPT + 1]; 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate /* 1277c478bd9Sstevel@tonic-gate * Vendor specific options (client only) 1287c478bd9Sstevel@tonic-gate */ 1297c478bd9Sstevel@tonic-gate DHCP_OPT *vs[VS_OPTION_END - VS_OPTION_START + 1]; 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate struct in_addr off_ip; /* Address OFFERed */ 1327c478bd9Sstevel@tonic-gate 133*d04ccbb3Scarlsonj uint_t ifindex; /* received ifindex (if any) */ 134*d04ccbb3Scarlsonj sockaddr46_t pktfrom; /* source (peer) address on input */ 135*d04ccbb3Scarlsonj sockaddr46_t pktto; /* destination (local) address */ 136*d04ccbb3Scarlsonj 1377c478bd9Sstevel@tonic-gate } PKT_LIST; 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate extern int dhcp_options_scan(PKT_LIST *, boolean_t); 1407c478bd9Sstevel@tonic-gate extern boolean_t dhcp_getinfo_pl(PKT_LIST *, uchar_t, uint16_t, uint16_t, 1417c478bd9Sstevel@tonic-gate void *, size_t *); 142*d04ccbb3Scarlsonj extern dhcpv6_option_t *dhcpv6_find_option(const void *, size_t, 143*d04ccbb3Scarlsonj const dhcpv6_option_t *, uint16_t, uint_t *); 144*d04ccbb3Scarlsonj extern dhcpv6_option_t *dhcpv6_pkt_option(const PKT_LIST *, 145*d04ccbb3Scarlsonj const dhcpv6_option_t *, uint16_t, uint_t *); 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1487c478bd9Sstevel@tonic-gate } 1497c478bd9Sstevel@tonic-gate #endif 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate #endif /* _DHCP_IMPL_H */ 152