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 /*
220a3e1f6cSVasumathi Sundaram  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
23*b31320a7SChris Fraire  * Copyright (c) 2016-2017, Chris Fraire <cfraire@me.com>.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	UTIL_H
277c478bd9Sstevel@tonic-gate #define	UTIL_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <netinet/in.h>
317c478bd9Sstevel@tonic-gate #include <netinet/dhcp.h>
32d04ccbb3Scarlsonj #include <netinet/dhcp6.h>
337c478bd9Sstevel@tonic-gate #include <libinetutil.h>
347c478bd9Sstevel@tonic-gate #include <dhcpagent_ipc.h>
357c478bd9Sstevel@tonic-gate 
36d04ccbb3Scarlsonj #include "common.h"
37*b31320a7SChris Fraire #include "packet.h"
38d04ccbb3Scarlsonj 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * general utility functions which have no better home.  see util.c
417c478bd9Sstevel@tonic-gate  * for documentation on how to use the exported functions.
427c478bd9Sstevel@tonic-gate  */
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
457c478bd9Sstevel@tonic-gate extern "C" {
467c478bd9Sstevel@tonic-gate #endif
477c478bd9Sstevel@tonic-gate 
48d04ccbb3Scarlsonj struct dhcp_timer_s {
49d04ccbb3Scarlsonj 	iu_timer_id_t	dt_id;
50d04ccbb3Scarlsonj 	lease_t		dt_start;		/* Initial timer value */
51d04ccbb3Scarlsonj };
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate /* conversion functions */
54d04ccbb3Scarlsonj const char	*pkt_type_to_string(uchar_t, boolean_t);
557c478bd9Sstevel@tonic-gate const char	*monosec_to_string(monosec_t);
567c478bd9Sstevel@tonic-gate time_t		monosec_to_time(monosec_t);
57d04ccbb3Scarlsonj monosec_t	hrtime_to_monosec(hrtime_t);
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate /* shutdown handlers */
607c478bd9Sstevel@tonic-gate void		graceful_shutdown(int);
617c478bd9Sstevel@tonic-gate void		inactivity_shutdown(iu_tq_t *, void *);
627c478bd9Sstevel@tonic-gate 
63d04ccbb3Scarlsonj /* timer functions */
64d04ccbb3Scarlsonj void		init_timer(dhcp_timer_t *, lease_t);
65d04ccbb3Scarlsonj boolean_t	cancel_timer(dhcp_timer_t *);
66d04ccbb3Scarlsonj boolean_t	schedule_timer(dhcp_timer_t *, iu_tq_callback_t *, void *);
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /* miscellaneous */
69cfb9c9abScarlsonj boolean_t	add_default_route(uint32_t, struct in_addr *);
70cfb9c9abScarlsonj boolean_t	del_default_route(uint32_t, struct in_addr *);
717c478bd9Sstevel@tonic-gate int		daemonize(void);
727c478bd9Sstevel@tonic-gate monosec_t	monosec(void);
73d04ccbb3Scarlsonj void		print_server_msg(dhcp_smach_t *, const char *, uint_t);
74d04ccbb3Scarlsonj boolean_t	bind_sock(int, in_port_t, in_addr_t);
75d04ccbb3Scarlsonj boolean_t	bind_sock_v6(int, in_port_t, const in6_addr_t *);
767c478bd9Sstevel@tonic-gate const char	*iffile_to_hostname(const char *);
77d04ccbb3Scarlsonj int		dhcpv6_status_code(const dhcpv6_option_t *, uint_t,
78d04ccbb3Scarlsonj     const char **, const char **, uint_t *);
790a3e1f6cSVasumathi Sundaram void		write_lease_to_hostconf(dhcp_smach_t *);
80*b31320a7SChris Fraire boolean_t	dhcp_add_hostname_opt(dhcp_pkt_t *, dhcp_smach_t *);
81*b31320a7SChris Fraire boolean_t	dhcp_add_fqdn_opt(dhcp_pkt_t *, dhcp_smach_t *);
82*b31320a7SChris Fraire void		save_domainname(dhcp_smach_t *, PKT_LIST *);
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
857c478bd9Sstevel@tonic-gate }
867c478bd9Sstevel@tonic-gate #endif
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate #endif	/* UTIL_H */
89