packet.h revision 4456:35ab34adfdad
150477Speter/* 222377Spst * CDDL HEADER START 322401Sphk * 422377Spst * The contents of this file are subject to the terms of the 522377Spst * Common Development and Distribution License (the "License"). 622377Spst * You may not use this file except in compliance with the License. 788857Sache * 822377Spst * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 979467Smarkm * or http://www.opensolaris.org/os/licensing. 1079467Smarkm * See the License for the specific language governing permissions 1122377Spst * and limitations under the License. 1222377Spst * 1379467Smarkm * When distributing Covered Code, include this CDDL HEADER in each 1483391Sru * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1578644Sache * If applicable, add the following below this CDDL HEADER, with the 1679467Smarkm * fields enclosed by brackets "[]" replaced with your own identifying 1722377Spst * information: Portions Copyright [yyyy] [name of copyright owner] 1822377Spst * 1922377Spst * CDDL HEADER END 2022377Spst */ 21/* 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26#ifndef _PACKET_H 27#define _PACKET_H 28 29#pragma ident "%Z%%M% %I% %E% SMI" 30 31#include <sys/types.h> 32#include <netinet/in.h> 33#include <netinet/dhcp.h> 34#include <netinet/dhcp6.h> 35#include <dhcp_impl.h> 36 37#include "common.h" 38 39/* 40 * packet.[ch] contain routines for manipulating, setting, and 41 * transmitting DHCP/BOOTP packets. see packet.c for descriptions on 42 * how to use the exported functions. 43 */ 44 45#ifdef __cplusplus 46extern "C" { 47#endif 48 49/* 50 * data type for recv_pkt(). needed because we may want to wait for 51 * several kinds of packets at once, and the existing enumeration of 52 * DHCP packet types does not provide a way to do that easily. here, 53 * we light a different bit in the enumeration for each type of packet 54 * we want to receive. 55 * 56 * Note that for DHCPv6, types 4 (CONFIRM), 5 (RENEW), 6 (REBIND), 12 57 * (RELAY-FORW, and 13 (RELAY-REPL) are not in the table. They're never 58 * received by a client, so there's no reason to process them. (SOLICIT, 59 * REQUEST, DECLINE, RELEASE, and INFORMATION-REQUEST are also never seen by 60 * clients, but are included for consistency.) 61 * 62 * Note also that the symbols are named for the DHCPv4 message types, and that 63 * DHCPv6 has analogous message types. 64 */ 65 66typedef enum { 67 68 DHCP_PUNTYPED = 0x001, /* untyped (BOOTP) message */ 69 DHCP_PDISCOVER = 0x002, /* in v6: SOLICIT (1) */ 70 DHCP_POFFER = 0x004, /* in v6: ADVERTISE (2) */ 71 DHCP_PREQUEST = 0x008, /* in v6: REQUEST (3) */ 72 DHCP_PDECLINE = 0x010, /* in v6: DECLINE (9) */ 73 DHCP_PACK = 0x020, /* in v6: REPLY (7), status == 0 */ 74 DHCP_PNAK = 0x040, /* in v6: REPLY (7), status != 0 */ 75 DHCP_PRELEASE = 0x080, /* in v6: RELEASE (8) */ 76 DHCP_PINFORM = 0x100, /* in v6: INFORMATION-REQUEST (11) */ 77 DHCP_PRECONFIG = 0x200 /* v6 only: RECONFIGURE (10) */ 78 79} dhcp_message_type_t; 80 81/* 82 * A dhcp_pkt_t is used by the output-side packet manipulation functions. 83 * While the structure is not strictly necessary, it allows a better separation 84 * of functionality since metadata about the packet (such as its current 85 * length) is stored along with the packet. 86 * 87 * Note that 'pkt' points to a dhcpv6_message_t if the packet is IPv6. 88 */ 89 90typedef struct dhcp_pkt_s { 91 PKT *pkt; /* the real underlying packet */ 92 unsigned int pkt_max_len; /* its maximum length */ 93 unsigned int pkt_cur_len; /* its current length */ 94 boolean_t pkt_isv6; 95} dhcp_pkt_t; 96 97/* 98 * a `stop_func_t' is used by parts of dhcpagent that use the 99 * retransmission capability of send_pkt(). this makes it so the 100 * callers of send_pkt() decide when to stop retransmitting, which 101 * makes more sense than hardcoding their instance-specific cases into 102 * packet.c 103 */ 104 105typedef boolean_t stop_func_t(dhcp_smach_t *, unsigned int); 106 107/* 108 * Default I/O and interface control sockets. 109 */ 110extern int v6_sock_fd; 111extern int v4_sock_fd; 112 113extern const in6_addr_t ipv6_all_dhcp_relay_and_servers; 114extern const in6_addr_t my_in6addr_any; 115 116PKT_LIST *alloc_pkt_entry(size_t, boolean_t); 117void free_pkt_entry(PKT_LIST *); 118void free_pkt_list(PKT_LIST **); 119uchar_t pkt_recv_type(const PKT_LIST *); 120uint_t pkt_get_xid(const PKT *, boolean_t); 121dhcp_pkt_t *init_pkt(dhcp_smach_t *, uchar_t); 122boolean_t remove_pkt_opt(dhcp_pkt_t *, uint_t); 123boolean_t update_v6opt_len(dhcpv6_option_t *, int); 124void *add_pkt_opt(dhcp_pkt_t *, uint_t, const void *, uint_t); 125void *add_pkt_subopt(dhcp_pkt_t *, dhcpv6_option_t *, uint_t, 126 const void *, uint_t); 127void *add_pkt_opt16(dhcp_pkt_t *, uint_t, uint16_t); 128void *add_pkt_opt32(dhcp_pkt_t *, uint_t, uint32_t); 129void *add_pkt_prl(dhcp_pkt_t *, dhcp_smach_t *); 130boolean_t add_pkt_lif(dhcp_pkt_t *, dhcp_lif_t *, int, const char *); 131void stop_pkt_retransmission(dhcp_smach_t *); 132void retransmit_now(dhcp_smach_t *); 133PKT_LIST *recv_pkt(int, int, boolean_t, boolean_t, dhcp_pif_t *); 134boolean_t pkt_v4_match(uchar_t, dhcp_message_type_t); 135void pkt_smach_enqueue(dhcp_smach_t *, PKT_LIST *); 136boolean_t send_pkt(dhcp_smach_t *, dhcp_pkt_t *, in_addr_t, 137 stop_func_t *); 138boolean_t send_pkt_v6(dhcp_smach_t *, dhcp_pkt_t *, in6_addr_t, 139 stop_func_t *, uint_t, uint_t); 140boolean_t dhcp_ip_default(void); 141 142#ifdef __cplusplus 143} 144#endif 145 146#endif /* _PACKET_H */ 147