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 53431Scarlsonj * Common Development and Distribution License (the "License"). 63431Scarlsonj * 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 /* 223431Scarlsonj * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 233431Scarlsonj * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _PACKET_H 270Sstevel@tonic-gate #define _PACKET_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 300Sstevel@tonic-gate 310Sstevel@tonic-gate #include <sys/types.h> 320Sstevel@tonic-gate #include <netinet/in.h> 330Sstevel@tonic-gate #include <netinet/dhcp.h> 343431Scarlsonj #include <netinet/dhcp6.h> 350Sstevel@tonic-gate #include <dhcp_impl.h> 360Sstevel@tonic-gate 373431Scarlsonj #include "common.h" 380Sstevel@tonic-gate 390Sstevel@tonic-gate /* 400Sstevel@tonic-gate * packet.[ch] contain routines for manipulating, setting, and 410Sstevel@tonic-gate * transmitting DHCP/BOOTP packets. see packet.c for descriptions on 420Sstevel@tonic-gate * how to use the exported functions. 430Sstevel@tonic-gate */ 440Sstevel@tonic-gate 450Sstevel@tonic-gate #ifdef __cplusplus 460Sstevel@tonic-gate extern "C" { 470Sstevel@tonic-gate #endif 480Sstevel@tonic-gate 490Sstevel@tonic-gate /* 500Sstevel@tonic-gate * data type for recv_pkt(). needed because we may want to wait for 510Sstevel@tonic-gate * several kinds of packets at once, and the existing enumeration of 520Sstevel@tonic-gate * DHCP packet types does not provide a way to do that easily. here, 530Sstevel@tonic-gate * we light a different bit in the enumeration for each type of packet 540Sstevel@tonic-gate * we want to receive. 553431Scarlsonj * 563431Scarlsonj * Note that for DHCPv6, types 4 (CONFIRM), 5 (RENEW), 6 (REBIND), 12 573431Scarlsonj * (RELAY-FORW, and 13 (RELAY-REPL) are not in the table. They're never 583431Scarlsonj * received by a client, so there's no reason to process them. (SOLICIT, 593431Scarlsonj * REQUEST, DECLINE, RELEASE, and INFORMATION-REQUEST are also never seen by 603431Scarlsonj * clients, but are included for consistency.) 613431Scarlsonj * 623431Scarlsonj * Note also that the symbols are named for the DHCPv4 message types, and that 633431Scarlsonj * DHCPv6 has analogous message types. 640Sstevel@tonic-gate */ 650Sstevel@tonic-gate 660Sstevel@tonic-gate typedef enum { 670Sstevel@tonic-gate 680Sstevel@tonic-gate DHCP_PUNTYPED = 0x001, /* untyped (BOOTP) message */ 693431Scarlsonj DHCP_PDISCOVER = 0x002, /* in v6: SOLICIT (1) */ 703431Scarlsonj DHCP_POFFER = 0x004, /* in v6: ADVERTISE (2) */ 713431Scarlsonj DHCP_PREQUEST = 0x008, /* in v6: REQUEST (3) */ 723431Scarlsonj DHCP_PDECLINE = 0x010, /* in v6: DECLINE (9) */ 733431Scarlsonj DHCP_PACK = 0x020, /* in v6: REPLY (7), status == 0 */ 743431Scarlsonj DHCP_PNAK = 0x040, /* in v6: REPLY (7), status != 0 */ 753431Scarlsonj DHCP_PRELEASE = 0x080, /* in v6: RELEASE (8) */ 763431Scarlsonj DHCP_PINFORM = 0x100, /* in v6: INFORMATION-REQUEST (11) */ 773431Scarlsonj DHCP_PRECONFIG = 0x200 /* v6 only: RECONFIGURE (10) */ 780Sstevel@tonic-gate 790Sstevel@tonic-gate } dhcp_message_type_t; 800Sstevel@tonic-gate 810Sstevel@tonic-gate /* 823431Scarlsonj * A dhcp_pkt_t is used by the output-side packet manipulation functions. 833431Scarlsonj * While the structure is not strictly necessary, it allows a better separation 843431Scarlsonj * of functionality since metadata about the packet (such as its current 853431Scarlsonj * length) is stored along with the packet. 863431Scarlsonj * 873431Scarlsonj * Note that 'pkt' points to a dhcpv6_message_t if the packet is IPv6. 880Sstevel@tonic-gate */ 890Sstevel@tonic-gate 903431Scarlsonj typedef struct dhcp_pkt_s { 910Sstevel@tonic-gate PKT *pkt; /* the real underlying packet */ 920Sstevel@tonic-gate unsigned int pkt_max_len; /* its maximum length */ 930Sstevel@tonic-gate unsigned int pkt_cur_len; /* its current length */ 943431Scarlsonj boolean_t pkt_isv6; 950Sstevel@tonic-gate } dhcp_pkt_t; 960Sstevel@tonic-gate 970Sstevel@tonic-gate /* 980Sstevel@tonic-gate * a `stop_func_t' is used by parts of dhcpagent that use the 990Sstevel@tonic-gate * retransmission capability of send_pkt(). this makes it so the 1000Sstevel@tonic-gate * callers of send_pkt() decide when to stop retransmitting, which 1010Sstevel@tonic-gate * makes more sense than hardcoding their instance-specific cases into 1020Sstevel@tonic-gate * packet.c 1030Sstevel@tonic-gate */ 1040Sstevel@tonic-gate 1053431Scarlsonj typedef boolean_t stop_func_t(dhcp_smach_t *, unsigned int); 1060Sstevel@tonic-gate 1073431Scarlsonj /* 1083431Scarlsonj * Default I/O and interface control sockets. 1093431Scarlsonj */ 1103431Scarlsonj extern int v6_sock_fd; 1113431Scarlsonj extern int v4_sock_fd; 1123431Scarlsonj 1133431Scarlsonj extern const in6_addr_t ipv6_all_dhcp_relay_and_servers; 1143431Scarlsonj extern const in6_addr_t my_in6addr_any; 1153431Scarlsonj 1163431Scarlsonj PKT_LIST *alloc_pkt_entry(size_t, boolean_t); 1173431Scarlsonj void free_pkt_entry(PKT_LIST *); 1180Sstevel@tonic-gate void free_pkt_list(PKT_LIST **); 1193431Scarlsonj uchar_t pkt_recv_type(const PKT_LIST *); 1203431Scarlsonj uint_t pkt_get_xid(const PKT *, boolean_t); 1213431Scarlsonj dhcp_pkt_t *init_pkt(dhcp_smach_t *, uchar_t); 1223431Scarlsonj boolean_t remove_pkt_opt(dhcp_pkt_t *, uint_t); 1233431Scarlsonj boolean_t update_v6opt_len(dhcpv6_option_t *, int); 1243431Scarlsonj void *add_pkt_opt(dhcp_pkt_t *, uint_t, const void *, uint_t); 1253431Scarlsonj void *add_pkt_subopt(dhcp_pkt_t *, dhcpv6_option_t *, uint_t, 1263431Scarlsonj const void *, uint_t); 1273431Scarlsonj void *add_pkt_opt16(dhcp_pkt_t *, uint_t, uint16_t); 1283431Scarlsonj void *add_pkt_opt32(dhcp_pkt_t *, uint_t, uint32_t); 1293431Scarlsonj void *add_pkt_prl(dhcp_pkt_t *, dhcp_smach_t *); 1303431Scarlsonj boolean_t add_pkt_lif(dhcp_pkt_t *, dhcp_lif_t *, int, const char *); 1313431Scarlsonj void stop_pkt_retransmission(dhcp_smach_t *); 1323431Scarlsonj void retransmit_now(dhcp_smach_t *); 133*5381Smeem PKT_LIST *recv_pkt(int, int, boolean_t); 1343431Scarlsonj boolean_t pkt_v4_match(uchar_t, dhcp_message_type_t); 1353431Scarlsonj void pkt_smach_enqueue(dhcp_smach_t *, PKT_LIST *); 1363431Scarlsonj boolean_t send_pkt(dhcp_smach_t *, dhcp_pkt_t *, in_addr_t, 1370Sstevel@tonic-gate stop_func_t *); 1383431Scarlsonj boolean_t send_pkt_v6(dhcp_smach_t *, dhcp_pkt_t *, in6_addr_t, 1393431Scarlsonj stop_func_t *, uint_t, uint_t); 1403431Scarlsonj boolean_t dhcp_ip_default(void); 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate #ifdef __cplusplus 1430Sstevel@tonic-gate } 1440Sstevel@tonic-gate #endif 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate #endif /* _PACKET_H */ 147