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 5d04ccbb3Scarlsonj * Common Development and Distribution License (the "License"). 6d04ccbb3Scarlsonj * 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 /* 22d04ccbb3Scarlsonj * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23d04ccbb3Scarlsonj * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _PACKET_H 277c478bd9Sstevel@tonic-gate #define _PACKET_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #include <sys/types.h> 327c478bd9Sstevel@tonic-gate #include <netinet/in.h> 337c478bd9Sstevel@tonic-gate #include <netinet/dhcp.h> 34d04ccbb3Scarlsonj #include <netinet/dhcp6.h> 357c478bd9Sstevel@tonic-gate #include <dhcp_impl.h> 367c478bd9Sstevel@tonic-gate 37d04ccbb3Scarlsonj #include "common.h" 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate /* 407c478bd9Sstevel@tonic-gate * packet.[ch] contain routines for manipulating, setting, and 417c478bd9Sstevel@tonic-gate * transmitting DHCP/BOOTP packets. see packet.c for descriptions on 427c478bd9Sstevel@tonic-gate * how to use the exported functions. 437c478bd9Sstevel@tonic-gate */ 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate #ifdef __cplusplus 467c478bd9Sstevel@tonic-gate extern "C" { 477c478bd9Sstevel@tonic-gate #endif 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate /* 507c478bd9Sstevel@tonic-gate * data type for recv_pkt(). needed because we may want to wait for 517c478bd9Sstevel@tonic-gate * several kinds of packets at once, and the existing enumeration of 527c478bd9Sstevel@tonic-gate * DHCP packet types does not provide a way to do that easily. here, 537c478bd9Sstevel@tonic-gate * we light a different bit in the enumeration for each type of packet 547c478bd9Sstevel@tonic-gate * we want to receive. 55d04ccbb3Scarlsonj * 56d04ccbb3Scarlsonj * Note that for DHCPv6, types 4 (CONFIRM), 5 (RENEW), 6 (REBIND), 12 57d04ccbb3Scarlsonj * (RELAY-FORW, and 13 (RELAY-REPL) are not in the table. They're never 58d04ccbb3Scarlsonj * received by a client, so there's no reason to process them. (SOLICIT, 59d04ccbb3Scarlsonj * REQUEST, DECLINE, RELEASE, and INFORMATION-REQUEST are also never seen by 60d04ccbb3Scarlsonj * clients, but are included for consistency.) 61d04ccbb3Scarlsonj * 62d04ccbb3Scarlsonj * Note also that the symbols are named for the DHCPv4 message types, and that 63d04ccbb3Scarlsonj * DHCPv6 has analogous message types. 647c478bd9Sstevel@tonic-gate */ 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate typedef enum { 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate DHCP_PUNTYPED = 0x001, /* untyped (BOOTP) message */ 69d04ccbb3Scarlsonj DHCP_PDISCOVER = 0x002, /* in v6: SOLICIT (1) */ 70d04ccbb3Scarlsonj DHCP_POFFER = 0x004, /* in v6: ADVERTISE (2) */ 71d04ccbb3Scarlsonj DHCP_PREQUEST = 0x008, /* in v6: REQUEST (3) */ 72d04ccbb3Scarlsonj DHCP_PDECLINE = 0x010, /* in v6: DECLINE (9) */ 73d04ccbb3Scarlsonj DHCP_PACK = 0x020, /* in v6: REPLY (7), status == 0 */ 74d04ccbb3Scarlsonj DHCP_PNAK = 0x040, /* in v6: REPLY (7), status != 0 */ 75d04ccbb3Scarlsonj DHCP_PRELEASE = 0x080, /* in v6: RELEASE (8) */ 76d04ccbb3Scarlsonj DHCP_PINFORM = 0x100, /* in v6: INFORMATION-REQUEST (11) */ 77d04ccbb3Scarlsonj DHCP_PRECONFIG = 0x200 /* v6 only: RECONFIGURE (10) */ 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate } dhcp_message_type_t; 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate /* 82d04ccbb3Scarlsonj * A dhcp_pkt_t is used by the output-side packet manipulation functions. 83d04ccbb3Scarlsonj * While the structure is not strictly necessary, it allows a better separation 84d04ccbb3Scarlsonj * of functionality since metadata about the packet (such as its current 85d04ccbb3Scarlsonj * length) is stored along with the packet. 86d04ccbb3Scarlsonj * 87d04ccbb3Scarlsonj * Note that 'pkt' points to a dhcpv6_message_t if the packet is IPv6. 887c478bd9Sstevel@tonic-gate */ 897c478bd9Sstevel@tonic-gate 90d04ccbb3Scarlsonj typedef struct dhcp_pkt_s { 917c478bd9Sstevel@tonic-gate PKT *pkt; /* the real underlying packet */ 927c478bd9Sstevel@tonic-gate unsigned int pkt_max_len; /* its maximum length */ 937c478bd9Sstevel@tonic-gate unsigned int pkt_cur_len; /* its current length */ 94d04ccbb3Scarlsonj boolean_t pkt_isv6; 957c478bd9Sstevel@tonic-gate } dhcp_pkt_t; 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate /* 987c478bd9Sstevel@tonic-gate * a `stop_func_t' is used by parts of dhcpagent that use the 997c478bd9Sstevel@tonic-gate * retransmission capability of send_pkt(). this makes it so the 1007c478bd9Sstevel@tonic-gate * callers of send_pkt() decide when to stop retransmitting, which 1017c478bd9Sstevel@tonic-gate * makes more sense than hardcoding their instance-specific cases into 1027c478bd9Sstevel@tonic-gate * packet.c 1037c478bd9Sstevel@tonic-gate */ 1047c478bd9Sstevel@tonic-gate 105d04ccbb3Scarlsonj typedef boolean_t stop_func_t(dhcp_smach_t *, unsigned int); 1067c478bd9Sstevel@tonic-gate 107d04ccbb3Scarlsonj /* 108d04ccbb3Scarlsonj * Default I/O and interface control sockets. 109d04ccbb3Scarlsonj */ 110d04ccbb3Scarlsonj extern int v6_sock_fd; 111d04ccbb3Scarlsonj extern int v4_sock_fd; 112d04ccbb3Scarlsonj 113d04ccbb3Scarlsonj extern const in6_addr_t ipv6_all_dhcp_relay_and_servers; 114d04ccbb3Scarlsonj extern const in6_addr_t my_in6addr_any; 115d04ccbb3Scarlsonj 116d04ccbb3Scarlsonj PKT_LIST *alloc_pkt_entry(size_t, boolean_t); 117d04ccbb3Scarlsonj void free_pkt_entry(PKT_LIST *); 1187c478bd9Sstevel@tonic-gate void free_pkt_list(PKT_LIST **); 119d04ccbb3Scarlsonj uchar_t pkt_recv_type(const PKT_LIST *); 120d04ccbb3Scarlsonj uint_t pkt_get_xid(const PKT *, boolean_t); 121d04ccbb3Scarlsonj dhcp_pkt_t *init_pkt(dhcp_smach_t *, uchar_t); 122d04ccbb3Scarlsonj boolean_t remove_pkt_opt(dhcp_pkt_t *, uint_t); 123d04ccbb3Scarlsonj boolean_t update_v6opt_len(dhcpv6_option_t *, int); 124d04ccbb3Scarlsonj void *add_pkt_opt(dhcp_pkt_t *, uint_t, const void *, uint_t); 125d04ccbb3Scarlsonj void *add_pkt_subopt(dhcp_pkt_t *, dhcpv6_option_t *, uint_t, 126d04ccbb3Scarlsonj const void *, uint_t); 127d04ccbb3Scarlsonj void *add_pkt_opt16(dhcp_pkt_t *, uint_t, uint16_t); 128d04ccbb3Scarlsonj void *add_pkt_opt32(dhcp_pkt_t *, uint_t, uint32_t); 129d04ccbb3Scarlsonj void *add_pkt_prl(dhcp_pkt_t *, dhcp_smach_t *); 130d04ccbb3Scarlsonj boolean_t add_pkt_lif(dhcp_pkt_t *, dhcp_lif_t *, int, const char *); 131d04ccbb3Scarlsonj void stop_pkt_retransmission(dhcp_smach_t *); 132d04ccbb3Scarlsonj void retransmit_now(dhcp_smach_t *); 133*e704a8f2Smeem PKT_LIST *recv_pkt(int, int, boolean_t); 134d04ccbb3Scarlsonj boolean_t pkt_v4_match(uchar_t, dhcp_message_type_t); 135d04ccbb3Scarlsonj void pkt_smach_enqueue(dhcp_smach_t *, PKT_LIST *); 136d04ccbb3Scarlsonj boolean_t send_pkt(dhcp_smach_t *, dhcp_pkt_t *, in_addr_t, 1377c478bd9Sstevel@tonic-gate stop_func_t *); 138d04ccbb3Scarlsonj boolean_t send_pkt_v6(dhcp_smach_t *, dhcp_pkt_t *, in6_addr_t, 139d04ccbb3Scarlsonj stop_func_t *, uint_t, uint_t); 140d04ccbb3Scarlsonj boolean_t dhcp_ip_default(void); 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1437c478bd9Sstevel@tonic-gate } 1447c478bd9Sstevel@tonic-gate #endif 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate #endif /* _PACKET_H */ 147