xref: /titanic_52/usr/src/cmd/cmd-inet/lib/nwamd/ncu.h (revision f6da83d4178694e7113b71d1e452f15b296f73d8)
16ba597c5SAnurag S. Maskey /*
26ba597c5SAnurag S. Maskey  * CDDL HEADER START
36ba597c5SAnurag S. Maskey  *
46ba597c5SAnurag S. Maskey  * The contents of this file are subject to the terms of the
56ba597c5SAnurag S. Maskey  * Common Development and Distribution License (the "License").
66ba597c5SAnurag S. Maskey  * You may not use this file except in compliance with the License.
76ba597c5SAnurag S. Maskey  *
86ba597c5SAnurag S. Maskey  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
96ba597c5SAnurag S. Maskey  * or http://www.opensolaris.org/os/licensing.
106ba597c5SAnurag S. Maskey  * See the License for the specific language governing permissions
116ba597c5SAnurag S. Maskey  * and limitations under the License.
126ba597c5SAnurag S. Maskey  *
136ba597c5SAnurag S. Maskey  * When distributing Covered Code, include this CDDL HEADER in each
146ba597c5SAnurag S. Maskey  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
156ba597c5SAnurag S. Maskey  * If applicable, add the following below this CDDL HEADER, with the
166ba597c5SAnurag S. Maskey  * fields enclosed by brackets "[]" replaced with your own identifying
176ba597c5SAnurag S. Maskey  * information: Portions Copyright [yyyy] [name of copyright owner]
186ba597c5SAnurag S. Maskey  *
196ba597c5SAnurag S. Maskey  * CDDL HEADER END
206ba597c5SAnurag S. Maskey  */
216ba597c5SAnurag S. Maskey 
226ba597c5SAnurag S. Maskey /*
23*f6da83d4SAnurag S. Maskey  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
246ba597c5SAnurag S. Maskey  */
256ba597c5SAnurag S. Maskey 
266ba597c5SAnurag S. Maskey #ifndef _NCU_H
276ba597c5SAnurag S. Maskey #define	_NCU_H
286ba597c5SAnurag S. Maskey 
296ba597c5SAnurag S. Maskey #include <dhcpagent_ipc.h>
306ba597c5SAnurag S. Maskey #include <dhcpagent_util.h>
316ba597c5SAnurag S. Maskey #include <libdladm.h>
326ba597c5SAnurag S. Maskey #include <libdlpi.h>
336ba597c5SAnurag S. Maskey #include <libdlwlan.h>
34*f6da83d4SAnurag S. Maskey #include <libinetutil.h>
35*f6da83d4SAnurag S. Maskey #include <libipadm.h>
366ba597c5SAnurag S. Maskey #include <libnwam.h>
376ba597c5SAnurag S. Maskey #include <libnwam_priv.h>
386ba597c5SAnurag S. Maskey #include <libuutil.h>
396ba597c5SAnurag S. Maskey #include <pthread.h>
406ba597c5SAnurag S. Maskey #include <sys/mac.h>
416ba597c5SAnurag S. Maskey 
426ba597c5SAnurag S. Maskey #include "events.h"
436ba597c5SAnurag S. Maskey 
446ba597c5SAnurag S. Maskey extern pthread_mutex_t active_ncp_mutex;
456ba597c5SAnurag S. Maskey extern pthread_mutex_t active_loc_mutex;
466ba597c5SAnurag S. Maskey extern char active_loc[];
476ba597c5SAnurag S. Maskey extern uint64_t wireless_scan_interval;
486ba597c5SAnurag S. Maskey extern dladm_wlan_strength_t wireless_scan_level;
496ba597c5SAnurag S. Maskey extern boolean_t wireless_autoconf;
506ba597c5SAnurag S. Maskey extern boolean_t wireless_strict_bssid;
516ba597c5SAnurag S. Maskey 
526ba597c5SAnurag S. Maskey /*
536ba597c5SAnurag S. Maskey  * NCPs are collections of NCUs.  At the moment there is one NCP in the system
546ba597c5SAnurag S. Maskey  * and its expected there will never be many.  There is a lock on the NCP which
556ba597c5SAnurag S. Maskey  * must be obtained to add or remove anything from the NCP.
566ba597c5SAnurag S. Maskey  *
576ba597c5SAnurag S. Maskey  * NCUs are also kept in a uu list for easy walking.  Each NCU has a lock which
586ba597c5SAnurag S. Maskey  * is used to protect manipulation of its contents.  One of its members is a
596ba597c5SAnurag S. Maskey  * reference count which is initialized to 1 when its placed on the NCP.  As
606ba597c5SAnurag S. Maskey  * references are passed around that should be manipulated as necessary
616ba597c5SAnurag S. Maskey  * (helper functions YYY provided).  It is removed from the NCP by
626ba597c5SAnurag S. Maskey  * ncu_destroy() but the memory containing it is not returned to the free pool
636ba597c5SAnurag S. Maskey  * until the reference count falls to 0.
646ba597c5SAnurag S. Maskey  *
656ba597c5SAnurag S. Maskey  * As we add
666ba597c5SAnurag S. Maskey  * more complex system objects their relationship becomes more complex.  That
676ba597c5SAnurag S. Maskey  * is represented by the links within the NCUs.  Reference counts should be
686ba597c5SAnurag S. Maskey  * used to maintain the consistency of these links.  Care should be used when
696ba597c5SAnurag S. Maskey  * walking more complex structures that might contain cycles.
706ba597c5SAnurag S. Maskey  */
716ba597c5SAnurag S. Maskey 
726ba597c5SAnurag S. Maskey /* Stores details of last/current WiFi scans */
736ba597c5SAnurag S. Maskey typedef struct nwamd_wifi_scan {
746ba597c5SAnurag S. Maskey 	char nwamd_wifi_scan_link[NWAM_MAX_NAME_LEN];
756ba597c5SAnurag S. Maskey 	nwam_wlan_t nwamd_wifi_scan_last[NWAMD_MAX_NUM_WLANS];
766ba597c5SAnurag S. Maskey 	uint_t nwamd_wifi_scan_last_num;
776ba597c5SAnurag S. Maskey 	nwam_wlan_t nwamd_wifi_scan_curr[NWAMD_MAX_NUM_WLANS];
786ba597c5SAnurag S. Maskey 	uint_t nwamd_wifi_scan_curr_num;
796ba597c5SAnurag S. Maskey 	boolean_t nwamd_wifi_scan_changed;
806ba597c5SAnurag S. Maskey 	uint32_t nwamd_wifi_scan_last_time;
816ba597c5SAnurag S. Maskey } nwamd_wifi_scan_t;
826ba597c5SAnurag S. Maskey 
836ba597c5SAnurag S. Maskey typedef struct nwamd_link {
846ba597c5SAnurag S. Maskey 	pthread_mutex_t nwamd_link_wifi_mutex;
856ba597c5SAnurag S. Maskey 	pthread_t nwamd_link_wifi_scan_thread;
866ba597c5SAnurag S. Maskey 	pthread_t nwamd_link_wifi_monitor_thread;
876ba597c5SAnurag S. Maskey 	char nwamd_link_wifi_essid[DLADM_STRSIZE];
886ba597c5SAnurag S. Maskey 	char nwamd_link_wifi_bssid[DLADM_STRSIZE];
896ba597c5SAnurag S. Maskey 	char nwamd_link_wifi_keyname[DLADM_STRSIZE];
906ba597c5SAnurag S. Maskey 	char nwamd_link_wifi_signal_strength[DLADM_STRSIZE];
916ba597c5SAnurag S. Maskey 	boolean_t nwamd_link_wifi_add_to_known_wlans;
926ba597c5SAnurag S. Maskey 	boolean_t nwamd_link_wifi_connected;
936ba597c5SAnurag S. Maskey 	uint32_t nwamd_link_wifi_security_mode;
946ba597c5SAnurag S. Maskey 	dladm_wlan_key_t *nwamd_link_wifi_key;
956ba597c5SAnurag S. Maskey 	nwamd_wifi_scan_t nwamd_link_wifi_scan;
966ba597c5SAnurag S. Maskey 	uint64_t nwamd_link_wifi_priority;
976ba597c5SAnurag S. Maskey 	boolean_t nwamd_link_wifi_autoconf;
986ba597c5SAnurag S. Maskey 	uint32_t nwamd_link_id;
996ba597c5SAnurag S. Maskey 	uint32_t nwamd_link_media;
1006ba597c5SAnurag S. Maskey 	uint64_t nwamd_link_flags;
1016ba597c5SAnurag S. Maskey 	dlpi_handle_t nwamd_link_dhp;
1026ba597c5SAnurag S. Maskey 	pthread_t nwamd_link_dlpi_thread;
1036ba597c5SAnurag S. Maskey 	uint64_t nwamd_link_activation_mode;
1046ba597c5SAnurag S. Maskey 	uint64_t nwamd_link_priority_mode;
1056ba597c5SAnurag S. Maskey 	uint64_t nwamd_link_priority_group;
1066ba597c5SAnurag S. Maskey 	char *nwamd_link_mac_addr;
1076ba597c5SAnurag S. Maskey 	size_t nwamd_link_mac_addr_len;
1086ba597c5SAnurag S. Maskey 	uint64_t nwamd_link_mtu;
1096ba597c5SAnurag S. Maskey 	char **nwamd_link_autopush;
1106ba597c5SAnurag S. Maskey 	uint_t nwamd_link_num_autopush;
1116ba597c5SAnurag S. Maskey } nwamd_link_t;
1126ba597c5SAnurag S. Maskey 
1136ba597c5SAnurag S. Maskey struct nwamd_if_address {
114*f6da83d4SAnurag S. Maskey 	sa_family_t family;
115*f6da83d4SAnurag S. Maskey 	ipadm_addr_type_t ipaddr_atype;
116*f6da83d4SAnurag S. Maskey 	ipadm_addrobj_t ipaddr;
1176ba597c5SAnurag S. Maskey 	boolean_t configured;
118*f6da83d4SAnurag S. Maskey 	struct sockaddr_storage conf_addr;	/* address configured for */
119*f6da83d4SAnurag S. Maskey 	struct sockaddr_storage conf_stateless_addr; /* this nwamd_if_address */
1206ba597c5SAnurag S. Maskey 	struct nwamd_if_address *next;
1216ba597c5SAnurag S. Maskey };
1226ba597c5SAnurag S. Maskey 
1236ba597c5SAnurag S. Maskey typedef struct nwamd_if {
1246ba597c5SAnurag S. Maskey 	boolean_t nwamd_if_dhcp_requested;
1256ba597c5SAnurag S. Maskey 	boolean_t nwamd_if_dhcp_configured;
1266ba597c5SAnurag S. Maskey 	boolean_t nwamd_if_stateful_requested;
1276ba597c5SAnurag S. Maskey 	boolean_t nwamd_if_stateful_configured;
1286ba597c5SAnurag S. Maskey 	boolean_t nwamd_if_stateless_requested;
1296ba597c5SAnurag S. Maskey 	boolean_t nwamd_if_stateless_configured;
1306ba597c5SAnurag S. Maskey 	struct nwamd_if_address *nwamd_if_list;
1316ba597c5SAnurag S. Maskey 	struct sockaddr_in nwamd_if_ipv4_default_route;
1326ba597c5SAnurag S. Maskey 	boolean_t nwamd_if_ipv4_default_route_set;
1336ba597c5SAnurag S. Maskey 	struct sockaddr_in6 nwamd_if_ipv6_default_route;
1346ba597c5SAnurag S. Maskey 	boolean_t nwamd_if_ipv6_default_route_set;
1356ba597c5SAnurag S. Maskey 	boolean_t nwamd_if_ipv4;
1366ba597c5SAnurag S. Maskey 	boolean_t nwamd_if_ipv6;
1376ba597c5SAnurag S. Maskey } nwamd_if_t;
1386ba597c5SAnurag S. Maskey 
1396ba597c5SAnurag S. Maskey typedef struct nwamd_ncu {
1406ba597c5SAnurag S. Maskey 	nwam_ncu_type_t ncu_type;
1416ba597c5SAnurag S. Maskey 	char *ncu_name;
1426ba597c5SAnurag S. Maskey 	char ncu_parent[NWAM_MAX_NAME_LEN];
1436ba597c5SAnurag S. Maskey 	boolean_t ncu_enabled; /* whether NCU has been enabled or not */
1446ba597c5SAnurag S. Maskey 	union {
1456ba597c5SAnurag S. Maskey 		nwamd_link_t u_link;
1466ba597c5SAnurag S. Maskey 		nwamd_if_t u_if;
1476ba597c5SAnurag S. Maskey 	} ncu_node;
1486ba597c5SAnurag S. Maskey } nwamd_ncu_t;
1496ba597c5SAnurag S. Maskey 
1506ba597c5SAnurag S. Maskey #define	ncu_link	ncu_node.u_link
1516ba597c5SAnurag S. Maskey #define	ncu_if		ncu_node.u_if
1526ba597c5SAnurag S. Maskey 
1536ba597c5SAnurag S. Maskey #define	LOOPBACK_IF				"lo0"
1546ba597c5SAnurag S. Maskey 
1556ba597c5SAnurag S. Maskey struct nwamd_dhcp_thread_arg {
1566ba597c5SAnurag S. Maskey 	char *name;
1576ba597c5SAnurag S. Maskey 	dhcp_ipc_type_t type;
158*f6da83d4SAnurag S. Maskey 	ipadm_addrobj_t ipaddr;
1596ba597c5SAnurag S. Maskey 	volatile uint32_t *guard;
1606ba597c5SAnurag S. Maskey };
1616ba597c5SAnurag S. Maskey 
1626ba597c5SAnurag S. Maskey #define	WIRELESS_SCAN_INTERVAL_DEFAULT		120
1636ba597c5SAnurag S. Maskey #define	WIRELESS_SCAN_INTERVAL_MIN		30
1646ba597c5SAnurag S. Maskey #define	WIRELESS_SCAN_REQUESTED_INTERVAL_MIN	10
1656ba597c5SAnurag S. Maskey #define	WIRELESS_MONITOR_SIGNAL_INTERVAL	10
1666ba597c5SAnurag S. Maskey #define	WIRELESS_RETRY_INTERVAL			30
1676ba597c5SAnurag S. Maskey #define	WIRELESS_SCAN_LEVEL_DEFAULT		DLADM_WLAN_STRENGTH_WEAK
1686ba597c5SAnurag S. Maskey #define	NWAMD_DHCP_RETRIES			5
1696ba597c5SAnurag S. Maskey #define	NWAMD_DHCP_RETRY_WAIT_TIME		10
1706ba597c5SAnurag S. Maskey #define	NWAMD_READONLY_RETRY_INTERVAL		5
1716ba597c5SAnurag S. Maskey 
1726ba597c5SAnurag S. Maskey /*
173*f6da83d4SAnurag S. Maskey  * This dladm and ipadm handles are opened before interfaces are initialized
174*f6da83d4SAnurag S. Maskey  * and closed only when nwamd shuts down.
1756ba597c5SAnurag S. Maskey  */
1766ba597c5SAnurag S. Maskey extern dladm_handle_t dld_handle;
177*f6da83d4SAnurag S. Maskey extern ipadm_handle_t ipadm_handle;
1786ba597c5SAnurag S. Maskey 
1796ba597c5SAnurag S. Maskey extern nwamd_object_t nwamd_ncu_object_find(nwam_ncu_type_t, const char *);
1806ba597c5SAnurag S. Maskey extern void nwamd_log_ncus(void);
1816ba597c5SAnurag S. Maskey extern void nwamd_ncu_free(nwamd_ncu_t *);
1826ba597c5SAnurag S. Maskey 
1836ba597c5SAnurag S. Maskey /* WLAN functions */
1846ba597c5SAnurag S. Maskey extern void nwamd_set_selected_connected(nwamd_ncu_t *, boolean_t, boolean_t);
1856ba597c5SAnurag S. Maskey extern nwam_error_t nwamd_wlan_select(const char *, const char *, const char *,
1866ba597c5SAnurag S. Maskey     uint32_t, boolean_t);
1876ba597c5SAnurag S. Maskey extern nwam_error_t nwamd_wlan_set_key(const char *, const char *, const char *,
1886ba597c5SAnurag S. Maskey     uint32_t, uint_t, char *);
1896ba597c5SAnurag S. Maskey extern nwam_error_t nwamd_wlan_scan(const char *);
1906ba597c5SAnurag S. Maskey extern void nwamd_wlan_connect(const char *);
1916ba597c5SAnurag S. Maskey extern boolean_t nwamd_wlan_connected(nwamd_object_t);
1926ba597c5SAnurag S. Maskey extern void nwamd_wlan_monitor_signal(const char *);
1936ba597c5SAnurag S. Maskey extern void nwamd_ncu_create_periodic_scan_event(nwamd_object_t);
1946ba597c5SAnurag S. Maskey extern dladm_wlan_key_t *nwamd_wlan_get_key_named(const char *, uint32_t);
1956ba597c5SAnurag S. Maskey extern void nwamd_set_key_name(const char *, const char *, char *, size_t);
1966ba597c5SAnurag S. Maskey 
1976ba597c5SAnurag S. Maskey /* Link functions */
1986ba597c5SAnurag S. Maskey extern link_state_t nwamd_get_link_state(const char *);
199*f6da83d4SAnurag S. Maskey extern const char *nwamd_sockaddr_to_str(const struct sockaddr *, char *,
200*f6da83d4SAnurag S. Maskey     size_t);
2016ba597c5SAnurag S. Maskey extern void nwamd_propogate_link_up_down_to_ip(const char *, boolean_t);
2026ba597c5SAnurag S. Maskey extern void nwamd_set_unset_link_properties(nwamd_ncu_t *, boolean_t);
2036ba597c5SAnurag S. Maskey /* DLPI event hooking */
2046ba597c5SAnurag S. Maskey extern void nwamd_dlpi_add_link(nwamd_object_t);
2056ba597c5SAnurag S. Maskey extern void nwamd_dlpi_delete_link(nwamd_object_t);
2066ba597c5SAnurag S. Maskey 
2076ba597c5SAnurag S. Maskey /* IP functions */
2086ba597c5SAnurag S. Maskey extern boolean_t nwamd_static_addresses_configured(nwamd_ncu_t *, sa_family_t);
209*f6da83d4SAnurag S. Maskey extern void nwamd_plumb_interface(nwamd_ncu_t *, sa_family_t);
210*f6da83d4SAnurag S. Maskey extern void nwamd_unplumb_interface(nwamd_ncu_t *, sa_family_t);
2116ba597c5SAnurag S. Maskey extern boolean_t nwamd_dhcp_managing(int, nwamd_ncu_t *);
2126ba597c5SAnurag S. Maskey extern void nwamd_configure_interface_addresses(nwamd_ncu_t *);
2136ba597c5SAnurag S. Maskey extern char *nwamd_get_dhcpinfo_data(const char *, char *);
2146ba597c5SAnurag S. Maskey extern void nwamd_dhcp_release(const char *);
2156ba597c5SAnurag S. Maskey extern void nwamd_add_default_routes(nwamd_ncu_t *);
2166ba597c5SAnurag S. Maskey extern void nwamd_add_route(struct sockaddr *, struct sockaddr *,
2176ba597c5SAnurag S. Maskey     struct sockaddr *, const char *);
2186ba597c5SAnurag S. Maskey 
2196ba597c5SAnurag S. Maskey /* NCU value set/get functions */
2206ba597c5SAnurag S. Maskey extern nwam_error_t nwamd_set_ncu_uint(nwam_ncu_handle_t, uint64_t *, uint_t,
2216ba597c5SAnurag S. Maskey     const char *);
2226ba597c5SAnurag S. Maskey extern nwam_error_t nwamd_set_ncu_string(nwam_ncu_handle_t, char **, uint_t,
2236ba597c5SAnurag S. Maskey     const char *);
2246ba597c5SAnurag S. Maskey extern nwam_error_t nwamd_get_ncu_uint(nwam_ncu_handle_t, nwam_value_t *,
2256ba597c5SAnurag S. Maskey     uint64_t **, uint_t *, const char *);
2266ba597c5SAnurag S. Maskey extern nwam_error_t nwamd_get_ncu_string(nwam_ncu_handle_t, nwam_value_t *,
2276ba597c5SAnurag S. Maskey     char ***, uint_t *, const char *);
2286ba597c5SAnurag S. Maskey 
2296ba597c5SAnurag S. Maskey extern void nwamd_walk_physical_configuration(void);
2306ba597c5SAnurag S. Maskey 
2316ba597c5SAnurag S. Maskey #endif /* _NCU_H */
232