17c478bd9Sstevel@tonic-gate /* 2dc632b73SJames Carlson * CDDL HEADER START 3dc632b73SJames Carlson * 4dc632b73SJames Carlson * The contents of this file are subject to the terms of the 5dc632b73SJames Carlson * Common Development and Distribution License (the "License"). 6dc632b73SJames Carlson * You may not use this file except in compliance with the License. 7dc632b73SJames Carlson * 8dc632b73SJames Carlson * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9dc632b73SJames Carlson * or http://www.opensolaris.org/os/licensing. 10dc632b73SJames Carlson * See the License for the specific language governing permissions 11dc632b73SJames Carlson * and limitations under the License. 12dc632b73SJames Carlson * 13dc632b73SJames Carlson * When distributing Covered Code, include this CDDL HEADER in each 14dc632b73SJames Carlson * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15dc632b73SJames Carlson * If applicable, add the following below this CDDL HEADER, with the 16dc632b73SJames Carlson * fields enclosed by brackets "[]" replaced with your own identifying 17dc632b73SJames Carlson * information: Portions Copyright [yyyy] [name of copyright owner] 18dc632b73SJames Carlson * 19dc632b73SJames Carlson * CDDL HEADER END 20dc632b73SJames Carlson */ 21dc632b73SJames Carlson 22dc632b73SJames Carlson /* 23*f53eecf5SJames Carlson * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #include <sys/types.h> 287c478bd9Sstevel@tonic-gate #include <sys/debug.h> 297c478bd9Sstevel@tonic-gate #include <sys/param.h> 307c478bd9Sstevel@tonic-gate #include <sys/stat.h> 317c478bd9Sstevel@tonic-gate #include <sys/systm.h> 327c478bd9Sstevel@tonic-gate #include <sys/socket.h> 337c478bd9Sstevel@tonic-gate #include <sys/stream.h> 347c478bd9Sstevel@tonic-gate #include <sys/stropts.h> 357c478bd9Sstevel@tonic-gate #include <sys/errno.h> 367c478bd9Sstevel@tonic-gate #include <sys/time.h> 377c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 38002c70ffScarlsonj #include <sys/sdt.h> 397c478bd9Sstevel@tonic-gate #include <sys/conf.h> 407c478bd9Sstevel@tonic-gate #include <sys/dlpi.h> 417c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 427c478bd9Sstevel@tonic-gate #include <sys/kstat.h> 437c478bd9Sstevel@tonic-gate #include <sys/strsun.h> 447c478bd9Sstevel@tonic-gate #include <sys/bitmap.h> 457c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 467c478bd9Sstevel@tonic-gate #include <sys/note.h> 477c478bd9Sstevel@tonic-gate #include <sys/policy.h> 487c478bd9Sstevel@tonic-gate #include <net/ppp_defs.h> 497c478bd9Sstevel@tonic-gate #include <net/pppio.h> 507c478bd9Sstevel@tonic-gate #include <net/sppptun.h> 517c478bd9Sstevel@tonic-gate #include <net/pppoe.h> 527c478bd9Sstevel@tonic-gate #include <netinet/in.h> 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate #include "s_common.h" 557c478bd9Sstevel@tonic-gate #include "sppptun_mod.h" 567c478bd9Sstevel@tonic-gate #include "sppptun_impl.h" 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate #define NTUN_INITIAL 16 /* Initial number of sppptun slots */ 597c478bd9Sstevel@tonic-gate #define NTUN_PERCENT 5 /* Percent of memory to use */ 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate /* 627c478bd9Sstevel@tonic-gate * This is used to tag official Solaris sources. Please do not define 637c478bd9Sstevel@tonic-gate * "INTERNAL_BUILD" when building this software outside of Sun 647c478bd9Sstevel@tonic-gate * Microsystems. 657c478bd9Sstevel@tonic-gate */ 667c478bd9Sstevel@tonic-gate #ifdef INTERNAL_BUILD 677c478bd9Sstevel@tonic-gate /* MODINFO is limited to 32 characters. */ 68002c70ffScarlsonj const char sppptun_driver_description[] = "PPP 4.0 tunnel driver"; 69002c70ffScarlsonj const char sppptun_module_description[] = "PPP 4.0 tunnel module"; 707c478bd9Sstevel@tonic-gate #else 7119397407SSherry Moore const char sppptun_driver_description[] = "ANU PPP tundrv"; 7219397407SSherry Moore const char sppptun_module_description[] = "ANU PPP tunmod"; 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate /* LINTED */ 757c478bd9Sstevel@tonic-gate static const char buildtime[] = "Built " __DATE__ " at " __TIME__ 767c478bd9Sstevel@tonic-gate #ifdef DEBUG 777c478bd9Sstevel@tonic-gate " DEBUG" 787c478bd9Sstevel@tonic-gate #endif 797c478bd9Sstevel@tonic-gate "\n"; 807c478bd9Sstevel@tonic-gate #endif 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate /* 837c478bd9Sstevel@tonic-gate * Tunable values; these are similar to the values used in ptms_conf.c. 847c478bd9Sstevel@tonic-gate * Override these settings via /etc/system. 857c478bd9Sstevel@tonic-gate */ 867c478bd9Sstevel@tonic-gate uint_t sppptun_cnt = 0; /* Minimum number of tunnels */ 877c478bd9Sstevel@tonic-gate size_t sppptun_max_pty = 0; /* Maximum number of tunnels */ 887c478bd9Sstevel@tonic-gate uint_t sppptun_init_cnt = NTUN_INITIAL; /* Initial number of tunnel slots */ 897c478bd9Sstevel@tonic-gate uint_t sppptun_pctofmem = NTUN_PERCENT; /* Percent of memory to use */ 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate typedef struct ether_dest_s { 927c478bd9Sstevel@tonic-gate ether_addr_t addr; 937c478bd9Sstevel@tonic-gate ushort_t type; 947c478bd9Sstevel@tonic-gate } ether_dest_t; 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate /* Allows unaligned access. */ 977c478bd9Sstevel@tonic-gate #define GETLONG(x) (((x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3]) 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate static const char *tll_kstats_list[] = { TLL_KSTATS_NAMES }; 1007c478bd9Sstevel@tonic-gate static const char *tcl_kstats_list[] = { TCL_KSTATS_NAMES }; 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate #define KREF(p, m, vn) p->m.vn.value.ui64 1037c478bd9Sstevel@tonic-gate #define KINCR(p, m, vn) ++KREF(p, m, vn) 1047c478bd9Sstevel@tonic-gate #define KDECR(p, m, vn) --KREF(p, m, vn) 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate #define KLINCR(vn) KINCR(tll, tll_kstats, vn) 1077c478bd9Sstevel@tonic-gate #define KLDECR(vn) KDECR(tll, tll_kstats, vn) 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate #define KCINCR(vn) KINCR(tcl, tcl_kstats, vn) 1107c478bd9Sstevel@tonic-gate #define KCDECR(vn) KDECR(tcl, tcl_kstats, vn) 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate static int sppptun_open(queue_t *, dev_t *, int, int, cred_t *); 1137c478bd9Sstevel@tonic-gate static int sppptun_close(queue_t *); 1147c478bd9Sstevel@tonic-gate static void sppptun_urput(queue_t *, mblk_t *); 1157c478bd9Sstevel@tonic-gate static void sppptun_uwput(queue_t *, mblk_t *); 1167c478bd9Sstevel@tonic-gate static int sppptun_ursrv(queue_t *); 1177c478bd9Sstevel@tonic-gate static int sppptun_uwsrv(queue_t *); 1187c478bd9Sstevel@tonic-gate static void sppptun_lrput(queue_t *, mblk_t *); 1197c478bd9Sstevel@tonic-gate static void sppptun_lwput(queue_t *, mblk_t *); 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate /* 1227c478bd9Sstevel@tonic-gate * This is the hash table of clients. Clients are the programs that 1237c478bd9Sstevel@tonic-gate * open /dev/sppptun as a device. There may be a large number of 1247c478bd9Sstevel@tonic-gate * these; one per tunneled PPP session. 1257c478bd9Sstevel@tonic-gate * 1267c478bd9Sstevel@tonic-gate * Note: slots are offset from minor node value by 1 because 1277c478bd9Sstevel@tonic-gate * vmem_alloc returns 0 for failure. 1287c478bd9Sstevel@tonic-gate * 1297c478bd9Sstevel@tonic-gate * The tcl_slots array entries are modified only when exclusive on 1307c478bd9Sstevel@tonic-gate * both inner and outer perimeters. This ensures that threads on 1317c478bd9Sstevel@tonic-gate * shared perimeters always view this as unchanging memory with no 1327c478bd9Sstevel@tonic-gate * need to lock around accesses. (Specifically, the tcl_slots array 1337c478bd9Sstevel@tonic-gate * is modified by entry to sppptun_open, sppptun_close, and _fini.) 1347c478bd9Sstevel@tonic-gate */ 1357c478bd9Sstevel@tonic-gate static tuncl_t **tcl_slots = NULL; /* Slots for tuncl_t */ 1367c478bd9Sstevel@tonic-gate static size_t tcl_nslots = 0; /* Size of slot array */ 1377c478bd9Sstevel@tonic-gate static size_t tcl_minormax = 0; /* Maximum number of tunnels */ 1387c478bd9Sstevel@tonic-gate static size_t tcl_inuse = 0; /* # of tunnels currently allocated */ 1397c478bd9Sstevel@tonic-gate static krwlock_t tcl_rwlock; 1407c478bd9Sstevel@tonic-gate static struct kmem_cache *tcl_cache = NULL; /* tunnel cache */ 1417c478bd9Sstevel@tonic-gate static vmem_t *tcl_minor_arena = NULL; /* Arena for device minors */ 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate /* 1447c478bd9Sstevel@tonic-gate * This is the simple list of lower layers. For PPPoE, there is one 1457c478bd9Sstevel@tonic-gate * of these per Ethernet interface. Lower layers are established by 1467c478bd9Sstevel@tonic-gate * "plumbing" -- using I_PLINK to connect the tunnel multiplexor to 1477c478bd9Sstevel@tonic-gate * the physical interface. 1487c478bd9Sstevel@tonic-gate */ 1497c478bd9Sstevel@tonic-gate static struct qelem tunll_list; 1507c478bd9Sstevel@tonic-gate static int tunll_index; 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate /* Test value; if all zeroes, then address hasn't been set yet. */ 1537c478bd9Sstevel@tonic-gate static const ether_addr_t zero_mac_addr = { 0, 0, 0, 0, 0, 0 }; 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate #define MIN_SET_FASTPATH_UNITDATAREQ_SIZE \ 1567c478bd9Sstevel@tonic-gate (sizeof (dl_unitdata_req_t) + 4) 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate #define TUN_MI_ID 2104 /* officially allocated module ID */ 1597c478bd9Sstevel@tonic-gate #define TUN_MI_MINPSZ (0) 1607c478bd9Sstevel@tonic-gate #define TUN_MI_MAXPSZ (PPP_MAXMTU) 1617c478bd9Sstevel@tonic-gate #define TUN_MI_HIWAT (PPP_MTU * 8) 1627c478bd9Sstevel@tonic-gate #define TUN_MI_LOWAT (128) 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate static struct module_info sppptun_modinfo = { 1657c478bd9Sstevel@tonic-gate TUN_MI_ID, /* mi_idnum */ 1667c478bd9Sstevel@tonic-gate PPP_TUN_NAME, /* mi_idname */ 1677c478bd9Sstevel@tonic-gate TUN_MI_MINPSZ, /* mi_minpsz */ 1687c478bd9Sstevel@tonic-gate TUN_MI_MAXPSZ, /* mi_maxpsz */ 1697c478bd9Sstevel@tonic-gate TUN_MI_HIWAT, /* mi_hiwat */ 1707c478bd9Sstevel@tonic-gate TUN_MI_LOWAT /* mi_lowat */ 1717c478bd9Sstevel@tonic-gate }; 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate static struct qinit sppptun_urinit = { 1747c478bd9Sstevel@tonic-gate (int (*)())sppptun_urput, /* qi_putp */ 1757c478bd9Sstevel@tonic-gate sppptun_ursrv, /* qi_srvp */ 1767c478bd9Sstevel@tonic-gate sppptun_open, /* qi_qopen */ 1777c478bd9Sstevel@tonic-gate sppptun_close, /* qi_qclose */ 1787c478bd9Sstevel@tonic-gate NULL, /* qi_qadmin */ 1797c478bd9Sstevel@tonic-gate &sppptun_modinfo, /* qi_minfo */ 1807c478bd9Sstevel@tonic-gate NULL /* qi_mstat */ 1817c478bd9Sstevel@tonic-gate }; 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate static struct qinit sppptun_uwinit = { 1847c478bd9Sstevel@tonic-gate (int (*)())sppptun_uwput, /* qi_putp */ 1857c478bd9Sstevel@tonic-gate sppptun_uwsrv, /* qi_srvp */ 1867c478bd9Sstevel@tonic-gate NULL, /* qi_qopen */ 1877c478bd9Sstevel@tonic-gate NULL, /* qi_qclose */ 1887c478bd9Sstevel@tonic-gate NULL, /* qi_qadmin */ 1897c478bd9Sstevel@tonic-gate &sppptun_modinfo, /* qi_minfo */ 1907c478bd9Sstevel@tonic-gate NULL /* qi_mstat */ 1917c478bd9Sstevel@tonic-gate }; 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate static struct qinit sppptun_lrinit = { 1947c478bd9Sstevel@tonic-gate (int (*)())sppptun_lrput, /* qi_putp */ 1957c478bd9Sstevel@tonic-gate NULL, /* qi_srvp */ 1967c478bd9Sstevel@tonic-gate NULL, /* qi_qopen */ 1977c478bd9Sstevel@tonic-gate NULL, /* qi_qclose */ 1987c478bd9Sstevel@tonic-gate NULL, /* qi_qadmin */ 1997c478bd9Sstevel@tonic-gate &sppptun_modinfo, /* qi_minfo */ 2007c478bd9Sstevel@tonic-gate NULL /* qi_mstat */ 2017c478bd9Sstevel@tonic-gate }; 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate static struct qinit sppptun_lwinit = { 2047c478bd9Sstevel@tonic-gate (int (*)())sppptun_lwput, /* qi_putp */ 2057c478bd9Sstevel@tonic-gate NULL, /* qi_srvp */ 2067c478bd9Sstevel@tonic-gate NULL, /* qi_qopen */ 2077c478bd9Sstevel@tonic-gate NULL, /* qi_qclose */ 2087c478bd9Sstevel@tonic-gate NULL, /* qi_qadmin */ 2097c478bd9Sstevel@tonic-gate &sppptun_modinfo, /* qi_minfo */ 2107c478bd9Sstevel@tonic-gate NULL /* qi_mstat */ 2117c478bd9Sstevel@tonic-gate }; 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate /* 2147c478bd9Sstevel@tonic-gate * This is referenced in sppptun_mod.c. 2157c478bd9Sstevel@tonic-gate */ 2167c478bd9Sstevel@tonic-gate struct streamtab sppptun_tab = { 2177c478bd9Sstevel@tonic-gate &sppptun_urinit, /* st_rdinit */ 2187c478bd9Sstevel@tonic-gate &sppptun_uwinit, /* st_wrinit */ 2197c478bd9Sstevel@tonic-gate &sppptun_lrinit, /* st_muxrinit */ 2207c478bd9Sstevel@tonic-gate &sppptun_lwinit /* st_muxwrinit */ 2217c478bd9Sstevel@tonic-gate }; 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate /* 2247c478bd9Sstevel@tonic-gate * Allocate another slot table twice as large as the original one 2257c478bd9Sstevel@tonic-gate * (limited to global maximum). Migrate all tunnels to the new slot 2267c478bd9Sstevel@tonic-gate * table and free the original one. Assumes we're exclusive on both 2277c478bd9Sstevel@tonic-gate * inner and outer perimeters, and thus there are no other users of 2287c478bd9Sstevel@tonic-gate * the tcl_slots array. 2297c478bd9Sstevel@tonic-gate */ 2307c478bd9Sstevel@tonic-gate static minor_t 2317c478bd9Sstevel@tonic-gate tcl_grow(void) 2327c478bd9Sstevel@tonic-gate { 2337c478bd9Sstevel@tonic-gate minor_t old_size = tcl_nslots; 2347c478bd9Sstevel@tonic-gate minor_t new_size = 2 * old_size; 2357c478bd9Sstevel@tonic-gate tuncl_t **tcl_old = tcl_slots; 2367c478bd9Sstevel@tonic-gate tuncl_t **tcl_new; 2377c478bd9Sstevel@tonic-gate void *vaddr; /* vmem_add return value */ 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate ASSERT(RW_LOCK_HELD(&tcl_rwlock)); 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate /* Allocate new ptms array */ 2427c478bd9Sstevel@tonic-gate tcl_new = kmem_zalloc(new_size * sizeof (tuncl_t *), KM_NOSLEEP); 2437c478bd9Sstevel@tonic-gate if (tcl_new == NULL) 2447c478bd9Sstevel@tonic-gate return ((minor_t)0); 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate /* Increase clone index space */ 2477c478bd9Sstevel@tonic-gate vaddr = vmem_add(tcl_minor_arena, (void*)((uintptr_t)old_size + 1), 2487c478bd9Sstevel@tonic-gate new_size - old_size, VM_NOSLEEP); 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate if (vaddr == NULL) { 2517c478bd9Sstevel@tonic-gate kmem_free(tcl_new, new_size * sizeof (tuncl_t *)); 2527c478bd9Sstevel@tonic-gate return ((minor_t)0); 2537c478bd9Sstevel@tonic-gate } 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate /* Migrate tuncl_t entries to a new location */ 2567c478bd9Sstevel@tonic-gate tcl_nslots = new_size; 2577c478bd9Sstevel@tonic-gate bcopy(tcl_old, tcl_new, old_size * sizeof (tuncl_t *)); 2587c478bd9Sstevel@tonic-gate tcl_slots = tcl_new; 2597c478bd9Sstevel@tonic-gate kmem_free(tcl_old, old_size * sizeof (tuncl_t *)); 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate /* Allocate minor number and return it */ 2627c478bd9Sstevel@tonic-gate return ((minor_t)(uintptr_t)vmem_alloc(tcl_minor_arena, 1, VM_NOSLEEP)); 2637c478bd9Sstevel@tonic-gate } 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate /* 2667c478bd9Sstevel@tonic-gate * Allocate new minor number and tunnel client entry. Returns the new 2677c478bd9Sstevel@tonic-gate * entry or NULL if no memory or maximum number of entries reached. 2687c478bd9Sstevel@tonic-gate * Assumes we're exclusive on both inner and outer perimeters, and 2697c478bd9Sstevel@tonic-gate * thus there are no other users of the tcl_slots array. 2707c478bd9Sstevel@tonic-gate */ 2717c478bd9Sstevel@tonic-gate static tuncl_t * 2727c478bd9Sstevel@tonic-gate tuncl_alloc(int wantminor) 2737c478bd9Sstevel@tonic-gate { 2747c478bd9Sstevel@tonic-gate minor_t dminor; 2757c478bd9Sstevel@tonic-gate tuncl_t *tcl = NULL; 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate rw_enter(&tcl_rwlock, RW_WRITER); 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate ASSERT(tcl_slots != NULL); 2807c478bd9Sstevel@tonic-gate 2817c478bd9Sstevel@tonic-gate /* 2827c478bd9Sstevel@tonic-gate * Always try to allocate new pty when sppptun_cnt minimum 2837c478bd9Sstevel@tonic-gate * limit is not achieved. If it is achieved, the maximum is 2847c478bd9Sstevel@tonic-gate * determined by either user-specified value (if it is 2857c478bd9Sstevel@tonic-gate * non-zero) or our memory estimations - whatever is less. 2867c478bd9Sstevel@tonic-gate */ 2877c478bd9Sstevel@tonic-gate if (tcl_inuse >= sppptun_cnt) { 2887c478bd9Sstevel@tonic-gate /* 2897c478bd9Sstevel@tonic-gate * When system achieved required minimum of tunnels, 2907c478bd9Sstevel@tonic-gate * check for the denial of service limits. 2917c478bd9Sstevel@tonic-gate * 2927c478bd9Sstevel@tonic-gate * Get user-imposed maximum, if configured, or 2937c478bd9Sstevel@tonic-gate * calculated memory constraint. 2947c478bd9Sstevel@tonic-gate */ 2957c478bd9Sstevel@tonic-gate size_t user_max = (sppptun_max_pty == 0 ? tcl_minormax : 2967c478bd9Sstevel@tonic-gate min(sppptun_max_pty, tcl_minormax)); 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate /* Do not try to allocate more than allowed */ 2997c478bd9Sstevel@tonic-gate if (tcl_inuse >= user_max) { 3007c478bd9Sstevel@tonic-gate rw_exit(&tcl_rwlock); 3017c478bd9Sstevel@tonic-gate return (NULL); 3027c478bd9Sstevel@tonic-gate } 3037c478bd9Sstevel@tonic-gate } 3047c478bd9Sstevel@tonic-gate tcl_inuse++; 3057c478bd9Sstevel@tonic-gate 3067c478bd9Sstevel@tonic-gate /* 3077c478bd9Sstevel@tonic-gate * Allocate new minor number. If this fails, all slots are 3087c478bd9Sstevel@tonic-gate * busy and we need to grow the hash. 3097c478bd9Sstevel@tonic-gate */ 3107c478bd9Sstevel@tonic-gate if (wantminor <= 0) { 3117c478bd9Sstevel@tonic-gate dminor = (minor_t)(uintptr_t)vmem_alloc(tcl_minor_arena, 1, 3127c478bd9Sstevel@tonic-gate VM_NOSLEEP); 3137c478bd9Sstevel@tonic-gate if (dminor == 0) { 3147c478bd9Sstevel@tonic-gate /* Grow the cache and retry allocation */ 3157c478bd9Sstevel@tonic-gate dminor = tcl_grow(); 3167c478bd9Sstevel@tonic-gate } 3177c478bd9Sstevel@tonic-gate } else { 3187c478bd9Sstevel@tonic-gate dminor = (minor_t)(uintptr_t)vmem_xalloc(tcl_minor_arena, 1, 3197c478bd9Sstevel@tonic-gate 0, 0, 0, (void *)(uintptr_t)wantminor, 3207c478bd9Sstevel@tonic-gate (void *)((uintptr_t)wantminor+1), VM_NOSLEEP); 3217c478bd9Sstevel@tonic-gate if (dminor != 0 && dminor != wantminor) { 3227c478bd9Sstevel@tonic-gate vmem_free(tcl_minor_arena, (void *)(uintptr_t)dminor, 3237c478bd9Sstevel@tonic-gate 1); 3247c478bd9Sstevel@tonic-gate dminor = 0; 3257c478bd9Sstevel@tonic-gate } 3267c478bd9Sstevel@tonic-gate } 3277c478bd9Sstevel@tonic-gate 3287c478bd9Sstevel@tonic-gate if (dminor == 0) { 3297c478bd9Sstevel@tonic-gate /* Not enough memory now */ 3307c478bd9Sstevel@tonic-gate tcl_inuse--; 3317c478bd9Sstevel@tonic-gate rw_exit(&tcl_rwlock); 3327c478bd9Sstevel@tonic-gate return (NULL); 3337c478bd9Sstevel@tonic-gate } 3347c478bd9Sstevel@tonic-gate 3357c478bd9Sstevel@tonic-gate tcl = kmem_cache_alloc(tcl_cache, KM_NOSLEEP); 3367c478bd9Sstevel@tonic-gate if (tcl == NULL) { 3377c478bd9Sstevel@tonic-gate /* Not enough memory - this entry can't be used now. */ 3387c478bd9Sstevel@tonic-gate vmem_free(tcl_minor_arena, (void *)(uintptr_t)dminor, 1); 3397c478bd9Sstevel@tonic-gate tcl_inuse--; 3407c478bd9Sstevel@tonic-gate } else { 3417c478bd9Sstevel@tonic-gate bzero(tcl, sizeof (*tcl)); 3427c478bd9Sstevel@tonic-gate tcl->tcl_lsessid = dminor; 3437c478bd9Sstevel@tonic-gate ASSERT(tcl_slots[dminor - 1] == NULL); 3447c478bd9Sstevel@tonic-gate tcl_slots[dminor - 1] = tcl; 3457c478bd9Sstevel@tonic-gate } 3467c478bd9Sstevel@tonic-gate 3477c478bd9Sstevel@tonic-gate rw_exit(&tcl_rwlock); 3487c478bd9Sstevel@tonic-gate return (tcl); 3497c478bd9Sstevel@tonic-gate } 3507c478bd9Sstevel@tonic-gate 3517c478bd9Sstevel@tonic-gate /* 3527c478bd9Sstevel@tonic-gate * This routine frees an upper level (client) stream by removing it 3537c478bd9Sstevel@tonic-gate * from the minor number pool and freeing the state structure storage. 3547c478bd9Sstevel@tonic-gate * Assumes we're exclusive on both inner and outer perimeters, and 3557c478bd9Sstevel@tonic-gate * thus there are no other concurrent users of the tcl_slots array or 3567c478bd9Sstevel@tonic-gate * of any entry in that array. 3577c478bd9Sstevel@tonic-gate */ 3587c478bd9Sstevel@tonic-gate static void 3597c478bd9Sstevel@tonic-gate tuncl_free(tuncl_t *tcl) 3607c478bd9Sstevel@tonic-gate { 3617c478bd9Sstevel@tonic-gate rw_enter(&tcl_rwlock, RW_WRITER); 3627c478bd9Sstevel@tonic-gate ASSERT(tcl->tcl_lsessid <= tcl_nslots); 3637c478bd9Sstevel@tonic-gate ASSERT(tcl_slots[tcl->tcl_lsessid - 1] == tcl); 3647c478bd9Sstevel@tonic-gate ASSERT(tcl_inuse > 0); 3657c478bd9Sstevel@tonic-gate tcl_inuse--; 3667c478bd9Sstevel@tonic-gate tcl_slots[tcl->tcl_lsessid - 1] = NULL; 3677c478bd9Sstevel@tonic-gate 3687c478bd9Sstevel@tonic-gate if (tcl->tcl_ksp != NULL) { 3697c478bd9Sstevel@tonic-gate kstat_delete(tcl->tcl_ksp); 3707c478bd9Sstevel@tonic-gate tcl->tcl_ksp = NULL; 3717c478bd9Sstevel@tonic-gate } 3727c478bd9Sstevel@tonic-gate 3737c478bd9Sstevel@tonic-gate /* Return minor number to the pool of minors */ 3747c478bd9Sstevel@tonic-gate vmem_free(tcl_minor_arena, (void *)(uintptr_t)tcl->tcl_lsessid, 1); 3757c478bd9Sstevel@tonic-gate 3767c478bd9Sstevel@tonic-gate /* Return tuncl_t to the cache */ 3777c478bd9Sstevel@tonic-gate kmem_cache_free(tcl_cache, tcl); 3787c478bd9Sstevel@tonic-gate rw_exit(&tcl_rwlock); 3797c478bd9Sstevel@tonic-gate } 3807c478bd9Sstevel@tonic-gate 3817c478bd9Sstevel@tonic-gate /* 3827c478bd9Sstevel@tonic-gate * Get tuncl_t structure by minor number. Returns NULL when minor is 3837c478bd9Sstevel@tonic-gate * out of range. Note that lookup of tcl pointers (and use of those 3847c478bd9Sstevel@tonic-gate * pointers) is safe because modification is done only when exclusive 3857c478bd9Sstevel@tonic-gate * on both inner and outer perimeters. 3867c478bd9Sstevel@tonic-gate */ 3877c478bd9Sstevel@tonic-gate static tuncl_t * 3887c478bd9Sstevel@tonic-gate tcl_by_minor(minor_t dminor) 3897c478bd9Sstevel@tonic-gate { 3907c478bd9Sstevel@tonic-gate tuncl_t *tcl = NULL; 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate if ((dminor >= 1) && (dminor <= tcl_nslots) && tcl_slots != NULL) { 3937c478bd9Sstevel@tonic-gate tcl = tcl_slots[dminor - 1]; 3947c478bd9Sstevel@tonic-gate } 3957c478bd9Sstevel@tonic-gate 3967c478bd9Sstevel@tonic-gate return (tcl); 3977c478bd9Sstevel@tonic-gate } 3987c478bd9Sstevel@tonic-gate 3997c478bd9Sstevel@tonic-gate /* 4007c478bd9Sstevel@tonic-gate * Set up kstats for upper or lower stream. 4017c478bd9Sstevel@tonic-gate */ 4027c478bd9Sstevel@tonic-gate static kstat_t * 4037c478bd9Sstevel@tonic-gate kstat_setup(kstat_named_t *knt, const char **names, int nstat, 4047c478bd9Sstevel@tonic-gate const char *modname, int unitnum) 4057c478bd9Sstevel@tonic-gate { 4067c478bd9Sstevel@tonic-gate kstat_t *ksp; 4077c478bd9Sstevel@tonic-gate char unitname[KSTAT_STRLEN]; 4087c478bd9Sstevel@tonic-gate int i; 4097c478bd9Sstevel@tonic-gate 4107c478bd9Sstevel@tonic-gate for (i = 0; i < nstat; i++) { 411d624471bSelowe kstat_set_string(knt[i].name, names[i]); 4127c478bd9Sstevel@tonic-gate knt[i].data_type = KSTAT_DATA_UINT64; 4137c478bd9Sstevel@tonic-gate } 414002c70ffScarlsonj (void) sprintf(unitname, "%s" "%d", modname, unitnum); 415d624471bSelowe ksp = kstat_create(modname, unitnum, unitname, "net", 4167c478bd9Sstevel@tonic-gate KSTAT_TYPE_NAMED, nstat, KSTAT_FLAG_VIRTUAL); 4177c478bd9Sstevel@tonic-gate if (ksp != NULL) { 4187c478bd9Sstevel@tonic-gate ksp->ks_data = (void *)knt; 4197c478bd9Sstevel@tonic-gate kstat_install(ksp); 4207c478bd9Sstevel@tonic-gate } 4217c478bd9Sstevel@tonic-gate return (ksp); 4227c478bd9Sstevel@tonic-gate } 4237c478bd9Sstevel@tonic-gate 4247c478bd9Sstevel@tonic-gate /* 4257c478bd9Sstevel@tonic-gate * sppptun_open() 4267c478bd9Sstevel@tonic-gate * 4277c478bd9Sstevel@tonic-gate * MT-Perimeters: 4287c478bd9Sstevel@tonic-gate * exclusive inner, exclusive outer. 4297c478bd9Sstevel@tonic-gate * 4307c478bd9Sstevel@tonic-gate * Description: 4317c478bd9Sstevel@tonic-gate * Common open procedure for module and driver. 4327c478bd9Sstevel@tonic-gate */ 4337c478bd9Sstevel@tonic-gate static int 4347c478bd9Sstevel@tonic-gate sppptun_open(queue_t *q, dev_t *devp, int oflag, int sflag, cred_t *credp) 4357c478bd9Sstevel@tonic-gate { 4367c478bd9Sstevel@tonic-gate _NOTE(ARGUNUSED(oflag)) 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate /* Allow a re-open */ 4397c478bd9Sstevel@tonic-gate if (q->q_ptr != NULL) 4407c478bd9Sstevel@tonic-gate return (0); 4417c478bd9Sstevel@tonic-gate 4427c478bd9Sstevel@tonic-gate /* In the off chance that we're on our way out, just return error */ 443002c70ffScarlsonj if (tcl_slots == NULL) 4447c478bd9Sstevel@tonic-gate return (EINVAL); 4457c478bd9Sstevel@tonic-gate 4467c478bd9Sstevel@tonic-gate if (sflag & MODOPEN) { 4477c478bd9Sstevel@tonic-gate tunll_t *tll; 4487c478bd9Sstevel@tonic-gate char *cp; 4497c478bd9Sstevel@tonic-gate 4507c478bd9Sstevel@tonic-gate /* ordinary users have no need to push this module */ 451*f53eecf5SJames Carlson if (secpolicy_ppp_config(credp) != 0) 4527c478bd9Sstevel@tonic-gate return (EPERM); 4537c478bd9Sstevel@tonic-gate 4547c478bd9Sstevel@tonic-gate tll = kmem_zalloc(sizeof (tunll_t), KM_SLEEP); 4557c478bd9Sstevel@tonic-gate 4567c478bd9Sstevel@tonic-gate tll->tll_index = tunll_index++; 4577c478bd9Sstevel@tonic-gate 4587c478bd9Sstevel@tonic-gate tll->tll_wq = WR(q); 459*f53eecf5SJames Carlson tll->tll_zoneid = crgetzoneid(credp); 4607c478bd9Sstevel@tonic-gate 4617c478bd9Sstevel@tonic-gate /* Insert at end of list */ 4627c478bd9Sstevel@tonic-gate insque(&tll->tll_next, tunll_list.q_back); 4637c478bd9Sstevel@tonic-gate q->q_ptr = WR(q)->q_ptr = tll; 4647c478bd9Sstevel@tonic-gate 4657c478bd9Sstevel@tonic-gate tll->tll_style = PTS_PPPOE; 4667c478bd9Sstevel@tonic-gate tll->tll_alen = sizeof (tll->tll_lcladdr.pta_pppoe); 4677c478bd9Sstevel@tonic-gate 4687c478bd9Sstevel@tonic-gate tll->tll_ksp = kstat_setup((kstat_named_t *)&tll->tll_kstats, 4697c478bd9Sstevel@tonic-gate tll_kstats_list, Dim(tll_kstats_list), "tll", 4707c478bd9Sstevel@tonic-gate tll->tll_index); 4717c478bd9Sstevel@tonic-gate 4727c478bd9Sstevel@tonic-gate /* 4737c478bd9Sstevel@tonic-gate * Find the name of the driver somewhere beneath us. 4747c478bd9Sstevel@tonic-gate * Note that we have no driver under us until after 4757c478bd9Sstevel@tonic-gate * qprocson(). 4767c478bd9Sstevel@tonic-gate */ 4777c478bd9Sstevel@tonic-gate qprocson(q); 4787c478bd9Sstevel@tonic-gate for (q = WR(q); q->q_next != NULL; q = q->q_next) 4797c478bd9Sstevel@tonic-gate ; 4807c478bd9Sstevel@tonic-gate cp = NULL; 4817c478bd9Sstevel@tonic-gate if (q->q_qinfo != NULL && q->q_qinfo->qi_minfo != NULL) 4827c478bd9Sstevel@tonic-gate cp = q->q_qinfo->qi_minfo->mi_idname; 4837c478bd9Sstevel@tonic-gate if (cp != NULL && *cp == '\0') 4847c478bd9Sstevel@tonic-gate cp = NULL; 4857c478bd9Sstevel@tonic-gate 4867c478bd9Sstevel@tonic-gate /* Set initial name; user should overwrite. */ 4877c478bd9Sstevel@tonic-gate if (cp == NULL) 4887c478bd9Sstevel@tonic-gate (void) snprintf(tll->tll_name, sizeof (tll->tll_name), 4897c478bd9Sstevel@tonic-gate PPP_TUN_NAME "%d", tll->tll_index); 4907c478bd9Sstevel@tonic-gate else 4917c478bd9Sstevel@tonic-gate (void) snprintf(tll->tll_name, sizeof (tll->tll_name), 4927c478bd9Sstevel@tonic-gate "%s:tun%d", cp, tll->tll_index); 4937c478bd9Sstevel@tonic-gate } else { 4947c478bd9Sstevel@tonic-gate tuncl_t *tcl; 4957c478bd9Sstevel@tonic-gate 4967c478bd9Sstevel@tonic-gate ASSERT(devp != NULL); 4977c478bd9Sstevel@tonic-gate if (sflag & CLONEOPEN) { 4987c478bd9Sstevel@tonic-gate tcl = tuncl_alloc(-1); 4997c478bd9Sstevel@tonic-gate } else { 5007c478bd9Sstevel@tonic-gate minor_t mn; 5017c478bd9Sstevel@tonic-gate 5027c478bd9Sstevel@tonic-gate /* 5037c478bd9Sstevel@tonic-gate * Support of non-clone open (ie, mknod with 5047c478bd9Sstevel@tonic-gate * defined minor number) is supported for 5057c478bd9Sstevel@tonic-gate * testing purposes so that 'arbitrary' minor 5067c478bd9Sstevel@tonic-gate * numbers can be used. 5077c478bd9Sstevel@tonic-gate */ 5087c478bd9Sstevel@tonic-gate mn = getminor(*devp); 5097c478bd9Sstevel@tonic-gate if (mn == 0 || (tcl = tcl_by_minor(mn)) != NULL) { 5107c478bd9Sstevel@tonic-gate return (EPERM); 5117c478bd9Sstevel@tonic-gate } 5127c478bd9Sstevel@tonic-gate tcl = tuncl_alloc(mn); 5137c478bd9Sstevel@tonic-gate } 5147c478bd9Sstevel@tonic-gate if (tcl == NULL) 5157c478bd9Sstevel@tonic-gate return (ENOSR); 5167c478bd9Sstevel@tonic-gate tcl->tcl_rq = q; /* save read queue pointer */ 5177c478bd9Sstevel@tonic-gate tcl->tcl_flags |= TCLF_ISCLIENT; /* sanity check */ 518*f53eecf5SJames Carlson tcl->tcl_zoneid = crgetzoneid(credp); 5197c478bd9Sstevel@tonic-gate 5207c478bd9Sstevel@tonic-gate q->q_ptr = WR(q)->q_ptr = (caddr_t)tcl; 5217c478bd9Sstevel@tonic-gate *devp = makedevice(getmajor(*devp), tcl->tcl_lsessid); 5227c478bd9Sstevel@tonic-gate 5237c478bd9Sstevel@tonic-gate tcl->tcl_ksp = kstat_setup((kstat_named_t *)&tcl->tcl_kstats, 5247c478bd9Sstevel@tonic-gate tcl_kstats_list, Dim(tcl_kstats_list), "tcl", 5257c478bd9Sstevel@tonic-gate tcl->tcl_lsessid); 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate qprocson(q); 5287c478bd9Sstevel@tonic-gate } 5297c478bd9Sstevel@tonic-gate return (0); 5307c478bd9Sstevel@tonic-gate } 5317c478bd9Sstevel@tonic-gate 5327c478bd9Sstevel@tonic-gate /* 5337c478bd9Sstevel@tonic-gate * Create an appropriate control message for this client event. 5347c478bd9Sstevel@tonic-gate */ 5357c478bd9Sstevel@tonic-gate static mblk_t * 5367c478bd9Sstevel@tonic-gate make_control(tuncl_t *tclabout, tunll_t *tllabout, int action, tuncl_t *tclto) 5377c478bd9Sstevel@tonic-gate { 5387c478bd9Sstevel@tonic-gate struct ppptun_control *ptc; 5397c478bd9Sstevel@tonic-gate mblk_t *mp = allocb(sizeof (*ptc), BPRI_HI); 5407c478bd9Sstevel@tonic-gate 5417c478bd9Sstevel@tonic-gate if (mp != NULL) { 5427c478bd9Sstevel@tonic-gate MTYPE(mp) = M_PROTO; 5437c478bd9Sstevel@tonic-gate ptc = (struct ppptun_control *)mp->b_wptr; 544*f53eecf5SJames Carlson bzero(ptc, sizeof (*ptc)); 5457c478bd9Sstevel@tonic-gate mp->b_wptr += sizeof (*ptc); 5467c478bd9Sstevel@tonic-gate if (tclabout != NULL) { 5477c478bd9Sstevel@tonic-gate ptc->ptc_rsessid = tclabout->tcl_rsessid; 5487c478bd9Sstevel@tonic-gate ptc->ptc_address = tclabout->tcl_address; 5497c478bd9Sstevel@tonic-gate } 5507c478bd9Sstevel@tonic-gate ptc->ptc_discrim = tclto->tcl_ctlval; 5517c478bd9Sstevel@tonic-gate ptc->ptc_action = action; 552*f53eecf5SJames Carlson if (tllabout != NULL) { 5537c478bd9Sstevel@tonic-gate (void) strncpy(ptc->ptc_name, tllabout->tll_name, 5547c478bd9Sstevel@tonic-gate sizeof (ptc->ptc_name)); 5557c478bd9Sstevel@tonic-gate } 556*f53eecf5SJames Carlson } 5577c478bd9Sstevel@tonic-gate return (mp); 5587c478bd9Sstevel@tonic-gate } 5597c478bd9Sstevel@tonic-gate 5607c478bd9Sstevel@tonic-gate /* 5617c478bd9Sstevel@tonic-gate * Send an appropriate control message up this client session. 5627c478bd9Sstevel@tonic-gate */ 5637c478bd9Sstevel@tonic-gate static void 5647c478bd9Sstevel@tonic-gate send_control(tuncl_t *tclabout, tunll_t *tllabout, int action, tuncl_t *tcl) 5657c478bd9Sstevel@tonic-gate { 5667c478bd9Sstevel@tonic-gate mblk_t *mp; 5677c478bd9Sstevel@tonic-gate 5687c478bd9Sstevel@tonic-gate if (tcl->tcl_rq != NULL) { 5697c478bd9Sstevel@tonic-gate mp = make_control(tclabout, tllabout, action, tcl); 5707c478bd9Sstevel@tonic-gate if (mp != NULL) { 5717c478bd9Sstevel@tonic-gate KCINCR(cks_octrl_spec); 5727c478bd9Sstevel@tonic-gate putnext(tcl->tcl_rq, mp); 5737c478bd9Sstevel@tonic-gate } 5747c478bd9Sstevel@tonic-gate } 5757c478bd9Sstevel@tonic-gate } 5767c478bd9Sstevel@tonic-gate 5777c478bd9Sstevel@tonic-gate /* 5787c478bd9Sstevel@tonic-gate * If a lower stream is being unplumbed, then the upper streams 5797c478bd9Sstevel@tonic-gate * connected to this lower stream must be disconnected. This routine 5807c478bd9Sstevel@tonic-gate * accomplishes this by sending M_HANGUP to data streams and M_PROTO 5817c478bd9Sstevel@tonic-gate * messages to control streams. This is called by vmem_walk, and 5827c478bd9Sstevel@tonic-gate * handles a span of minor node numbers. 5837c478bd9Sstevel@tonic-gate * 5847c478bd9Sstevel@tonic-gate * No need to update lks_clients here; the lower stream is on its way 5857c478bd9Sstevel@tonic-gate * out. 5867c478bd9Sstevel@tonic-gate */ 5877c478bd9Sstevel@tonic-gate static void 5887c478bd9Sstevel@tonic-gate tclvm_remove_tll(void *arg, void *firstv, size_t numv) 5897c478bd9Sstevel@tonic-gate { 5907c478bd9Sstevel@tonic-gate tunll_t *tll = (tunll_t *)arg; 5917c478bd9Sstevel@tonic-gate int minorn = (int)(uintptr_t)firstv; 5927c478bd9Sstevel@tonic-gate int minormax = minorn + numv; 5937c478bd9Sstevel@tonic-gate tuncl_t *tcl; 5947c478bd9Sstevel@tonic-gate mblk_t *mp; 5957c478bd9Sstevel@tonic-gate 5967c478bd9Sstevel@tonic-gate while (minorn < minormax) { 5977c478bd9Sstevel@tonic-gate tcl = tcl_slots[minorn - 1]; 5987c478bd9Sstevel@tonic-gate ASSERT(tcl != NULL); 5997c478bd9Sstevel@tonic-gate if (tcl->tcl_data_tll == tll && tcl->tcl_rq != NULL) { 6007c478bd9Sstevel@tonic-gate tcl->tcl_data_tll = NULL; 6017c478bd9Sstevel@tonic-gate mp = allocb(0, BPRI_HI); 6027c478bd9Sstevel@tonic-gate if (mp != NULL) { 6037c478bd9Sstevel@tonic-gate MTYPE(mp) = M_HANGUP; 6047c478bd9Sstevel@tonic-gate putnext(tcl->tcl_rq, mp); 6057c478bd9Sstevel@tonic-gate if (tcl->tcl_ctrl_tll == tll) 6067c478bd9Sstevel@tonic-gate tcl->tcl_ctrl_tll = NULL; 6077c478bd9Sstevel@tonic-gate } 6087c478bd9Sstevel@tonic-gate } 6097c478bd9Sstevel@tonic-gate if (tcl->tcl_ctrl_tll == tll) { 6107c478bd9Sstevel@tonic-gate send_control(tcl, tll, PTCA_UNPLUMB, tcl); 6117c478bd9Sstevel@tonic-gate tcl->tcl_ctrl_tll = NULL; 6127c478bd9Sstevel@tonic-gate } 6137c478bd9Sstevel@tonic-gate minorn++; 6147c478bd9Sstevel@tonic-gate } 6157c478bd9Sstevel@tonic-gate } 6167c478bd9Sstevel@tonic-gate 6177c478bd9Sstevel@tonic-gate /* 6187c478bd9Sstevel@tonic-gate * sppptun_close() 6197c478bd9Sstevel@tonic-gate * 6207c478bd9Sstevel@tonic-gate * MT-Perimeters: 6217c478bd9Sstevel@tonic-gate * exclusive inner, exclusive outer. 6227c478bd9Sstevel@tonic-gate * 6237c478bd9Sstevel@tonic-gate * Description: 6247c478bd9Sstevel@tonic-gate * Common close procedure for module and driver. 6257c478bd9Sstevel@tonic-gate */ 6267c478bd9Sstevel@tonic-gate static int 6277c478bd9Sstevel@tonic-gate sppptun_close(queue_t *q) 6287c478bd9Sstevel@tonic-gate { 6297c478bd9Sstevel@tonic-gate int err; 6307c478bd9Sstevel@tonic-gate void *qptr; 6317c478bd9Sstevel@tonic-gate tunll_t *tll; 6327c478bd9Sstevel@tonic-gate tuncl_t *tcl; 6337c478bd9Sstevel@tonic-gate 6347c478bd9Sstevel@tonic-gate qptr = q->q_ptr; 6357c478bd9Sstevel@tonic-gate 6367c478bd9Sstevel@tonic-gate err = 0; 637002c70ffScarlsonj tll = qptr; 6387c478bd9Sstevel@tonic-gate if (!(tll->tll_flags & TLLF_NOTLOWER)) { 6397c478bd9Sstevel@tonic-gate /* q_next is set on modules */ 6407c478bd9Sstevel@tonic-gate ASSERT(WR(q)->q_next != NULL); 6417c478bd9Sstevel@tonic-gate 6427c478bd9Sstevel@tonic-gate /* unlink any clients using this lower layer. */ 6437c478bd9Sstevel@tonic-gate vmem_walk(tcl_minor_arena, VMEM_ALLOC, tclvm_remove_tll, tll); 6447c478bd9Sstevel@tonic-gate 6457c478bd9Sstevel@tonic-gate /* tell daemon that this has been removed. */ 6467c478bd9Sstevel@tonic-gate if ((tcl = tll->tll_defcl) != NULL) 6477c478bd9Sstevel@tonic-gate send_control(NULL, tll, PTCA_UNPLUMB, tcl); 6487c478bd9Sstevel@tonic-gate 6497c478bd9Sstevel@tonic-gate tll->tll_flags |= TLLF_CLOSING; 6507c478bd9Sstevel@tonic-gate while (!(tll->tll_flags & TLLF_CLOSE_DONE)) { 6517c478bd9Sstevel@tonic-gate qenable(tll->tll_wq); 6527c478bd9Sstevel@tonic-gate qwait(tll->tll_wq); 6537c478bd9Sstevel@tonic-gate } 6547c478bd9Sstevel@tonic-gate tll->tll_error = 0; 6557c478bd9Sstevel@tonic-gate while (!(tll->tll_flags & TLLF_SHUTDOWN_DONE)) { 6567c478bd9Sstevel@tonic-gate if (!qwait_sig(tll->tll_wq)) 6577c478bd9Sstevel@tonic-gate break; 6587c478bd9Sstevel@tonic-gate } 6597c478bd9Sstevel@tonic-gate 6607c478bd9Sstevel@tonic-gate qprocsoff(q); 6617c478bd9Sstevel@tonic-gate q->q_ptr = WR(q)->q_ptr = NULL; 6627c478bd9Sstevel@tonic-gate tll->tll_wq = NULL; 6637c478bd9Sstevel@tonic-gate remque(&tll->tll_next); 6647c478bd9Sstevel@tonic-gate err = tll->tll_error; 6657c478bd9Sstevel@tonic-gate if (tll->tll_ksp != NULL) 6667c478bd9Sstevel@tonic-gate kstat_delete(tll->tll_ksp); 6677c478bd9Sstevel@tonic-gate kmem_free(tll, sizeof (*tll)); 6687c478bd9Sstevel@tonic-gate } else { 669002c70ffScarlsonj tcl = qptr; 6707c478bd9Sstevel@tonic-gate 6717c478bd9Sstevel@tonic-gate /* devices are end of line; no q_next. */ 6727c478bd9Sstevel@tonic-gate ASSERT(WR(q)->q_next == NULL); 6737c478bd9Sstevel@tonic-gate 6747c478bd9Sstevel@tonic-gate qprocsoff(q); 675002c70ffScarlsonj DTRACE_PROBE1(sppptun__client__close, tuncl_t *, tcl); 6767c478bd9Sstevel@tonic-gate tcl->tcl_rq = NULL; 6777c478bd9Sstevel@tonic-gate q->q_ptr = WR(q)->q_ptr = NULL; 6787c478bd9Sstevel@tonic-gate 6797c478bd9Sstevel@tonic-gate tll = TO_TLL(tunll_list.q_forw); 6807c478bd9Sstevel@tonic-gate while (tll != TO_TLL(&tunll_list)) { 6817c478bd9Sstevel@tonic-gate if (tll->tll_defcl == tcl) 6827c478bd9Sstevel@tonic-gate tll->tll_defcl = NULL; 6837c478bd9Sstevel@tonic-gate if (tll->tll_lastcl == tcl) 6847c478bd9Sstevel@tonic-gate tll->tll_lastcl = NULL; 6857c478bd9Sstevel@tonic-gate tll = TO_TLL(tll->tll_next); 6867c478bd9Sstevel@tonic-gate } 6877c478bd9Sstevel@tonic-gate /* 6887c478bd9Sstevel@tonic-gate * If this was a normal session, then tell the daemon. 6897c478bd9Sstevel@tonic-gate */ 6907c478bd9Sstevel@tonic-gate if (!(tcl->tcl_flags & TCLF_DAEMON) && 6917c478bd9Sstevel@tonic-gate (tll = tcl->tcl_ctrl_tll) != NULL && 6927c478bd9Sstevel@tonic-gate tll->tll_defcl != NULL) { 6937c478bd9Sstevel@tonic-gate send_control(tcl, tll, PTCA_DISCONNECT, 6947c478bd9Sstevel@tonic-gate tll->tll_defcl); 6957c478bd9Sstevel@tonic-gate } 6967c478bd9Sstevel@tonic-gate 6977c478bd9Sstevel@tonic-gate /* Update statistics for references being dropped. */ 6987c478bd9Sstevel@tonic-gate if ((tll = tcl->tcl_data_tll) != NULL) { 6997c478bd9Sstevel@tonic-gate KLDECR(lks_clients); 7007c478bd9Sstevel@tonic-gate } 7017c478bd9Sstevel@tonic-gate if ((tll = tcl->tcl_ctrl_tll) != NULL) { 7027c478bd9Sstevel@tonic-gate KLDECR(lks_clients); 7037c478bd9Sstevel@tonic-gate } 7047c478bd9Sstevel@tonic-gate 7057c478bd9Sstevel@tonic-gate tuncl_free(tcl); 7067c478bd9Sstevel@tonic-gate } 7077c478bd9Sstevel@tonic-gate 7087c478bd9Sstevel@tonic-gate return (err); 7097c478bd9Sstevel@tonic-gate } 7107c478bd9Sstevel@tonic-gate 7117c478bd9Sstevel@tonic-gate /* 7127c478bd9Sstevel@tonic-gate * Allocate and initialize a DLPI or TPI template of the specified 7137c478bd9Sstevel@tonic-gate * length. 7147c478bd9Sstevel@tonic-gate */ 7157c478bd9Sstevel@tonic-gate static mblk_t * 7167c478bd9Sstevel@tonic-gate pi_alloc(size_t len, int prim) 7177c478bd9Sstevel@tonic-gate { 7187c478bd9Sstevel@tonic-gate mblk_t *mp; 7197c478bd9Sstevel@tonic-gate 7207c478bd9Sstevel@tonic-gate mp = allocb(len, BPRI_MED); 7217c478bd9Sstevel@tonic-gate if (mp != NULL) { 7227c478bd9Sstevel@tonic-gate MTYPE(mp) = M_PROTO; 7237c478bd9Sstevel@tonic-gate mp->b_wptr = mp->b_rptr + len; 7247c478bd9Sstevel@tonic-gate bzero(mp->b_rptr, len); 7257c478bd9Sstevel@tonic-gate *(int *)mp->b_rptr = prim; 7267c478bd9Sstevel@tonic-gate } 7277c478bd9Sstevel@tonic-gate return (mp); 7287c478bd9Sstevel@tonic-gate } 7297c478bd9Sstevel@tonic-gate 7307c478bd9Sstevel@tonic-gate #define dlpi_alloc(l, p) pi_alloc((l), (p)) 7317c478bd9Sstevel@tonic-gate 7327c478bd9Sstevel@tonic-gate /* 7337c478bd9Sstevel@tonic-gate * Prepend some room to an mblk. Try to reuse the existing buffer, if 7347c478bd9Sstevel@tonic-gate * at all possible, rather than allocating a new one. (Fast-path 7357c478bd9Sstevel@tonic-gate * output should be able to use this.) 7367c478bd9Sstevel@tonic-gate * 7377c478bd9Sstevel@tonic-gate * (XXX why isn't this a library function ...?) 7387c478bd9Sstevel@tonic-gate */ 7397c478bd9Sstevel@tonic-gate static mblk_t * 7407c478bd9Sstevel@tonic-gate prependb(mblk_t *mp, size_t len, size_t align) 7417c478bd9Sstevel@tonic-gate { 7427c478bd9Sstevel@tonic-gate mblk_t *newmp; 7437c478bd9Sstevel@tonic-gate 7447c478bd9Sstevel@tonic-gate 7457c478bd9Sstevel@tonic-gate if (align == 0) 7467c478bd9Sstevel@tonic-gate align = 8; 7477c478bd9Sstevel@tonic-gate if (DB_REF(mp) > 1 || mp->b_datap->db_base+len > mp->b_rptr || 7487c478bd9Sstevel@tonic-gate ((uint_t)((uintptr_t)mp->b_rptr - len) % align) != 0) { 7497c478bd9Sstevel@tonic-gate if ((newmp = allocb(len, BPRI_LO)) == NULL) { 7507c478bd9Sstevel@tonic-gate freemsg(mp); 7517c478bd9Sstevel@tonic-gate return (NULL); 7527c478bd9Sstevel@tonic-gate } 7537c478bd9Sstevel@tonic-gate newmp->b_wptr = newmp->b_rptr + len; 7547c478bd9Sstevel@tonic-gate newmp->b_cont = mp; 7557c478bd9Sstevel@tonic-gate return (newmp); 7567c478bd9Sstevel@tonic-gate } 7577c478bd9Sstevel@tonic-gate mp->b_rptr -= len; 7587c478bd9Sstevel@tonic-gate return (mp); 7597c478bd9Sstevel@tonic-gate } 7607c478bd9Sstevel@tonic-gate 7617c478bd9Sstevel@tonic-gate /* 7627c478bd9Sstevel@tonic-gate * sppptun_outpkt() 7637c478bd9Sstevel@tonic-gate * 7647c478bd9Sstevel@tonic-gate * MT-Perimeters: 7657c478bd9Sstevel@tonic-gate * shared inner, shared outer (if called from sppptun_uwput), 7667c478bd9Sstevel@tonic-gate * exclusive inner, shared outer (if called from sppptun_uwsrv). 7677c478bd9Sstevel@tonic-gate * 7687c478bd9Sstevel@tonic-gate * Description: 7697c478bd9Sstevel@tonic-gate * Called from sppptun_uwput or sppptun_uwsrv when processing a 7707c478bd9Sstevel@tonic-gate * M_DATA, M_PROTO, or M_PCPROTO message. For all cases, it tries 7717c478bd9Sstevel@tonic-gate * to prepare the data to be sent to the module below this driver 7727c478bd9Sstevel@tonic-gate * if there is a lower stream linked underneath. If no lower 7737c478bd9Sstevel@tonic-gate * stream exists, then the data will be discarded and an ENXIO 7747c478bd9Sstevel@tonic-gate * error returned. 7757c478bd9Sstevel@tonic-gate * 7767c478bd9Sstevel@tonic-gate * Returns: 7777c478bd9Sstevel@tonic-gate * pointer to queue if caller should do putnext, otherwise 7787c478bd9Sstevel@tonic-gate * *mpp != NULL if message should be enqueued, otherwise 7797c478bd9Sstevel@tonic-gate * *mpp == NULL if message is gone. 7807c478bd9Sstevel@tonic-gate */ 7817c478bd9Sstevel@tonic-gate static queue_t * 7827c478bd9Sstevel@tonic-gate sppptun_outpkt(queue_t *q, mblk_t **mpp) 7837c478bd9Sstevel@tonic-gate { 7847c478bd9Sstevel@tonic-gate mblk_t *mp; 7857c478bd9Sstevel@tonic-gate tuncl_t *tcl; 7867c478bd9Sstevel@tonic-gate tunll_t *tll; 7877c478bd9Sstevel@tonic-gate mblk_t *encmb; 7887c478bd9Sstevel@tonic-gate mblk_t *datamb; 7897c478bd9Sstevel@tonic-gate dl_unitdata_req_t *dur; 7907c478bd9Sstevel@tonic-gate queue_t *lowerq; 7917c478bd9Sstevel@tonic-gate poep_t *poep; 7927c478bd9Sstevel@tonic-gate int len; 7937c478bd9Sstevel@tonic-gate ether_dest_t *edestp; 7947c478bd9Sstevel@tonic-gate enum { luNone, luCopy, luSend } loopup; 7957c478bd9Sstevel@tonic-gate boolean_t isdata; 7967c478bd9Sstevel@tonic-gate struct ppptun_control *ptc; 7977c478bd9Sstevel@tonic-gate 7987c478bd9Sstevel@tonic-gate mp = *mpp; 799002c70ffScarlsonj tcl = q->q_ptr; 8007c478bd9Sstevel@tonic-gate 8017c478bd9Sstevel@tonic-gate *mpp = NULL; 8027c478bd9Sstevel@tonic-gate if (!(tcl->tcl_flags & TCLF_ISCLIENT)) { 803*f53eecf5SJames Carlson /* This should never happen on a lower layer stream */ 804*f53eecf5SJames Carlson freemsg(mp); 8057c478bd9Sstevel@tonic-gate return (NULL); 8067c478bd9Sstevel@tonic-gate } 8077c478bd9Sstevel@tonic-gate 8087c478bd9Sstevel@tonic-gate isdata = (MTYPE(mp) == M_DATA); 8097c478bd9Sstevel@tonic-gate if (isdata) { 8107c478bd9Sstevel@tonic-gate tll = tcl->tcl_data_tll; 8117c478bd9Sstevel@tonic-gate ptc = NULL; 8127c478bd9Sstevel@tonic-gate } else { 8137c478bd9Sstevel@tonic-gate /* 8147c478bd9Sstevel@tonic-gate * If data are unaligned or otherwise unsuitable, then 8157c478bd9Sstevel@tonic-gate * discard. 8167c478bd9Sstevel@tonic-gate */ 8177c478bd9Sstevel@tonic-gate if (MBLKL(mp) != sizeof (*ptc) || DB_REF(mp) > 1 || 8187c478bd9Sstevel@tonic-gate !IS_P2ALIGNED(mp->b_rptr, sizeof (ptc))) { 8197c478bd9Sstevel@tonic-gate KCINCR(cks_octrl_drop); 820002c70ffScarlsonj DTRACE_PROBE2(sppptun__bad__control, tuncl_t *, tcl, 821002c70ffScarlsonj mblk_t *, mp); 822*f53eecf5SJames Carlson send_control(tcl, tcl->tcl_ctrl_tll, PTCA_BADCTRL, tcl); 823*f53eecf5SJames Carlson freemsg(mp); 8247c478bd9Sstevel@tonic-gate return (NULL); 8257c478bd9Sstevel@tonic-gate } 8267c478bd9Sstevel@tonic-gate ptc = (struct ppptun_control *)mp->b_rptr; 8277c478bd9Sstevel@tonic-gate 8287c478bd9Sstevel@tonic-gate /* Set stream discriminator value if not yet set. */ 8297c478bd9Sstevel@tonic-gate if (tcl->tcl_ctlval == 0) 8307c478bd9Sstevel@tonic-gate tcl->tcl_ctlval = ptc->ptc_discrim; 8317c478bd9Sstevel@tonic-gate 8327c478bd9Sstevel@tonic-gate /* If this is a test message, then reply to caller. */ 8337c478bd9Sstevel@tonic-gate if (ptc->ptc_action == PTCA_TEST) { 834002c70ffScarlsonj DTRACE_PROBE2(sppptun__test, tuncl_t *, tcl, 835002c70ffScarlsonj struct ppptun_control *, ptc); 8367c478bd9Sstevel@tonic-gate if (mp->b_cont != NULL) { 8377c478bd9Sstevel@tonic-gate freemsg(mp->b_cont); 8387c478bd9Sstevel@tonic-gate mp->b_cont = NULL; 8397c478bd9Sstevel@tonic-gate } 8407c478bd9Sstevel@tonic-gate ptc->ptc_discrim = tcl->tcl_ctlval; 8417c478bd9Sstevel@tonic-gate putnext(RD(q), mp); 8427c478bd9Sstevel@tonic-gate return (NULL); 8437c478bd9Sstevel@tonic-gate } 8447c478bd9Sstevel@tonic-gate 8457c478bd9Sstevel@tonic-gate /* If this one isn't for us, then discard it */ 8467c478bd9Sstevel@tonic-gate if (tcl->tcl_ctlval != ptc->ptc_discrim) { 847002c70ffScarlsonj DTRACE_PROBE2(sppptun__bad__discrim, tuncl_t *, tcl, 848002c70ffScarlsonj struct ppptun_control *, ptc); 8497c478bd9Sstevel@tonic-gate freemsg(mp); 8507c478bd9Sstevel@tonic-gate return (NULL); 8517c478bd9Sstevel@tonic-gate } 8527c478bd9Sstevel@tonic-gate 8537c478bd9Sstevel@tonic-gate /* Don't allow empty control packets. */ 854*f53eecf5SJames Carlson tll = tcl->tcl_ctrl_tll; 8557c478bd9Sstevel@tonic-gate if (mp->b_cont == NULL) { 8567c478bd9Sstevel@tonic-gate KCINCR(cks_octrl_drop); 857*f53eecf5SJames Carlson DTRACE_PROBE2(sppptun__bad__control, tuncl_t *, tcl, 858*f53eecf5SJames Carlson mblk_t *, mp); 859*f53eecf5SJames Carlson send_control(tcl, tll, PTCA_BADCTRL, tcl); 860*f53eecf5SJames Carlson freemsg(mp); 8617c478bd9Sstevel@tonic-gate return (NULL); 8627c478bd9Sstevel@tonic-gate } 8637c478bd9Sstevel@tonic-gate } 8647c478bd9Sstevel@tonic-gate 8657c478bd9Sstevel@tonic-gate if (tll == NULL || (lowerq = tll->tll_wq) == NULL) { 866002c70ffScarlsonj DTRACE_PROBE3(sppptun__cannot__send, tuncl_t *, tcl, 867002c70ffScarlsonj tunll_t *, tll, mblk_t *, mp); 868*f53eecf5SJames Carlson send_control(tcl, tll, PTCA_UNPLUMB, tcl); 869*f53eecf5SJames Carlson freemsg(mp); 8707c478bd9Sstevel@tonic-gate if (isdata) { 8717c478bd9Sstevel@tonic-gate tcl->tcl_stats.ppp_oerrors++; 8727c478bd9Sstevel@tonic-gate } else { 8737c478bd9Sstevel@tonic-gate KCINCR(cks_octrl_drop); 8747c478bd9Sstevel@tonic-gate } 8757c478bd9Sstevel@tonic-gate return (NULL); 8767c478bd9Sstevel@tonic-gate } 8777c478bd9Sstevel@tonic-gate 8787c478bd9Sstevel@tonic-gate /* 8797c478bd9Sstevel@tonic-gate * If so, then try to send it down. The lower queue is only 8807c478bd9Sstevel@tonic-gate * ever detached while holding an exclusive lock on the whole 8817c478bd9Sstevel@tonic-gate * driver, so we can be confident that the lower queue is 8827c478bd9Sstevel@tonic-gate * still there. 8837c478bd9Sstevel@tonic-gate */ 8847c478bd9Sstevel@tonic-gate if (!bcanputnext(lowerq, mp->b_band)) { 885002c70ffScarlsonj DTRACE_PROBE3(sppptun__flow__control, tuncl_t *, tcl, 886002c70ffScarlsonj tunll_t *, tll, mblk_t *, mp); 8877c478bd9Sstevel@tonic-gate *mpp = mp; 8887c478bd9Sstevel@tonic-gate return (NULL); 8897c478bd9Sstevel@tonic-gate } 8907c478bd9Sstevel@tonic-gate 8917c478bd9Sstevel@tonic-gate /* 8927c478bd9Sstevel@tonic-gate * Note: DLPI and TPI expect that the first buffer contains 8937c478bd9Sstevel@tonic-gate * the control (unitdata-req) header, destination address, and 8947c478bd9Sstevel@tonic-gate * nothing else. Any protocol headers must go in the next 8957c478bd9Sstevel@tonic-gate * buffer. 8967c478bd9Sstevel@tonic-gate */ 8977c478bd9Sstevel@tonic-gate loopup = luNone; 8987c478bd9Sstevel@tonic-gate encmb = NULL; 8997c478bd9Sstevel@tonic-gate if (isdata) { 9007c478bd9Sstevel@tonic-gate if (tll->tll_alen != 0 && 9017c478bd9Sstevel@tonic-gate bcmp(&tcl->tcl_address, &tll->tll_lcladdr, 9027c478bd9Sstevel@tonic-gate tll->tll_alen) == 0) 9037c478bd9Sstevel@tonic-gate loopup = luSend; 9047c478bd9Sstevel@tonic-gate switch (tll->tll_style) { 9057c478bd9Sstevel@tonic-gate case PTS_PPPOE: 9067c478bd9Sstevel@tonic-gate /* Strip address and control fields if present. */ 9077c478bd9Sstevel@tonic-gate if (mp->b_rptr[0] == 0xFF) { 9087c478bd9Sstevel@tonic-gate if (MBLKL(mp) < 3) { 9097c478bd9Sstevel@tonic-gate encmb = msgpullup(mp, 3); 9107c478bd9Sstevel@tonic-gate freemsg(mp); 9117c478bd9Sstevel@tonic-gate if ((mp = encmb) == NULL) 9127c478bd9Sstevel@tonic-gate break; 9137c478bd9Sstevel@tonic-gate } 9147c478bd9Sstevel@tonic-gate mp->b_rptr += 2; 9157c478bd9Sstevel@tonic-gate } 9167c478bd9Sstevel@tonic-gate /* Broadcasting data is probably not a good idea. */ 9177c478bd9Sstevel@tonic-gate if (tcl->tcl_address.pta_pppoe.ptma_mac[0] & 1) 9187c478bd9Sstevel@tonic-gate break; 9197c478bd9Sstevel@tonic-gate encmb = dlpi_alloc(sizeof (*dur) + sizeof (*edestp), 9207c478bd9Sstevel@tonic-gate DL_UNITDATA_REQ); 9217c478bd9Sstevel@tonic-gate if (encmb == NULL) 9227c478bd9Sstevel@tonic-gate break; 9237c478bd9Sstevel@tonic-gate 9247c478bd9Sstevel@tonic-gate dur = (dl_unitdata_req_t *)encmb->b_rptr; 9257c478bd9Sstevel@tonic-gate dur->dl_dest_addr_length = sizeof (*edestp); 9267c478bd9Sstevel@tonic-gate dur->dl_dest_addr_offset = sizeof (*dur); 9277c478bd9Sstevel@tonic-gate edestp = (ether_dest_t *)(dur + 1); 9287c478bd9Sstevel@tonic-gate ether_copy(tcl->tcl_address.pta_pppoe.ptma_mac, 9297c478bd9Sstevel@tonic-gate edestp->addr); 9307c478bd9Sstevel@tonic-gate /* DLPI SAPs are in host byte order! */ 931*f53eecf5SJames Carlson edestp->type = tll->tll_sap; 9327c478bd9Sstevel@tonic-gate 9337c478bd9Sstevel@tonic-gate /* Make sure the protocol field isn't compressed. */ 9347c478bd9Sstevel@tonic-gate len = (*mp->b_rptr & 1); 9357c478bd9Sstevel@tonic-gate mp = prependb(mp, sizeof (*poep) + len, POE_HDR_ALIGN); 9367c478bd9Sstevel@tonic-gate if (mp == NULL) 9377c478bd9Sstevel@tonic-gate break; 9387c478bd9Sstevel@tonic-gate poep = (poep_t *)mp->b_rptr; 9397c478bd9Sstevel@tonic-gate poep->poep_version_type = POE_VERSION; 9407c478bd9Sstevel@tonic-gate poep->poep_code = POECODE_DATA; 9417c478bd9Sstevel@tonic-gate poep->poep_session_id = htons(tcl->tcl_rsessid); 9427c478bd9Sstevel@tonic-gate poep->poep_length = htons(msgsize(mp) - 9437c478bd9Sstevel@tonic-gate sizeof (*poep)); 9447c478bd9Sstevel@tonic-gate if (len > 0) 9457c478bd9Sstevel@tonic-gate *(char *)(poep + 1) = '\0'; 9467c478bd9Sstevel@tonic-gate break; 9477c478bd9Sstevel@tonic-gate 9487c478bd9Sstevel@tonic-gate default: 9497c478bd9Sstevel@tonic-gate ASSERT(0); 9507c478bd9Sstevel@tonic-gate } 9517c478bd9Sstevel@tonic-gate } else { 9527c478bd9Sstevel@tonic-gate /* 9537c478bd9Sstevel@tonic-gate * Control side encapsulation. 9547c478bd9Sstevel@tonic-gate */ 9557c478bd9Sstevel@tonic-gate if (bcmp(&ptc->ptc_address, &tll->tll_lcladdr, tll->tll_alen) 9567c478bd9Sstevel@tonic-gate == 0) 9577c478bd9Sstevel@tonic-gate loopup = luSend; 9587c478bd9Sstevel@tonic-gate datamb = mp->b_cont; 9597c478bd9Sstevel@tonic-gate switch (tll->tll_style) { 9607c478bd9Sstevel@tonic-gate case PTS_PPPOE: 9617c478bd9Sstevel@tonic-gate /* 9627c478bd9Sstevel@tonic-gate * Don't allow a loopback session to establish 9637c478bd9Sstevel@tonic-gate * itself. PPPoE is broken; it uses only one 9647c478bd9Sstevel@tonic-gate * session ID for both data directions, so the 9657c478bd9Sstevel@tonic-gate * loopback data path can simply never work. 9667c478bd9Sstevel@tonic-gate */ 9677c478bd9Sstevel@tonic-gate if (loopup == luSend && 9687c478bd9Sstevel@tonic-gate ((poep_t *)datamb->b_rptr)->poep_code == 9697c478bd9Sstevel@tonic-gate POECODE_PADR) 9707c478bd9Sstevel@tonic-gate break; 9717c478bd9Sstevel@tonic-gate encmb = dlpi_alloc(sizeof (*dur) + sizeof (*edestp), 9727c478bd9Sstevel@tonic-gate DL_UNITDATA_REQ); 9737c478bd9Sstevel@tonic-gate if (encmb == NULL) 9747c478bd9Sstevel@tonic-gate break; 9757c478bd9Sstevel@tonic-gate dur = (dl_unitdata_req_t *)encmb->b_rptr; 9767c478bd9Sstevel@tonic-gate dur->dl_dest_addr_length = sizeof (*edestp); 9777c478bd9Sstevel@tonic-gate dur->dl_dest_addr_offset = sizeof (*dur); 9787c478bd9Sstevel@tonic-gate 9797c478bd9Sstevel@tonic-gate edestp = (ether_dest_t *)(dur + 1); 9807c478bd9Sstevel@tonic-gate /* DLPI SAPs are in host byte order! */ 981*f53eecf5SJames Carlson edestp->type = tll->tll_sap; 9827c478bd9Sstevel@tonic-gate 9837c478bd9Sstevel@tonic-gate /* 9847c478bd9Sstevel@tonic-gate * If destination isn't set yet, then we have to 9857c478bd9Sstevel@tonic-gate * allow anything at all. Otherwise, force use 9867c478bd9Sstevel@tonic-gate * of configured peer address. 9877c478bd9Sstevel@tonic-gate */ 9887c478bd9Sstevel@tonic-gate if (bcmp(tcl->tcl_address.pta_pppoe.ptma_mac, 9897c478bd9Sstevel@tonic-gate zero_mac_addr, sizeof (zero_mac_addr)) == 0 || 9907c478bd9Sstevel@tonic-gate (tcl->tcl_flags & TCLF_DAEMON)) { 9917c478bd9Sstevel@tonic-gate ether_copy(ptc->ptc_address.pta_pppoe.ptma_mac, 9927c478bd9Sstevel@tonic-gate edestp->addr); 9937c478bd9Sstevel@tonic-gate } else { 9947c478bd9Sstevel@tonic-gate ether_copy(tcl->tcl_address.pta_pppoe.ptma_mac, 9957c478bd9Sstevel@tonic-gate edestp->addr); 9967c478bd9Sstevel@tonic-gate } 9977c478bd9Sstevel@tonic-gate /* Reflect multicast/broadcast back up. */ 9987c478bd9Sstevel@tonic-gate if (edestp->addr[0] & 1) 9997c478bd9Sstevel@tonic-gate loopup = luCopy; 10007c478bd9Sstevel@tonic-gate break; 10017c478bd9Sstevel@tonic-gate 10027c478bd9Sstevel@tonic-gate case PTS_PPTP: 10037c478bd9Sstevel@tonic-gate /* 10047c478bd9Sstevel@tonic-gate * PPTP's control side is actually done over 10057c478bd9Sstevel@tonic-gate * separate TCP connections. 10067c478bd9Sstevel@tonic-gate */ 10077c478bd9Sstevel@tonic-gate default: 10087c478bd9Sstevel@tonic-gate ASSERT(0); 10097c478bd9Sstevel@tonic-gate } 10107c478bd9Sstevel@tonic-gate freeb(mp); 10117c478bd9Sstevel@tonic-gate mp = datamb; 10127c478bd9Sstevel@tonic-gate } 10137c478bd9Sstevel@tonic-gate if (mp == NULL || encmb == NULL) { 1014002c70ffScarlsonj DTRACE_PROBE1(sppptun__output__failure, tuncl_t *, tcl); 10157c478bd9Sstevel@tonic-gate freemsg(mp); 10167c478bd9Sstevel@tonic-gate freemsg(encmb); 10177c478bd9Sstevel@tonic-gate if (isdata) { 10187c478bd9Sstevel@tonic-gate tcl->tcl_stats.ppp_oerrors++; 10197c478bd9Sstevel@tonic-gate } else { 10207c478bd9Sstevel@tonic-gate KCINCR(cks_octrl_drop); 10217c478bd9Sstevel@tonic-gate KLINCR(lks_octrl_drop); 10227c478bd9Sstevel@tonic-gate } 10237c478bd9Sstevel@tonic-gate lowerq = NULL; 10247c478bd9Sstevel@tonic-gate } else { 10257c478bd9Sstevel@tonic-gate if (isdata) { 10267c478bd9Sstevel@tonic-gate tcl->tcl_stats.ppp_obytes += msgsize(mp); 10277c478bd9Sstevel@tonic-gate tcl->tcl_stats.ppp_opackets++; 10287c478bd9Sstevel@tonic-gate } else { 10297c478bd9Sstevel@tonic-gate KCINCR(cks_octrls); 10307c478bd9Sstevel@tonic-gate KLINCR(lks_octrls); 10317c478bd9Sstevel@tonic-gate } 10327c478bd9Sstevel@tonic-gate if (encmb != mp) 10337c478bd9Sstevel@tonic-gate encmb->b_cont = mp; 10347c478bd9Sstevel@tonic-gate switch (loopup) { 10357c478bd9Sstevel@tonic-gate case luNone: 10367c478bd9Sstevel@tonic-gate *mpp = encmb; 10377c478bd9Sstevel@tonic-gate break; 10387c478bd9Sstevel@tonic-gate case luCopy: 10397c478bd9Sstevel@tonic-gate mp = copymsg(encmb); 10407c478bd9Sstevel@tonic-gate if (mp != NULL) 10417c478bd9Sstevel@tonic-gate sppptun_urput(RD(lowerq), mp); 10427c478bd9Sstevel@tonic-gate *mpp = encmb; 10437c478bd9Sstevel@tonic-gate break; 10447c478bd9Sstevel@tonic-gate case luSend: 10457c478bd9Sstevel@tonic-gate sppptun_urput(RD(lowerq), encmb); 10467c478bd9Sstevel@tonic-gate lowerq = NULL; 10477c478bd9Sstevel@tonic-gate break; 10487c478bd9Sstevel@tonic-gate } 10497c478bd9Sstevel@tonic-gate } 10507c478bd9Sstevel@tonic-gate return (lowerq); 10517c478bd9Sstevel@tonic-gate } 10527c478bd9Sstevel@tonic-gate 10537c478bd9Sstevel@tonic-gate /* 10547c478bd9Sstevel@tonic-gate * Enqueue a message to be sent when the lower stream is closed. This 10557c478bd9Sstevel@tonic-gate * is done so that we're guaranteed that we always have the necessary 10567c478bd9Sstevel@tonic-gate * resources to properly detach ourselves from the system. (If we 10577c478bd9Sstevel@tonic-gate * waited until the close was done to allocate these messages, then 10587c478bd9Sstevel@tonic-gate * the message allocation could fail, and we'd be unable to properly 10597c478bd9Sstevel@tonic-gate * detach.) 10607c478bd9Sstevel@tonic-gate */ 10617c478bd9Sstevel@tonic-gate static void 10627c478bd9Sstevel@tonic-gate save_for_close(tunll_t *tll, mblk_t *mp) 10637c478bd9Sstevel@tonic-gate { 10647c478bd9Sstevel@tonic-gate mblk_t *onc; 10657c478bd9Sstevel@tonic-gate 10667c478bd9Sstevel@tonic-gate if ((onc = tll->tll_onclose) == NULL) 10677c478bd9Sstevel@tonic-gate tll->tll_onclose = mp; 10687c478bd9Sstevel@tonic-gate else { 10697c478bd9Sstevel@tonic-gate while (onc->b_next != NULL) 10707c478bd9Sstevel@tonic-gate onc = onc->b_next; 10717c478bd9Sstevel@tonic-gate onc->b_next = mp; 10727c478bd9Sstevel@tonic-gate } 10737c478bd9Sstevel@tonic-gate } 10747c478bd9Sstevel@tonic-gate 10757c478bd9Sstevel@tonic-gate /* 10767c478bd9Sstevel@tonic-gate * Given the lower stream name, locate the state structure. Note that 10777c478bd9Sstevel@tonic-gate * lookup of tcl pointers (and use of those pointers) is safe because 10787c478bd9Sstevel@tonic-gate * modification is done only when exclusive on both inner and outer 10797c478bd9Sstevel@tonic-gate * perimeters. 10807c478bd9Sstevel@tonic-gate */ 10817c478bd9Sstevel@tonic-gate static tunll_t * 1082*f53eecf5SJames Carlson tll_lookup_on_name(const char *dname, zoneid_t zoneid) 10837c478bd9Sstevel@tonic-gate { 10847c478bd9Sstevel@tonic-gate tunll_t *tll; 10857c478bd9Sstevel@tonic-gate 10867c478bd9Sstevel@tonic-gate tll = TO_TLL(tunll_list.q_forw); 10877c478bd9Sstevel@tonic-gate for (; tll != TO_TLL(&tunll_list); tll = TO_TLL(tll->tll_next)) 1088*f53eecf5SJames Carlson if (tll->tll_zoneid == zoneid && 1089*f53eecf5SJames Carlson strcmp(dname, tll->tll_name) == 0) 10907c478bd9Sstevel@tonic-gate return (tll); 10917c478bd9Sstevel@tonic-gate return (NULL); 10927c478bd9Sstevel@tonic-gate } 10937c478bd9Sstevel@tonic-gate 10947c478bd9Sstevel@tonic-gate /* 10957c478bd9Sstevel@tonic-gate * sppptun_inner_ioctl() 10967c478bd9Sstevel@tonic-gate * 10977c478bd9Sstevel@tonic-gate * MT-Perimeters: 10987c478bd9Sstevel@tonic-gate * exclusive inner, shared outer. 10997c478bd9Sstevel@tonic-gate * 11007c478bd9Sstevel@tonic-gate * Description: 11017c478bd9Sstevel@tonic-gate * Called by qwriter from sppptun_ioctl as the result of receiving 11027c478bd9Sstevel@tonic-gate * a handled ioctl. 11037c478bd9Sstevel@tonic-gate */ 11047c478bd9Sstevel@tonic-gate static void 11057c478bd9Sstevel@tonic-gate sppptun_inner_ioctl(queue_t *q, mblk_t *mp) 11067c478bd9Sstevel@tonic-gate { 11077c478bd9Sstevel@tonic-gate struct iocblk *iop; 11087c478bd9Sstevel@tonic-gate int rc = 0; 11097c478bd9Sstevel@tonic-gate int len = 0; 11107c478bd9Sstevel@tonic-gate int i; 11117c478bd9Sstevel@tonic-gate tuncl_t *tcl; 11127c478bd9Sstevel@tonic-gate tunll_t *tll; 11137c478bd9Sstevel@tonic-gate union ppptun_name *ptn; 11147c478bd9Sstevel@tonic-gate struct ppptun_info *pti; 11157c478bd9Sstevel@tonic-gate struct ppptun_peer *ptp; 11167c478bd9Sstevel@tonic-gate mblk_t *mptmp; 11177c478bd9Sstevel@tonic-gate ppptun_atype *pap; 11187c478bd9Sstevel@tonic-gate struct ppp_stats64 *psp; 1119*f53eecf5SJames Carlson zoneid_t zoneid; 11207c478bd9Sstevel@tonic-gate 11217c478bd9Sstevel@tonic-gate iop = (struct iocblk *)mp->b_rptr; 11227c478bd9Sstevel@tonic-gate tcl = NULL; 1123002c70ffScarlsonj tll = q->q_ptr; 11247c478bd9Sstevel@tonic-gate if (tll->tll_flags & TLLF_NOTLOWER) { 11257c478bd9Sstevel@tonic-gate tcl = (tuncl_t *)tll; 11267c478bd9Sstevel@tonic-gate tll = NULL; 11277c478bd9Sstevel@tonic-gate } 11287c478bd9Sstevel@tonic-gate 1129002c70ffScarlsonj DTRACE_PROBE3(sppptun__ioctl, tuncl_t *, tcl, tunll_t *, tll, 1130002c70ffScarlsonj struct iocblk *, iop); 1131002c70ffScarlsonj 11327c478bd9Sstevel@tonic-gate switch (iop->ioc_cmd) { 11337c478bd9Sstevel@tonic-gate case PPPIO_DEBUG: 1134002c70ffScarlsonj /* 1135002c70ffScarlsonj * Debug requests are now ignored; use dtrace or wireshark 1136002c70ffScarlsonj * instead. 1137002c70ffScarlsonj */ 11387c478bd9Sstevel@tonic-gate break; 11397c478bd9Sstevel@tonic-gate 11407c478bd9Sstevel@tonic-gate case PPPIO_GETSTAT: 11417c478bd9Sstevel@tonic-gate rc = EINVAL; 11427c478bd9Sstevel@tonic-gate break; 11437c478bd9Sstevel@tonic-gate 11447c478bd9Sstevel@tonic-gate case PPPIO_GETSTAT64: 11457c478bd9Sstevel@tonic-gate /* Client (device) side only */ 11467c478bd9Sstevel@tonic-gate if (tcl == NULL) { 11477c478bd9Sstevel@tonic-gate rc = EINVAL; 11487c478bd9Sstevel@tonic-gate break; 11497c478bd9Sstevel@tonic-gate } 11507c478bd9Sstevel@tonic-gate mptmp = allocb(sizeof (*psp), BPRI_HI); 11517c478bd9Sstevel@tonic-gate if (mptmp == NULL) { 11527c478bd9Sstevel@tonic-gate rc = ENOSR; 11537c478bd9Sstevel@tonic-gate break; 11547c478bd9Sstevel@tonic-gate } 11557c478bd9Sstevel@tonic-gate freemsg(mp->b_cont); 11567c478bd9Sstevel@tonic-gate mp->b_cont = mptmp; 11577c478bd9Sstevel@tonic-gate 11587c478bd9Sstevel@tonic-gate psp = (struct ppp_stats64 *)mptmp->b_wptr; 11597c478bd9Sstevel@tonic-gate bzero((caddr_t)psp, sizeof (*psp)); 11607c478bd9Sstevel@tonic-gate psp->p = tcl->tcl_stats; 11617c478bd9Sstevel@tonic-gate 11627c478bd9Sstevel@tonic-gate len = sizeof (*psp); 11637c478bd9Sstevel@tonic-gate break; 11647c478bd9Sstevel@tonic-gate 11657c478bd9Sstevel@tonic-gate case PPPTUN_SNAME: 11667c478bd9Sstevel@tonic-gate /* This is done on the *module* (lower level) side. */ 11677c478bd9Sstevel@tonic-gate if (tll == NULL || mp->b_cont == NULL || 11687c478bd9Sstevel@tonic-gate iop->ioc_count != sizeof (*ptn) || 11697c478bd9Sstevel@tonic-gate *mp->b_cont->b_rptr == '\0') { 11707c478bd9Sstevel@tonic-gate rc = EINVAL; 11717c478bd9Sstevel@tonic-gate break; 11727c478bd9Sstevel@tonic-gate } 11737c478bd9Sstevel@tonic-gate 11747c478bd9Sstevel@tonic-gate ptn = (union ppptun_name *)mp->b_cont->b_rptr; 11757c478bd9Sstevel@tonic-gate ptn->ptn_name[sizeof (ptn->ptn_name) - 1] = '\0'; 11767c478bd9Sstevel@tonic-gate 1177*f53eecf5SJames Carlson tll = tll_lookup_on_name(ptn->ptn_name, tll->tll_zoneid); 1178*f53eecf5SJames Carlson if (tll != NULL) { 11797c478bd9Sstevel@tonic-gate rc = EEXIST; 11807c478bd9Sstevel@tonic-gate break; 11817c478bd9Sstevel@tonic-gate } 11827c478bd9Sstevel@tonic-gate tll = (tunll_t *)q->q_ptr; 11837c478bd9Sstevel@tonic-gate (void) strcpy(tll->tll_name, ptn->ptn_name); 11847c478bd9Sstevel@tonic-gate break; 11857c478bd9Sstevel@tonic-gate 11867c478bd9Sstevel@tonic-gate case PPPTUN_SINFO: 11877c478bd9Sstevel@tonic-gate case PPPTUN_GINFO: 11887c478bd9Sstevel@tonic-gate /* Either side */ 11897c478bd9Sstevel@tonic-gate if (mp->b_cont == NULL || iop->ioc_count != sizeof (*pti)) { 11907c478bd9Sstevel@tonic-gate rc = EINVAL; 11917c478bd9Sstevel@tonic-gate break; 11927c478bd9Sstevel@tonic-gate } 11937c478bd9Sstevel@tonic-gate pti = (struct ppptun_info *)mp->b_cont->b_rptr; 11947c478bd9Sstevel@tonic-gate if (pti->pti_name[0] != '\0') 1195*f53eecf5SJames Carlson tll = tll_lookup_on_name(pti->pti_name, 1196*f53eecf5SJames Carlson tcl == NULL ? tll->tll_zoneid : tcl->tcl_zoneid); 11977c478bd9Sstevel@tonic-gate if (tll == NULL) { 11987c478bd9Sstevel@tonic-gate /* Driver (client) side must have name */ 1199002c70ffScarlsonj if (tcl != NULL && pti->pti_name[0] == '\0') 12007c478bd9Sstevel@tonic-gate rc = EINVAL; 1201002c70ffScarlsonj else 12027c478bd9Sstevel@tonic-gate rc = ESRCH; 12037c478bd9Sstevel@tonic-gate break; 12047c478bd9Sstevel@tonic-gate } 12057c478bd9Sstevel@tonic-gate if (iop->ioc_cmd == PPPTUN_GINFO) { 12067c478bd9Sstevel@tonic-gate pti->pti_muxid = tll->tll_muxid; 12077c478bd9Sstevel@tonic-gate pti->pti_style = tll->tll_style; 12087c478bd9Sstevel@tonic-gate len = sizeof (*pti); 12097c478bd9Sstevel@tonic-gate break; 12107c478bd9Sstevel@tonic-gate } 12117c478bd9Sstevel@tonic-gate tll->tll_muxid = pti->pti_muxid; 12127c478bd9Sstevel@tonic-gate tll->tll_style = pti->pti_style; 12137c478bd9Sstevel@tonic-gate switch (tll->tll_style) { 12147c478bd9Sstevel@tonic-gate case PTS_PPPOE: /* DLPI type */ 12157c478bd9Sstevel@tonic-gate tll->tll_alen = sizeof (tll->tll_lcladdr.pta_pppoe); 12167c478bd9Sstevel@tonic-gate mptmp = dlpi_alloc(sizeof (dl_unbind_req_t), 12177c478bd9Sstevel@tonic-gate DL_UNBIND_REQ); 12187c478bd9Sstevel@tonic-gate if (mptmp == NULL) { 12197c478bd9Sstevel@tonic-gate rc = ENOSR; 12207c478bd9Sstevel@tonic-gate break; 12217c478bd9Sstevel@tonic-gate } 12227c478bd9Sstevel@tonic-gate save_for_close(tll, mptmp); 12237c478bd9Sstevel@tonic-gate mptmp = dlpi_alloc(sizeof (dl_detach_req_t), 12247c478bd9Sstevel@tonic-gate DL_DETACH_REQ); 12257c478bd9Sstevel@tonic-gate if (mptmp == NULL) { 12267c478bd9Sstevel@tonic-gate rc = ENOSR; 12277c478bd9Sstevel@tonic-gate break; 12287c478bd9Sstevel@tonic-gate } 12297c478bd9Sstevel@tonic-gate save_for_close(tll, mptmp); 12307c478bd9Sstevel@tonic-gate break; 12317c478bd9Sstevel@tonic-gate default: 12327c478bd9Sstevel@tonic-gate tll->tll_style = PTS_NONE; 12337c478bd9Sstevel@tonic-gate tll->tll_alen = 0; 12347c478bd9Sstevel@tonic-gate rc = EINVAL; 12357c478bd9Sstevel@tonic-gate break; 12367c478bd9Sstevel@tonic-gate } 12377c478bd9Sstevel@tonic-gate break; 12387c478bd9Sstevel@tonic-gate 12397c478bd9Sstevel@tonic-gate case PPPTUN_GNNAME: 12407c478bd9Sstevel@tonic-gate /* This can be done on either side. */ 12417c478bd9Sstevel@tonic-gate if (mp->b_cont == NULL || iop->ioc_count < sizeof (uint32_t)) { 12427c478bd9Sstevel@tonic-gate rc = EINVAL; 12437c478bd9Sstevel@tonic-gate break; 12447c478bd9Sstevel@tonic-gate } 1245*f53eecf5SJames Carlson zoneid = tcl == NULL ? tll->tll_zoneid : tcl->tcl_zoneid; 12467c478bd9Sstevel@tonic-gate ptn = (union ppptun_name *)mp->b_cont->b_rptr; 12477c478bd9Sstevel@tonic-gate i = ptn->ptn_index; 12487c478bd9Sstevel@tonic-gate tll = TO_TLL(tunll_list.q_forw); 1249*f53eecf5SJames Carlson while (tll != TO_TLL(&tunll_list)) { 1250*f53eecf5SJames Carlson if (tll->tll_zoneid == zoneid && --i < 0) 1251*f53eecf5SJames Carlson break; 12527c478bd9Sstevel@tonic-gate tll = TO_TLL(tll->tll_next); 1253*f53eecf5SJames Carlson } 12547c478bd9Sstevel@tonic-gate if (tll != TO_TLL(&tunll_list)) { 12557c478bd9Sstevel@tonic-gate bcopy(tll->tll_name, ptn->ptn_name, 12567c478bd9Sstevel@tonic-gate sizeof (ptn->ptn_name)); 12577c478bd9Sstevel@tonic-gate } else { 12587c478bd9Sstevel@tonic-gate bzero(ptn, sizeof (*ptn)); 12597c478bd9Sstevel@tonic-gate } 12607c478bd9Sstevel@tonic-gate len = sizeof (*ptn); 12617c478bd9Sstevel@tonic-gate break; 12627c478bd9Sstevel@tonic-gate 12637c478bd9Sstevel@tonic-gate case PPPTUN_LCLADDR: 12647c478bd9Sstevel@tonic-gate /* This is done on the *module* (lower level) side. */ 12657c478bd9Sstevel@tonic-gate if (tll == NULL || mp->b_cont == NULL) { 12667c478bd9Sstevel@tonic-gate rc = EINVAL; 12677c478bd9Sstevel@tonic-gate break; 12687c478bd9Sstevel@tonic-gate } 12697c478bd9Sstevel@tonic-gate 12707c478bd9Sstevel@tonic-gate pap = &tll->tll_lcladdr; 12717c478bd9Sstevel@tonic-gate len = tll->tll_alen; 12727c478bd9Sstevel@tonic-gate if (len == 0 || len > iop->ioc_count) { 12737c478bd9Sstevel@tonic-gate rc = EINVAL; 12747c478bd9Sstevel@tonic-gate break; 12757c478bd9Sstevel@tonic-gate } 12767c478bd9Sstevel@tonic-gate bcopy(mp->b_cont->b_rptr, pap, len); 12777c478bd9Sstevel@tonic-gate len = 0; 12787c478bd9Sstevel@tonic-gate break; 12797c478bd9Sstevel@tonic-gate 12807c478bd9Sstevel@tonic-gate case PPPTUN_SPEER: 12817c478bd9Sstevel@tonic-gate /* Client (device) side only; before SDATA */ 12827c478bd9Sstevel@tonic-gate if (tcl == NULL || mp->b_cont == NULL || 12837c478bd9Sstevel@tonic-gate iop->ioc_count != sizeof (*ptp)) { 12847c478bd9Sstevel@tonic-gate rc = EINVAL; 12857c478bd9Sstevel@tonic-gate break; 12867c478bd9Sstevel@tonic-gate } 12877c478bd9Sstevel@tonic-gate if (tcl->tcl_data_tll != NULL) { 12887c478bd9Sstevel@tonic-gate rc = EINVAL; 12897c478bd9Sstevel@tonic-gate break; 12907c478bd9Sstevel@tonic-gate } 12917c478bd9Sstevel@tonic-gate ptp = (struct ppptun_peer *)mp->b_cont->b_rptr; 1292002c70ffScarlsonj DTRACE_PROBE2(sppptun__speer, tuncl_t *, tcl, 1293002c70ffScarlsonj struct ppptun_peer *, ptp); 12947c478bd9Sstevel@tonic-gate /* Once set, the style cannot change. */ 12957c478bd9Sstevel@tonic-gate if (tcl->tcl_style != PTS_NONE && 12967c478bd9Sstevel@tonic-gate tcl->tcl_style != ptp->ptp_style) { 12977c478bd9Sstevel@tonic-gate rc = EINVAL; 12987c478bd9Sstevel@tonic-gate break; 12997c478bd9Sstevel@tonic-gate } 13007c478bd9Sstevel@tonic-gate if (ptp->ptp_flags & PTPF_DAEMON) { 13017c478bd9Sstevel@tonic-gate /* User requests registration for tunnel 0 */ 13027c478bd9Sstevel@tonic-gate if ((tcl->tcl_flags & TCLF_SPEER_DONE) || 13037c478bd9Sstevel@tonic-gate ptp->ptp_ltunid != 0 || ptp->ptp_rtunid != 0 || 13047c478bd9Sstevel@tonic-gate ptp->ptp_lsessid != 0 || ptp->ptp_rsessid != 0) { 13057c478bd9Sstevel@tonic-gate rc = EINVAL; 13067c478bd9Sstevel@tonic-gate break; 13077c478bd9Sstevel@tonic-gate } 13087c478bd9Sstevel@tonic-gate tcl->tcl_flags |= TCLF_DAEMON; 13097c478bd9Sstevel@tonic-gate } else { 13107c478bd9Sstevel@tonic-gate /* Normal client connection */ 13117c478bd9Sstevel@tonic-gate if (tcl->tcl_flags & TCLF_DAEMON) { 13127c478bd9Sstevel@tonic-gate rc = EINVAL; 13137c478bd9Sstevel@tonic-gate break; 13147c478bd9Sstevel@tonic-gate } 13157c478bd9Sstevel@tonic-gate if (ptp->ptp_lsessid != 0 && 13167c478bd9Sstevel@tonic-gate ptp->ptp_lsessid != tcl->tcl_lsessid) { 13177c478bd9Sstevel@tonic-gate rc = EINVAL; 13187c478bd9Sstevel@tonic-gate break; 13197c478bd9Sstevel@tonic-gate } 13207c478bd9Sstevel@tonic-gate /* 13217c478bd9Sstevel@tonic-gate * If we're reassigning the peer data, then 13227c478bd9Sstevel@tonic-gate * the previous assignment must have been for 13237c478bd9Sstevel@tonic-gate * a client control connection. Check that. 13247c478bd9Sstevel@tonic-gate */ 13257c478bd9Sstevel@tonic-gate if ((tcl->tcl_flags & TCLF_SPEER_DONE) && 13267c478bd9Sstevel@tonic-gate ((tcl->tcl_ltunid != 0 && 13277c478bd9Sstevel@tonic-gate tcl->tcl_ltunid != ptp->ptp_ltunid) || 13287c478bd9Sstevel@tonic-gate (tcl->tcl_rtunid != 0 && 13297c478bd9Sstevel@tonic-gate tcl->tcl_rtunid != ptp->ptp_rtunid) || 13307c478bd9Sstevel@tonic-gate (tcl->tcl_rsessid != 0 && 13317c478bd9Sstevel@tonic-gate tcl->tcl_rsessid != ptp->ptp_rsessid))) { 13327c478bd9Sstevel@tonic-gate rc = EINVAL; 13337c478bd9Sstevel@tonic-gate break; 13347c478bd9Sstevel@tonic-gate } 13357c478bd9Sstevel@tonic-gate if ((tcl->tcl_ltunid = ptp->ptp_ltunid) == 0 && 13367c478bd9Sstevel@tonic-gate tcl->tcl_style == PTS_L2FTP) 13377c478bd9Sstevel@tonic-gate tcl->tcl_ltunid = ptp->ptp_lsessid; 13387c478bd9Sstevel@tonic-gate tcl->tcl_rtunid = ptp->ptp_rtunid; 13397c478bd9Sstevel@tonic-gate tcl->tcl_rsessid = ptp->ptp_rsessid; 13407c478bd9Sstevel@tonic-gate } 13417c478bd9Sstevel@tonic-gate tcl->tcl_flags |= TCLF_SPEER_DONE; 13427c478bd9Sstevel@tonic-gate tcl->tcl_style = ptp->ptp_style; 13437c478bd9Sstevel@tonic-gate tcl->tcl_address = ptp->ptp_address; 13447c478bd9Sstevel@tonic-gate goto fill_in_peer; 13457c478bd9Sstevel@tonic-gate 13467c478bd9Sstevel@tonic-gate case PPPTUN_GPEER: 13477c478bd9Sstevel@tonic-gate /* Client (device) side only */ 13487c478bd9Sstevel@tonic-gate if (tcl == NULL) { 13497c478bd9Sstevel@tonic-gate rc = EINVAL; 13507c478bd9Sstevel@tonic-gate break; 13517c478bd9Sstevel@tonic-gate } 13527c478bd9Sstevel@tonic-gate if (mp->b_cont != NULL) 13537c478bd9Sstevel@tonic-gate freemsg(mp->b_cont); 13547c478bd9Sstevel@tonic-gate mp->b_cont = allocb(sizeof (*ptp), BPRI_HI); 13557c478bd9Sstevel@tonic-gate if (mp->b_cont == NULL) { 13567c478bd9Sstevel@tonic-gate rc = ENOSR; 13577c478bd9Sstevel@tonic-gate break; 13587c478bd9Sstevel@tonic-gate } 13597c478bd9Sstevel@tonic-gate ptp = (struct ppptun_peer *)mp->b_cont->b_rptr; 13607c478bd9Sstevel@tonic-gate fill_in_peer: 13617c478bd9Sstevel@tonic-gate ptp->ptp_style = tcl->tcl_style; 13627c478bd9Sstevel@tonic-gate ptp->ptp_flags = (tcl->tcl_flags & TCLF_DAEMON) ? PTPF_DAEMON : 13637c478bd9Sstevel@tonic-gate 0; 13647c478bd9Sstevel@tonic-gate ptp->ptp_ltunid = tcl->tcl_ltunid; 13657c478bd9Sstevel@tonic-gate ptp->ptp_rtunid = tcl->tcl_rtunid; 13667c478bd9Sstevel@tonic-gate ptp->ptp_lsessid = tcl->tcl_lsessid; 13677c478bd9Sstevel@tonic-gate ptp->ptp_rsessid = tcl->tcl_rsessid; 13687c478bd9Sstevel@tonic-gate ptp->ptp_address = tcl->tcl_address; 13697c478bd9Sstevel@tonic-gate len = sizeof (*ptp); 13707c478bd9Sstevel@tonic-gate break; 13717c478bd9Sstevel@tonic-gate 13727c478bd9Sstevel@tonic-gate case PPPTUN_SDATA: 13737c478bd9Sstevel@tonic-gate case PPPTUN_SCTL: 13747c478bd9Sstevel@tonic-gate /* Client (device) side only; must do SPEER first */ 13757c478bd9Sstevel@tonic-gate if (tcl == NULL || mp->b_cont == NULL || 13767c478bd9Sstevel@tonic-gate iop->ioc_count != sizeof (*ptn) || 13777c478bd9Sstevel@tonic-gate *mp->b_cont->b_rptr == '\0') { 13787c478bd9Sstevel@tonic-gate rc = EINVAL; 13797c478bd9Sstevel@tonic-gate break; 13807c478bd9Sstevel@tonic-gate } 13817c478bd9Sstevel@tonic-gate if (!(tcl->tcl_flags & TCLF_SPEER_DONE)) { 13827c478bd9Sstevel@tonic-gate rc = EINVAL; 13837c478bd9Sstevel@tonic-gate break; 13847c478bd9Sstevel@tonic-gate } 13857c478bd9Sstevel@tonic-gate ptn = (union ppptun_name *)mp->b_cont->b_rptr; 13867c478bd9Sstevel@tonic-gate ptn->ptn_name[sizeof (ptn->ptn_name) - 1] = '\0'; 1387*f53eecf5SJames Carlson tll = tll_lookup_on_name(ptn->ptn_name, tcl->tcl_zoneid); 13887c478bd9Sstevel@tonic-gate if (tll == NULL) { 13897c478bd9Sstevel@tonic-gate rc = ESRCH; 13907c478bd9Sstevel@tonic-gate break; 13917c478bd9Sstevel@tonic-gate } 13927c478bd9Sstevel@tonic-gate if (tll->tll_style != tcl->tcl_style) { 13937c478bd9Sstevel@tonic-gate rc = ENXIO; 13947c478bd9Sstevel@tonic-gate break; 13957c478bd9Sstevel@tonic-gate } 13967c478bd9Sstevel@tonic-gate if (iop->ioc_cmd == PPPTUN_SDATA) { 13977c478bd9Sstevel@tonic-gate if (tcl->tcl_data_tll != NULL) { 13987c478bd9Sstevel@tonic-gate rc = EEXIST; 13997c478bd9Sstevel@tonic-gate break; 14007c478bd9Sstevel@tonic-gate } 14017c478bd9Sstevel@tonic-gate /* server daemons cannot use regular data */ 14027c478bd9Sstevel@tonic-gate if (tcl->tcl_flags & TCLF_DAEMON) { 14037c478bd9Sstevel@tonic-gate rc = EINVAL; 14047c478bd9Sstevel@tonic-gate break; 14057c478bd9Sstevel@tonic-gate } 14067c478bd9Sstevel@tonic-gate tcl->tcl_data_tll = tll; 14077c478bd9Sstevel@tonic-gate } else if (tcl->tcl_flags & TCLF_DAEMON) { 14087c478bd9Sstevel@tonic-gate if (tll->tll_defcl != NULL && tll->tll_defcl != tcl) { 14097c478bd9Sstevel@tonic-gate rc = EEXIST; 14107c478bd9Sstevel@tonic-gate break; 14117c478bd9Sstevel@tonic-gate } 14127c478bd9Sstevel@tonic-gate tll->tll_defcl = tcl; 14137c478bd9Sstevel@tonic-gate if (tcl->tcl_ctrl_tll != NULL) { 14147c478bd9Sstevel@tonic-gate KDECR(tcl->tcl_ctrl_tll, tll_kstats, 14157c478bd9Sstevel@tonic-gate lks_clients); 14167c478bd9Sstevel@tonic-gate } 14177c478bd9Sstevel@tonic-gate tcl->tcl_ctrl_tll = tll; 14187c478bd9Sstevel@tonic-gate } else { 14197c478bd9Sstevel@tonic-gate if (tcl->tcl_ctrl_tll != NULL) { 14207c478bd9Sstevel@tonic-gate rc = EEXIST; 14217c478bd9Sstevel@tonic-gate break; 14227c478bd9Sstevel@tonic-gate } 14237c478bd9Sstevel@tonic-gate tcl->tcl_ctrl_tll = tll; 14247c478bd9Sstevel@tonic-gate } 14257c478bd9Sstevel@tonic-gate KLINCR(lks_clients); 14267c478bd9Sstevel@tonic-gate break; 14277c478bd9Sstevel@tonic-gate 14287c478bd9Sstevel@tonic-gate case PPPTUN_GDATA: 14297c478bd9Sstevel@tonic-gate case PPPTUN_GCTL: 14307c478bd9Sstevel@tonic-gate /* Client (device) side only */ 14317c478bd9Sstevel@tonic-gate if (tcl == NULL) { 14327c478bd9Sstevel@tonic-gate rc = EINVAL; 14337c478bd9Sstevel@tonic-gate break; 14347c478bd9Sstevel@tonic-gate } 14357c478bd9Sstevel@tonic-gate if (mp->b_cont != NULL) 14367c478bd9Sstevel@tonic-gate freemsg(mp->b_cont); 14377c478bd9Sstevel@tonic-gate mp->b_cont = allocb(sizeof (*ptn), BPRI_HI); 14387c478bd9Sstevel@tonic-gate if (mp->b_cont == NULL) { 14397c478bd9Sstevel@tonic-gate rc = ENOSR; 14407c478bd9Sstevel@tonic-gate break; 14417c478bd9Sstevel@tonic-gate } 14427c478bd9Sstevel@tonic-gate ptn = (union ppptun_name *)mp->b_cont->b_rptr; 14437c478bd9Sstevel@tonic-gate if (iop->ioc_cmd == PPPTUN_GDATA) 14447c478bd9Sstevel@tonic-gate tll = tcl->tcl_data_tll; 14457c478bd9Sstevel@tonic-gate else 14467c478bd9Sstevel@tonic-gate tll = tcl->tcl_ctrl_tll; 14477c478bd9Sstevel@tonic-gate if (tll == NULL) 14487c478bd9Sstevel@tonic-gate bzero(ptn, sizeof (*ptn)); 14497c478bd9Sstevel@tonic-gate else 14507c478bd9Sstevel@tonic-gate bcopy(tll->tll_name, ptn->ptn_name, 14517c478bd9Sstevel@tonic-gate sizeof (ptn->ptn_name)); 14527c478bd9Sstevel@tonic-gate len = sizeof (*ptn); 14537c478bd9Sstevel@tonic-gate break; 14547c478bd9Sstevel@tonic-gate 14557c478bd9Sstevel@tonic-gate case PPPTUN_DCTL: 14567c478bd9Sstevel@tonic-gate /* Client (device) side daemon mode only */ 14577c478bd9Sstevel@tonic-gate if (tcl == NULL || mp->b_cont == NULL || 14587c478bd9Sstevel@tonic-gate iop->ioc_count != sizeof (*ptn) || 14597c478bd9Sstevel@tonic-gate !(tcl->tcl_flags & TCLF_DAEMON)) { 14607c478bd9Sstevel@tonic-gate rc = EINVAL; 14617c478bd9Sstevel@tonic-gate break; 14627c478bd9Sstevel@tonic-gate } 14637c478bd9Sstevel@tonic-gate ptn = (union ppptun_name *)mp->b_cont->b_rptr; 14647c478bd9Sstevel@tonic-gate ptn->ptn_name[sizeof (ptn->ptn_name) - 1] = '\0'; 1465*f53eecf5SJames Carlson tll = tll_lookup_on_name(ptn->ptn_name, tcl->tcl_zoneid); 14667c478bd9Sstevel@tonic-gate if (tll == NULL || tll->tll_defcl != tcl) { 14677c478bd9Sstevel@tonic-gate rc = ESRCH; 14687c478bd9Sstevel@tonic-gate break; 14697c478bd9Sstevel@tonic-gate } 14707c478bd9Sstevel@tonic-gate tll->tll_defcl = NULL; 14717c478bd9Sstevel@tonic-gate break; 14727c478bd9Sstevel@tonic-gate 1473*f53eecf5SJames Carlson case PPPTUN_SSAP: 1474*f53eecf5SJames Carlson /* This is done on the *module* (lower level) side. */ 1475*f53eecf5SJames Carlson if (tll == NULL || mp->b_cont == NULL || 1476*f53eecf5SJames Carlson iop->ioc_count != sizeof (uint_t)) { 1477*f53eecf5SJames Carlson rc = EINVAL; 1478*f53eecf5SJames Carlson break; 1479*f53eecf5SJames Carlson } 1480*f53eecf5SJames Carlson 1481*f53eecf5SJames Carlson tll->tll_sap = *(uint_t *)mp->b_cont->b_rptr; 1482*f53eecf5SJames Carlson break; 1483*f53eecf5SJames Carlson 14847c478bd9Sstevel@tonic-gate default: 14857c478bd9Sstevel@tonic-gate /* Caller should already have checked command value */ 14867c478bd9Sstevel@tonic-gate ASSERT(0); 14877c478bd9Sstevel@tonic-gate } 14887c478bd9Sstevel@tonic-gate if (rc != 0) { 14897c478bd9Sstevel@tonic-gate miocnak(q, mp, 0, rc); 14907c478bd9Sstevel@tonic-gate } else { 14917c478bd9Sstevel@tonic-gate if (len > 0) 14927c478bd9Sstevel@tonic-gate mp->b_cont->b_wptr = mp->b_cont->b_rptr + len; 14937c478bd9Sstevel@tonic-gate miocack(q, mp, len, 0); 14947c478bd9Sstevel@tonic-gate } 14957c478bd9Sstevel@tonic-gate } 14967c478bd9Sstevel@tonic-gate 14977c478bd9Sstevel@tonic-gate /* 14987c478bd9Sstevel@tonic-gate * sppptun_ioctl() 14997c478bd9Sstevel@tonic-gate * 15007c478bd9Sstevel@tonic-gate * MT-Perimeters: 15017c478bd9Sstevel@tonic-gate * shared inner, shared outer. 15027c478bd9Sstevel@tonic-gate * 15037c478bd9Sstevel@tonic-gate * Description: 15047c478bd9Sstevel@tonic-gate * Called by sppptun_uwput as the result of receiving a M_IOCTL command. 15057c478bd9Sstevel@tonic-gate */ 15067c478bd9Sstevel@tonic-gate static void 15077c478bd9Sstevel@tonic-gate sppptun_ioctl(queue_t *q, mblk_t *mp) 15087c478bd9Sstevel@tonic-gate { 15097c478bd9Sstevel@tonic-gate struct iocblk *iop; 15107c478bd9Sstevel@tonic-gate int rc = 0; 15117c478bd9Sstevel@tonic-gate int len = 0; 15127c478bd9Sstevel@tonic-gate uint32_t val = 0; 15137c478bd9Sstevel@tonic-gate tunll_t *tll; 15147c478bd9Sstevel@tonic-gate 15157c478bd9Sstevel@tonic-gate iop = (struct iocblk *)mp->b_rptr; 15167c478bd9Sstevel@tonic-gate 15177c478bd9Sstevel@tonic-gate switch (iop->ioc_cmd) { 15187c478bd9Sstevel@tonic-gate case PPPIO_DEBUG: 15197c478bd9Sstevel@tonic-gate case PPPIO_GETSTAT: 15207c478bd9Sstevel@tonic-gate case PPPIO_GETSTAT64: 15217c478bd9Sstevel@tonic-gate case PPPTUN_SNAME: 15227c478bd9Sstevel@tonic-gate case PPPTUN_SINFO: 15237c478bd9Sstevel@tonic-gate case PPPTUN_GINFO: 15247c478bd9Sstevel@tonic-gate case PPPTUN_GNNAME: 15257c478bd9Sstevel@tonic-gate case PPPTUN_LCLADDR: 15267c478bd9Sstevel@tonic-gate case PPPTUN_SPEER: 15277c478bd9Sstevel@tonic-gate case PPPTUN_GPEER: 15287c478bd9Sstevel@tonic-gate case PPPTUN_SDATA: 15297c478bd9Sstevel@tonic-gate case PPPTUN_GDATA: 15307c478bd9Sstevel@tonic-gate case PPPTUN_SCTL: 15317c478bd9Sstevel@tonic-gate case PPPTUN_GCTL: 15327c478bd9Sstevel@tonic-gate case PPPTUN_DCTL: 1533*f53eecf5SJames Carlson case PPPTUN_SSAP: 15347c478bd9Sstevel@tonic-gate qwriter(q, mp, sppptun_inner_ioctl, PERIM_INNER); 15357c478bd9Sstevel@tonic-gate return; 15367c478bd9Sstevel@tonic-gate 15377c478bd9Sstevel@tonic-gate case PPPIO_GCLEAN: /* always clean */ 15387c478bd9Sstevel@tonic-gate val = RCV_B7_1 | RCV_B7_0 | RCV_ODDP | RCV_EVNP; 15397c478bd9Sstevel@tonic-gate len = sizeof (uint32_t); 15407c478bd9Sstevel@tonic-gate break; 15417c478bd9Sstevel@tonic-gate 15427c478bd9Sstevel@tonic-gate case PPPIO_GTYPE: /* we look like an async driver. */ 15437c478bd9Sstevel@tonic-gate val = PPPTYP_AHDLC; 15447c478bd9Sstevel@tonic-gate len = sizeof (uint32_t); 15457c478bd9Sstevel@tonic-gate break; 15467c478bd9Sstevel@tonic-gate 15477c478bd9Sstevel@tonic-gate case PPPIO_CFLAGS: /* never compress headers */ 15487c478bd9Sstevel@tonic-gate val = 0; 15497c478bd9Sstevel@tonic-gate len = sizeof (uint32_t); 15507c478bd9Sstevel@tonic-gate break; 15517c478bd9Sstevel@tonic-gate 15527c478bd9Sstevel@tonic-gate /* quietly ack PPP things we don't need to do. */ 15537c478bd9Sstevel@tonic-gate case PPPIO_XFCS: 15547c478bd9Sstevel@tonic-gate case PPPIO_RFCS: 15557c478bd9Sstevel@tonic-gate case PPPIO_XACCM: 15567c478bd9Sstevel@tonic-gate case PPPIO_RACCM: 15577c478bd9Sstevel@tonic-gate case PPPIO_LASTMOD: 15587c478bd9Sstevel@tonic-gate case PPPIO_MUX: 15597c478bd9Sstevel@tonic-gate case I_PLINK: 15607c478bd9Sstevel@tonic-gate case I_PUNLINK: 15617c478bd9Sstevel@tonic-gate case I_LINK: 15627c478bd9Sstevel@tonic-gate case I_UNLINK: 15637c478bd9Sstevel@tonic-gate break; 15647c478bd9Sstevel@tonic-gate 15657c478bd9Sstevel@tonic-gate default: 15667c478bd9Sstevel@tonic-gate tll = (tunll_t *)q->q_ptr; 15677c478bd9Sstevel@tonic-gate if (!(tll->tll_flags & TLLF_NOTLOWER)) { 15687c478bd9Sstevel@tonic-gate /* module side; pass this through. */ 15697c478bd9Sstevel@tonic-gate putnext(q, mp); 15707c478bd9Sstevel@tonic-gate return; 15717c478bd9Sstevel@tonic-gate } 15727c478bd9Sstevel@tonic-gate rc = EINVAL; 15737c478bd9Sstevel@tonic-gate break; 15747c478bd9Sstevel@tonic-gate } 15757c478bd9Sstevel@tonic-gate if (rc == 0 && len == sizeof (uint32_t)) { 15767c478bd9Sstevel@tonic-gate if (mp->b_cont != NULL) 15777c478bd9Sstevel@tonic-gate freemsg(mp->b_cont); 15787c478bd9Sstevel@tonic-gate mp->b_cont = allocb(sizeof (uint32_t), BPRI_HI); 15797c478bd9Sstevel@tonic-gate if (mp->b_cont == NULL) { 15807c478bd9Sstevel@tonic-gate rc = ENOSR; 15817c478bd9Sstevel@tonic-gate } else { 15827c478bd9Sstevel@tonic-gate *(uint32_t *)mp->b_cont->b_wptr = val; 15837c478bd9Sstevel@tonic-gate mp->b_cont->b_wptr += sizeof (uint32_t); 15847c478bd9Sstevel@tonic-gate } 15857c478bd9Sstevel@tonic-gate } 15867c478bd9Sstevel@tonic-gate if (rc == 0) { 15877c478bd9Sstevel@tonic-gate miocack(q, mp, len, 0); 15887c478bd9Sstevel@tonic-gate } else { 15897c478bd9Sstevel@tonic-gate miocnak(q, mp, 0, rc); 15907c478bd9Sstevel@tonic-gate } 15917c478bd9Sstevel@tonic-gate } 15927c478bd9Sstevel@tonic-gate 15937c478bd9Sstevel@tonic-gate /* 15947c478bd9Sstevel@tonic-gate * sppptun_inner_mctl() 15957c478bd9Sstevel@tonic-gate * 15967c478bd9Sstevel@tonic-gate * MT-Perimeters: 15977c478bd9Sstevel@tonic-gate * exclusive inner, shared outer. 15987c478bd9Sstevel@tonic-gate * 15997c478bd9Sstevel@tonic-gate * Description: 16007c478bd9Sstevel@tonic-gate * Called by qwriter (via sppptun_uwput) as the result of receiving 16017c478bd9Sstevel@tonic-gate * an M_CTL. Called only on the client (driver) side. 16027c478bd9Sstevel@tonic-gate */ 16037c478bd9Sstevel@tonic-gate static void 16047c478bd9Sstevel@tonic-gate sppptun_inner_mctl(queue_t *q, mblk_t *mp) 16057c478bd9Sstevel@tonic-gate { 16067c478bd9Sstevel@tonic-gate int msglen; 16077c478bd9Sstevel@tonic-gate tuncl_t *tcl; 16087c478bd9Sstevel@tonic-gate 1609002c70ffScarlsonj tcl = q->q_ptr; 16107c478bd9Sstevel@tonic-gate 16117c478bd9Sstevel@tonic-gate if (!(tcl->tcl_flags & TCLF_ISCLIENT)) { 16127c478bd9Sstevel@tonic-gate freemsg(mp); 16137c478bd9Sstevel@tonic-gate return; 16147c478bd9Sstevel@tonic-gate } 16157c478bd9Sstevel@tonic-gate 16167c478bd9Sstevel@tonic-gate msglen = MBLKL(mp); 16177c478bd9Sstevel@tonic-gate switch (*mp->b_rptr) { 16187c478bd9Sstevel@tonic-gate case PPPCTL_UNIT: 16197c478bd9Sstevel@tonic-gate if (msglen == 2) 16207c478bd9Sstevel@tonic-gate tcl->tcl_unit = mp->b_rptr[1]; 16217c478bd9Sstevel@tonic-gate else if (msglen == 8) 16227c478bd9Sstevel@tonic-gate tcl->tcl_unit = ((uint32_t *)mp->b_rptr)[1]; 16237c478bd9Sstevel@tonic-gate break; 16247c478bd9Sstevel@tonic-gate } 16257c478bd9Sstevel@tonic-gate freemsg(mp); 16267c478bd9Sstevel@tonic-gate } 16277c478bd9Sstevel@tonic-gate 16287c478bd9Sstevel@tonic-gate /* 16297c478bd9Sstevel@tonic-gate * sppptun_uwput() 16307c478bd9Sstevel@tonic-gate * 16317c478bd9Sstevel@tonic-gate * MT-Perimeters: 16327c478bd9Sstevel@tonic-gate * shared inner, shared outer. 16337c478bd9Sstevel@tonic-gate * 16347c478bd9Sstevel@tonic-gate * Description: 16357c478bd9Sstevel@tonic-gate * Regular output data and controls pass through here. 16367c478bd9Sstevel@tonic-gate */ 16377c478bd9Sstevel@tonic-gate static void 16387c478bd9Sstevel@tonic-gate sppptun_uwput(queue_t *q, mblk_t *mp) 16397c478bd9Sstevel@tonic-gate { 16407c478bd9Sstevel@tonic-gate queue_t *nextq; 16417c478bd9Sstevel@tonic-gate tuncl_t *tcl; 16427c478bd9Sstevel@tonic-gate 16437c478bd9Sstevel@tonic-gate ASSERT(q->q_ptr != NULL); 16447c478bd9Sstevel@tonic-gate 16457c478bd9Sstevel@tonic-gate switch (MTYPE(mp)) { 16467c478bd9Sstevel@tonic-gate case M_DATA: 16477c478bd9Sstevel@tonic-gate case M_PROTO: 16487c478bd9Sstevel@tonic-gate case M_PCPROTO: 16497c478bd9Sstevel@tonic-gate if (q->q_first == NULL && 16507c478bd9Sstevel@tonic-gate (nextq = sppptun_outpkt(q, &mp)) != NULL) { 16517c478bd9Sstevel@tonic-gate putnext(nextq, mp); 16527c478bd9Sstevel@tonic-gate } else if (mp != NULL && !putq(q, mp)) { 16537c478bd9Sstevel@tonic-gate freemsg(mp); 16547c478bd9Sstevel@tonic-gate } 16557c478bd9Sstevel@tonic-gate break; 16567c478bd9Sstevel@tonic-gate case M_IOCTL: 16577c478bd9Sstevel@tonic-gate sppptun_ioctl(q, mp); 16587c478bd9Sstevel@tonic-gate break; 16597c478bd9Sstevel@tonic-gate case M_CTL: 16607c478bd9Sstevel@tonic-gate qwriter(q, mp, sppptun_inner_mctl, PERIM_INNER); 16617c478bd9Sstevel@tonic-gate break; 16627c478bd9Sstevel@tonic-gate default: 16637c478bd9Sstevel@tonic-gate tcl = (tuncl_t *)q->q_ptr; 16647c478bd9Sstevel@tonic-gate /* 16657c478bd9Sstevel@tonic-gate * If we're the driver, then discard unknown junk. 16667c478bd9Sstevel@tonic-gate * Otherwise, if we're the module, then forward along. 16677c478bd9Sstevel@tonic-gate */ 16687c478bd9Sstevel@tonic-gate if (tcl->tcl_flags & TCLF_ISCLIENT) 16697c478bd9Sstevel@tonic-gate freemsg(mp); 16707c478bd9Sstevel@tonic-gate else 16717c478bd9Sstevel@tonic-gate putnext(q, mp); 16727c478bd9Sstevel@tonic-gate break; 16737c478bd9Sstevel@tonic-gate } 16747c478bd9Sstevel@tonic-gate } 16757c478bd9Sstevel@tonic-gate 16767c478bd9Sstevel@tonic-gate /* 16777c478bd9Sstevel@tonic-gate * Send a DLPI/TPI control message to the driver but make sure there 16787c478bd9Sstevel@tonic-gate * is only one outstanding message. Uses tll_msg_pending to tell when 16797c478bd9Sstevel@tonic-gate * it must queue. sppptun_urput calls message_done() when an ACK or a 16807c478bd9Sstevel@tonic-gate * NAK is received to process the next queued message. 16817c478bd9Sstevel@tonic-gate */ 16827c478bd9Sstevel@tonic-gate static void 16837c478bd9Sstevel@tonic-gate message_send(tunll_t *tll, mblk_t *mp) 16847c478bd9Sstevel@tonic-gate { 16857c478bd9Sstevel@tonic-gate mblk_t **mpp; 16867c478bd9Sstevel@tonic-gate 16877c478bd9Sstevel@tonic-gate if (tll->tll_msg_pending) { 16887c478bd9Sstevel@tonic-gate /* Must queue message. Tail insertion */ 16897c478bd9Sstevel@tonic-gate mpp = &tll->tll_msg_deferred; 16907c478bd9Sstevel@tonic-gate while (*mpp != NULL) 16917c478bd9Sstevel@tonic-gate mpp = &((*mpp)->b_next); 16927c478bd9Sstevel@tonic-gate *mpp = mp; 16937c478bd9Sstevel@tonic-gate return; 16947c478bd9Sstevel@tonic-gate } 16957c478bd9Sstevel@tonic-gate tll->tll_msg_pending = 1; 16967c478bd9Sstevel@tonic-gate putnext(tll->tll_wq, mp); 16977c478bd9Sstevel@tonic-gate } 16987c478bd9Sstevel@tonic-gate 16997c478bd9Sstevel@tonic-gate /* 17007c478bd9Sstevel@tonic-gate * Called when an DLPI/TPI control message has been acked or nacked to 17017c478bd9Sstevel@tonic-gate * send down the next queued message (if any). 17027c478bd9Sstevel@tonic-gate */ 17037c478bd9Sstevel@tonic-gate static void 17047c478bd9Sstevel@tonic-gate message_done(tunll_t *tll) 17057c478bd9Sstevel@tonic-gate { 17067c478bd9Sstevel@tonic-gate mblk_t *mp; 17077c478bd9Sstevel@tonic-gate 17087c478bd9Sstevel@tonic-gate ASSERT(tll->tll_msg_pending); 17097c478bd9Sstevel@tonic-gate tll->tll_msg_pending = 0; 17107c478bd9Sstevel@tonic-gate mp = tll->tll_msg_deferred; 17117c478bd9Sstevel@tonic-gate if (mp != NULL) { 17127c478bd9Sstevel@tonic-gate tll->tll_msg_deferred = mp->b_next; 17137c478bd9Sstevel@tonic-gate mp->b_next = NULL; 17147c478bd9Sstevel@tonic-gate tll->tll_msg_pending = 1; 17157c478bd9Sstevel@tonic-gate putnext(tll->tll_wq, mp); 17167c478bd9Sstevel@tonic-gate } 17177c478bd9Sstevel@tonic-gate } 17187c478bd9Sstevel@tonic-gate 17197c478bd9Sstevel@tonic-gate /* 17207c478bd9Sstevel@tonic-gate * Send down queued "close" messages to lower stream. These were 17217c478bd9Sstevel@tonic-gate * enqueued right after the stream was originally allocated, when the 17227c478bd9Sstevel@tonic-gate * tll_style was set by PPPTUN_SINFO. 17237c478bd9Sstevel@tonic-gate */ 17247c478bd9Sstevel@tonic-gate static int 17257c478bd9Sstevel@tonic-gate tll_close_req(tunll_t *tll) 17267c478bd9Sstevel@tonic-gate { 17277c478bd9Sstevel@tonic-gate mblk_t *mb, *mbnext; 17287c478bd9Sstevel@tonic-gate 17297c478bd9Sstevel@tonic-gate if ((mb = tll->tll_onclose) == NULL) 17307c478bd9Sstevel@tonic-gate tll->tll_flags |= TLLF_SHUTDOWN_DONE; 17317c478bd9Sstevel@tonic-gate else { 17327c478bd9Sstevel@tonic-gate tll->tll_onclose = NULL; 17337c478bd9Sstevel@tonic-gate while (mb != NULL) { 17347c478bd9Sstevel@tonic-gate mbnext = mb->b_next; 17357c478bd9Sstevel@tonic-gate mb->b_next = NULL; 17367c478bd9Sstevel@tonic-gate message_send(tll, mb); 17377c478bd9Sstevel@tonic-gate mb = mbnext; 17387c478bd9Sstevel@tonic-gate } 17397c478bd9Sstevel@tonic-gate } 17407c478bd9Sstevel@tonic-gate return (0); 17417c478bd9Sstevel@tonic-gate } 17427c478bd9Sstevel@tonic-gate 17437c478bd9Sstevel@tonic-gate /* 1744002c70ffScarlsonj * This function is called when a backenable occurs on the write side of a 1745002c70ffScarlsonj * lower stream. It walks over the client streams, looking for ones that use 1746002c70ffScarlsonj * the given tunll_t lower stream. Each client is then backenabled. 1747002c70ffScarlsonj */ 1748002c70ffScarlsonj static void 1749002c70ffScarlsonj tclvm_backenable(void *arg, void *firstv, size_t numv) 1750002c70ffScarlsonj { 1751002c70ffScarlsonj tunll_t *tll = arg; 1752002c70ffScarlsonj int minorn = (int)(uintptr_t)firstv; 1753002c70ffScarlsonj int minormax = minorn + numv; 1754002c70ffScarlsonj tuncl_t *tcl; 1755002c70ffScarlsonj queue_t *q; 1756002c70ffScarlsonj 1757002c70ffScarlsonj while (minorn < minormax) { 1758002c70ffScarlsonj tcl = tcl_slots[minorn - 1]; 1759002c70ffScarlsonj if ((tcl->tcl_data_tll == tll || 1760002c70ffScarlsonj tcl->tcl_ctrl_tll == tll) && 1761002c70ffScarlsonj (q = tcl->tcl_rq) != NULL) { 1762002c70ffScarlsonj qenable(OTHERQ(q)); 1763002c70ffScarlsonj } 1764002c70ffScarlsonj minorn++; 1765002c70ffScarlsonj } 1766002c70ffScarlsonj } 1767002c70ffScarlsonj 1768002c70ffScarlsonj /* 17697c478bd9Sstevel@tonic-gate * sppptun_uwsrv() 17707c478bd9Sstevel@tonic-gate * 17717c478bd9Sstevel@tonic-gate * MT-Perimeters: 17727c478bd9Sstevel@tonic-gate * exclusive inner, shared outer. 17737c478bd9Sstevel@tonic-gate * 17747c478bd9Sstevel@tonic-gate * Description: 17757c478bd9Sstevel@tonic-gate * Upper write-side service procedure. In addition to the usual 17767c478bd9Sstevel@tonic-gate * STREAMS queue service handling, this routine also handles the 17777c478bd9Sstevel@tonic-gate * transmission of the unbind/detach messages to the lower stream 17787c478bd9Sstevel@tonic-gate * driver when a lower stream is being closed. (See the use of 17797c478bd9Sstevel@tonic-gate * qenable/qwait in sppptun_close().) 17807c478bd9Sstevel@tonic-gate */ 17817c478bd9Sstevel@tonic-gate static int 17827c478bd9Sstevel@tonic-gate sppptun_uwsrv(queue_t *q) 17837c478bd9Sstevel@tonic-gate { 17847c478bd9Sstevel@tonic-gate tuncl_t *tcl; 17857c478bd9Sstevel@tonic-gate mblk_t *mp; 17867c478bd9Sstevel@tonic-gate queue_t *nextq; 17877c478bd9Sstevel@tonic-gate 1788002c70ffScarlsonj tcl = q->q_ptr; 17897c478bd9Sstevel@tonic-gate if (!(tcl->tcl_flags & TCLF_ISCLIENT)) { 17907c478bd9Sstevel@tonic-gate tunll_t *tll = (tunll_t *)tcl; 1791002c70ffScarlsonj 17927c478bd9Sstevel@tonic-gate if ((tll->tll_flags & (TLLF_CLOSING|TLLF_CLOSE_DONE)) == 17937c478bd9Sstevel@tonic-gate TLLF_CLOSING) { 17947c478bd9Sstevel@tonic-gate tll->tll_error = tll_close_req(tll); 17957c478bd9Sstevel@tonic-gate tll->tll_flags |= TLLF_CLOSE_DONE; 1796002c70ffScarlsonj } else { 1797002c70ffScarlsonj /* 1798002c70ffScarlsonj * We've been enabled here because of a backenable on 1799002c70ffScarlsonj * output flow control. Backenable clients using this 1800002c70ffScarlsonj * lower layer. 1801002c70ffScarlsonj */ 1802002c70ffScarlsonj vmem_walk(tcl_minor_arena, VMEM_ALLOC, tclvm_backenable, 1803002c70ffScarlsonj tll); 18047c478bd9Sstevel@tonic-gate } 18057c478bd9Sstevel@tonic-gate return (0); 18067c478bd9Sstevel@tonic-gate } 18077c478bd9Sstevel@tonic-gate 18087c478bd9Sstevel@tonic-gate while ((mp = getq(q)) != NULL) { 18097c478bd9Sstevel@tonic-gate if ((nextq = sppptun_outpkt(q, &mp)) != NULL) { 18107c478bd9Sstevel@tonic-gate putnext(nextq, mp); 18117c478bd9Sstevel@tonic-gate } else if (mp != NULL) { 18127c478bd9Sstevel@tonic-gate (void) putbq(q, mp); 18137c478bd9Sstevel@tonic-gate break; 18147c478bd9Sstevel@tonic-gate } 18157c478bd9Sstevel@tonic-gate } 18167c478bd9Sstevel@tonic-gate return (0); 18177c478bd9Sstevel@tonic-gate } 18187c478bd9Sstevel@tonic-gate 18197c478bd9Sstevel@tonic-gate /* 18207c478bd9Sstevel@tonic-gate * sppptun_lwput() 18217c478bd9Sstevel@tonic-gate * 18227c478bd9Sstevel@tonic-gate * MT-Perimeters: 18237c478bd9Sstevel@tonic-gate * shared inner, shared outer. 18247c478bd9Sstevel@tonic-gate * 18257c478bd9Sstevel@tonic-gate * Description: 18267c478bd9Sstevel@tonic-gate * Lower write-side put procedure. Nothing should be sending 18277c478bd9Sstevel@tonic-gate * packets down this stream. 18287c478bd9Sstevel@tonic-gate */ 18297c478bd9Sstevel@tonic-gate static void 18307c478bd9Sstevel@tonic-gate sppptun_lwput(queue_t *q, mblk_t *mp) 18317c478bd9Sstevel@tonic-gate { 18327c478bd9Sstevel@tonic-gate switch (MTYPE(mp)) { 18337c478bd9Sstevel@tonic-gate case M_PROTO: 18347c478bd9Sstevel@tonic-gate putnext(q, mp); 18357c478bd9Sstevel@tonic-gate break; 18367c478bd9Sstevel@tonic-gate default: 18377c478bd9Sstevel@tonic-gate freemsg(mp); 18387c478bd9Sstevel@tonic-gate break; 18397c478bd9Sstevel@tonic-gate } 18407c478bd9Sstevel@tonic-gate } 18417c478bd9Sstevel@tonic-gate 18427c478bd9Sstevel@tonic-gate /* 18437c478bd9Sstevel@tonic-gate * sppptun_lrput() 18447c478bd9Sstevel@tonic-gate * 18457c478bd9Sstevel@tonic-gate * MT-Perimeters: 18467c478bd9Sstevel@tonic-gate * shared inner, shared outer. 18477c478bd9Sstevel@tonic-gate * 18487c478bd9Sstevel@tonic-gate * Description: 18497c478bd9Sstevel@tonic-gate * Lower read-side put procedure. Nothing should arrive here. 18507c478bd9Sstevel@tonic-gate */ 18517c478bd9Sstevel@tonic-gate static void 18527c478bd9Sstevel@tonic-gate sppptun_lrput(queue_t *q, mblk_t *mp) 18537c478bd9Sstevel@tonic-gate { 18547c478bd9Sstevel@tonic-gate tuncl_t *tcl; 18557c478bd9Sstevel@tonic-gate 18567c478bd9Sstevel@tonic-gate switch (MTYPE(mp)) { 18577c478bd9Sstevel@tonic-gate case M_IOCTL: 18587c478bd9Sstevel@tonic-gate miocnak(q, mp, 0, EINVAL); 18597c478bd9Sstevel@tonic-gate return; 18607c478bd9Sstevel@tonic-gate case M_FLUSH: 18617c478bd9Sstevel@tonic-gate if (*mp->b_rptr & FLUSHR) { 18627c478bd9Sstevel@tonic-gate flushq(q, FLUSHDATA); 18637c478bd9Sstevel@tonic-gate } 18647c478bd9Sstevel@tonic-gate if (*mp->b_rptr & FLUSHW) { 18657c478bd9Sstevel@tonic-gate *mp->b_rptr &= ~FLUSHR; 18667c478bd9Sstevel@tonic-gate qreply(q, mp); 18677c478bd9Sstevel@tonic-gate } else { 18687c478bd9Sstevel@tonic-gate freemsg(mp); 18697c478bd9Sstevel@tonic-gate } 18707c478bd9Sstevel@tonic-gate return; 18717c478bd9Sstevel@tonic-gate } 18727c478bd9Sstevel@tonic-gate /* 18737c478bd9Sstevel@tonic-gate * Try to forward the message to the put procedure for the upper 18747c478bd9Sstevel@tonic-gate * control stream for this lower stream. If there are already messages 18757c478bd9Sstevel@tonic-gate * queued here, queue this one up to preserve message ordering. 18767c478bd9Sstevel@tonic-gate */ 18777c478bd9Sstevel@tonic-gate if ((tcl = (tuncl_t *)q->q_ptr) == NULL || tcl->tcl_rq == NULL) { 18787c478bd9Sstevel@tonic-gate freemsg(mp); 18797c478bd9Sstevel@tonic-gate return; 18807c478bd9Sstevel@tonic-gate } 18817c478bd9Sstevel@tonic-gate if (queclass(mp) == QPCTL || 18827c478bd9Sstevel@tonic-gate (q->q_first == NULL && canput(tcl->tcl_rq))) { 18837c478bd9Sstevel@tonic-gate put(tcl->tcl_rq, mp); 18847c478bd9Sstevel@tonic-gate } else { 18857c478bd9Sstevel@tonic-gate if (!putq(q, mp)) 18867c478bd9Sstevel@tonic-gate freemsg(mp); 18877c478bd9Sstevel@tonic-gate } 18887c478bd9Sstevel@tonic-gate } 18897c478bd9Sstevel@tonic-gate 18907c478bd9Sstevel@tonic-gate /* 18917c478bd9Sstevel@tonic-gate * MT-Perimeters: 18927c478bd9Sstevel@tonic-gate * shared inner, shared outer. 18937c478bd9Sstevel@tonic-gate * 18947c478bd9Sstevel@tonic-gate * Handle non-data DLPI messages. Used with PPPoE, which runs over 18957c478bd9Sstevel@tonic-gate * Ethernet only. 18967c478bd9Sstevel@tonic-gate */ 18977c478bd9Sstevel@tonic-gate static void 18987c478bd9Sstevel@tonic-gate urput_dlpi(queue_t *q, mblk_t *mp) 18997c478bd9Sstevel@tonic-gate { 19007c478bd9Sstevel@tonic-gate int err; 19017c478bd9Sstevel@tonic-gate union DL_primitives *dlp = (union DL_primitives *)mp->b_rptr; 1902002c70ffScarlsonj tunll_t *tll = q->q_ptr; 1903002c70ffScarlsonj size_t mlen = MBLKL(mp); 19047c478bd9Sstevel@tonic-gate 19057c478bd9Sstevel@tonic-gate switch (dlp->dl_primitive) { 19067c478bd9Sstevel@tonic-gate case DL_UDERROR_IND: 19077c478bd9Sstevel@tonic-gate break; 19087c478bd9Sstevel@tonic-gate 19097c478bd9Sstevel@tonic-gate case DL_ERROR_ACK: 1910002c70ffScarlsonj if (mlen < DL_ERROR_ACK_SIZE) 1911002c70ffScarlsonj break; 19127c478bd9Sstevel@tonic-gate err = dlp->error_ack.dl_unix_errno ? 19137c478bd9Sstevel@tonic-gate dlp->error_ack.dl_unix_errno : ENXIO; 19147c478bd9Sstevel@tonic-gate switch (dlp->error_ack.dl_error_primitive) { 19157c478bd9Sstevel@tonic-gate case DL_UNBIND_REQ: 19167c478bd9Sstevel@tonic-gate message_done(tll); 19177c478bd9Sstevel@tonic-gate break; 19187c478bd9Sstevel@tonic-gate case DL_DETACH_REQ: 19197c478bd9Sstevel@tonic-gate message_done(tll); 19207c478bd9Sstevel@tonic-gate tll->tll_error = err; 19217c478bd9Sstevel@tonic-gate tll->tll_flags |= TLLF_SHUTDOWN_DONE; 19227c478bd9Sstevel@tonic-gate break; 19237c478bd9Sstevel@tonic-gate case DL_PHYS_ADDR_REQ: 19247c478bd9Sstevel@tonic-gate message_done(tll); 19257c478bd9Sstevel@tonic-gate break; 19267c478bd9Sstevel@tonic-gate case DL_INFO_REQ: 19277c478bd9Sstevel@tonic-gate case DL_ATTACH_REQ: 19287c478bd9Sstevel@tonic-gate case DL_BIND_REQ: 19297c478bd9Sstevel@tonic-gate message_done(tll); 19307c478bd9Sstevel@tonic-gate tll->tll_error = err; 19317c478bd9Sstevel@tonic-gate break; 19327c478bd9Sstevel@tonic-gate } 19337c478bd9Sstevel@tonic-gate break; 19347c478bd9Sstevel@tonic-gate 19357c478bd9Sstevel@tonic-gate case DL_INFO_ACK: 19367c478bd9Sstevel@tonic-gate message_done(tll); 19377c478bd9Sstevel@tonic-gate break; 19387c478bd9Sstevel@tonic-gate 19397c478bd9Sstevel@tonic-gate case DL_BIND_ACK: 19407c478bd9Sstevel@tonic-gate message_done(tll); 19417c478bd9Sstevel@tonic-gate break; 19427c478bd9Sstevel@tonic-gate 19437c478bd9Sstevel@tonic-gate case DL_PHYS_ADDR_ACK: 19447c478bd9Sstevel@tonic-gate break; 19457c478bd9Sstevel@tonic-gate 19467c478bd9Sstevel@tonic-gate case DL_OK_ACK: 1947002c70ffScarlsonj if (mlen < DL_OK_ACK_SIZE) 1948002c70ffScarlsonj break; 19497c478bd9Sstevel@tonic-gate switch (dlp->ok_ack.dl_correct_primitive) { 19507c478bd9Sstevel@tonic-gate case DL_UNBIND_REQ: 19517c478bd9Sstevel@tonic-gate message_done(tll); 19527c478bd9Sstevel@tonic-gate break; 19537c478bd9Sstevel@tonic-gate case DL_DETACH_REQ: 19547c478bd9Sstevel@tonic-gate tll->tll_flags |= TLLF_SHUTDOWN_DONE; 19557c478bd9Sstevel@tonic-gate break; 19567c478bd9Sstevel@tonic-gate case DL_ATTACH_REQ: 19577c478bd9Sstevel@tonic-gate message_done(tll); 19587c478bd9Sstevel@tonic-gate break; 19597c478bd9Sstevel@tonic-gate } 19607c478bd9Sstevel@tonic-gate break; 19617c478bd9Sstevel@tonic-gate } 19627c478bd9Sstevel@tonic-gate freemsg(mp); 19637c478bd9Sstevel@tonic-gate } 19647c478bd9Sstevel@tonic-gate 19657c478bd9Sstevel@tonic-gate /* Search structure used with PPPoE only; see tclvm_pppoe_search(). */ 19667c478bd9Sstevel@tonic-gate struct poedat { 19677c478bd9Sstevel@tonic-gate uint_t sessid; 19687c478bd9Sstevel@tonic-gate tunll_t *tll; 1969002c70ffScarlsonj const void *srcaddr; 19707c478bd9Sstevel@tonic-gate int isdata; 19717c478bd9Sstevel@tonic-gate tuncl_t *tcl; 19727c478bd9Sstevel@tonic-gate }; 19737c478bd9Sstevel@tonic-gate 19747c478bd9Sstevel@tonic-gate /* 19757c478bd9Sstevel@tonic-gate * This function is called by vmem_walk from within sppptun_recv. It 19767c478bd9Sstevel@tonic-gate * iterates over a span of allocated minor node numbers to search for 19777c478bd9Sstevel@tonic-gate * the appropriate lower stream, session ID, and peer MAC address. 19787c478bd9Sstevel@tonic-gate * 19797c478bd9Sstevel@tonic-gate * (This is necessary due to a design flaw in the PPPoE protocol 19807c478bd9Sstevel@tonic-gate * itself. The protocol assigns session IDs from the server side 19817c478bd9Sstevel@tonic-gate * only. Both server and client use the same number. Thus, if there 19827c478bd9Sstevel@tonic-gate * are multiple clients on a single host, there can be session ID 19837c478bd9Sstevel@tonic-gate * conflicts between servers and there's no way to detangle them 19847c478bd9Sstevel@tonic-gate * except by looking at the remote MAC address.) 19857c478bd9Sstevel@tonic-gate * 19867c478bd9Sstevel@tonic-gate * (This could have been handled by linking together sessions that 19877c478bd9Sstevel@tonic-gate * differ only in the remote MAC address. This isn't done because it 19887c478bd9Sstevel@tonic-gate * would involve extra per-session storage and it's very unlikely that 19897c478bd9Sstevel@tonic-gate * PPPoE would be used this way.) 19907c478bd9Sstevel@tonic-gate */ 19917c478bd9Sstevel@tonic-gate static void 19927c478bd9Sstevel@tonic-gate tclvm_pppoe_search(void *arg, void *firstv, size_t numv) 19937c478bd9Sstevel@tonic-gate { 19947c478bd9Sstevel@tonic-gate struct poedat *poedat = (struct poedat *)arg; 19957c478bd9Sstevel@tonic-gate int minorn = (int)(uintptr_t)firstv; 19967c478bd9Sstevel@tonic-gate int minormax = minorn + numv; 19977c478bd9Sstevel@tonic-gate tuncl_t *tcl; 19987c478bd9Sstevel@tonic-gate 19997c478bd9Sstevel@tonic-gate if (poedat->tcl != NULL) 20007c478bd9Sstevel@tonic-gate return; 20017c478bd9Sstevel@tonic-gate while (minorn < minormax) { 20027c478bd9Sstevel@tonic-gate tcl = tcl_slots[minorn - 1]; 20037c478bd9Sstevel@tonic-gate ASSERT(tcl != NULL); 20047c478bd9Sstevel@tonic-gate if (tcl->tcl_rsessid == poedat->sessid && 20057c478bd9Sstevel@tonic-gate ((!poedat->isdata && tcl->tcl_ctrl_tll == poedat->tll) || 2006002c70ffScarlsonj (poedat->isdata && tcl->tcl_data_tll == poedat->tll)) && 20077c478bd9Sstevel@tonic-gate bcmp(tcl->tcl_address.pta_pppoe.ptma_mac, 20087c478bd9Sstevel@tonic-gate poedat->srcaddr, 20097c478bd9Sstevel@tonic-gate sizeof (tcl->tcl_address.pta_pppoe.ptma_mac)) == 0) { 20107c478bd9Sstevel@tonic-gate poedat->tcl = tcl; 20117c478bd9Sstevel@tonic-gate break; 20127c478bd9Sstevel@tonic-gate } 20137c478bd9Sstevel@tonic-gate minorn++; 20147c478bd9Sstevel@tonic-gate } 20157c478bd9Sstevel@tonic-gate } 20167c478bd9Sstevel@tonic-gate 20177c478bd9Sstevel@tonic-gate /* 20187c478bd9Sstevel@tonic-gate * sppptun_recv() 20197c478bd9Sstevel@tonic-gate * 20207c478bd9Sstevel@tonic-gate * MT-Perimeters: 20217c478bd9Sstevel@tonic-gate * shared inner, shared outer. 20227c478bd9Sstevel@tonic-gate * 20237c478bd9Sstevel@tonic-gate * Description: 20247c478bd9Sstevel@tonic-gate * Receive function called by sppptun_urput, which is called when 20257c478bd9Sstevel@tonic-gate * the lower read-side put or service procedure sends a message 20267c478bd9Sstevel@tonic-gate * upstream to the a device user (PPP). It attempts to find an 20277c478bd9Sstevel@tonic-gate * appropriate queue on the module above us (depending on what the 20287c478bd9Sstevel@tonic-gate * associated upper stream for the protocol would be), and if not 20297c478bd9Sstevel@tonic-gate * possible, it will find an upper control stream for the protocol. 20307c478bd9Sstevel@tonic-gate * Returns a pointer to the upper queue_t, or NULL if the message 20317c478bd9Sstevel@tonic-gate * has been discarded. 20327c478bd9Sstevel@tonic-gate * 20337c478bd9Sstevel@tonic-gate * About demultiplexing: 20347c478bd9Sstevel@tonic-gate * 20357c478bd9Sstevel@tonic-gate * All four protocols (L2F, PPTP, L2TP, and PPPoE) support a 20367c478bd9Sstevel@tonic-gate * locally assigned ID for demultiplexing incoming traffic. For 20377c478bd9Sstevel@tonic-gate * L2F, this is called the Client ID, for PPTP the Call ID, for 20387c478bd9Sstevel@tonic-gate * L2TP the Session ID, and for PPPoE the SESSION_ID. This is a 20397c478bd9Sstevel@tonic-gate * 16 bit number for all four protocols, and is used to directly 20407c478bd9Sstevel@tonic-gate * index into a list of upper streams. With the upper stream in 20417c478bd9Sstevel@tonic-gate * hand, we verify that this is the right stream and deliver the 20427c478bd9Sstevel@tonic-gate * data. 20437c478bd9Sstevel@tonic-gate * 20447c478bd9Sstevel@tonic-gate * L2TP has a Tunnel ID, which represents a bundle of PPP 20457c478bd9Sstevel@tonic-gate * sessions between the peers. Because we always assign unique 20467c478bd9Sstevel@tonic-gate * session ID numbers, we merely check that the given ID matches 20477c478bd9Sstevel@tonic-gate * the assigned ID for the upper stream. 20487c478bd9Sstevel@tonic-gate * 20497c478bd9Sstevel@tonic-gate * L2F has a Multiplex ID, which is unique per connection. It 20507c478bd9Sstevel@tonic-gate * does not have L2TP's concept of multiple-connections-within- 20517c478bd9Sstevel@tonic-gate * a-tunnel. The same checking is done. 20527c478bd9Sstevel@tonic-gate * 20537c478bd9Sstevel@tonic-gate * PPPoE is a horribly broken protocol. Only one ID is assigned 20547c478bd9Sstevel@tonic-gate * per connection. The client must somehow demultiplex based on 20557c478bd9Sstevel@tonic-gate * an ID number assigned by the server. It's not necessarily 20567c478bd9Sstevel@tonic-gate * unique. The search is done based on {ID,peerEthernet} (using 20577c478bd9Sstevel@tonic-gate * tcl_rsessid) for all packet types except PADI and PADS. 20587c478bd9Sstevel@tonic-gate * 20597c478bd9Sstevel@tonic-gate * Neither PPPoE nor PPTP supports additional ID numbers. 20607c478bd9Sstevel@tonic-gate * 20617c478bd9Sstevel@tonic-gate * Both L2F and L2TP come in over UDP. They are distinguished by 20627c478bd9Sstevel@tonic-gate * looking at the GRE version field -- 001 for L2F and 010 for 20637c478bd9Sstevel@tonic-gate * L2TP. 20647c478bd9Sstevel@tonic-gate */ 20657c478bd9Sstevel@tonic-gate static queue_t * 2066002c70ffScarlsonj sppptun_recv(queue_t *q, mblk_t **mpp, const void *srcaddr) 20677c478bd9Sstevel@tonic-gate { 20687c478bd9Sstevel@tonic-gate mblk_t *mp; 20697c478bd9Sstevel@tonic-gate tunll_t *tll; 20707c478bd9Sstevel@tonic-gate tuncl_t *tcl; 20717c478bd9Sstevel@tonic-gate int sessid; 20727c478bd9Sstevel@tonic-gate int remlen; 20737c478bd9Sstevel@tonic-gate int msglen; 20747c478bd9Sstevel@tonic-gate int isdata; 20757c478bd9Sstevel@tonic-gate int i; 2076002c70ffScarlsonj const uchar_t *ucp; 2077002c70ffScarlsonj const poep_t *poep; 20787c478bd9Sstevel@tonic-gate mblk_t *mnew; 20797c478bd9Sstevel@tonic-gate ppptun_atype *pap; 20807c478bd9Sstevel@tonic-gate 20817c478bd9Sstevel@tonic-gate mp = *mpp; 20827c478bd9Sstevel@tonic-gate 2083002c70ffScarlsonj tll = q->q_ptr; 20847c478bd9Sstevel@tonic-gate ASSERT(!(tll->tll_flags & TLLF_NOTLOWER)); 20857c478bd9Sstevel@tonic-gate 2086002c70ffScarlsonj tcl = NULL; 2087002c70ffScarlsonj switch (tll->tll_style) { 2088002c70ffScarlsonj case PTS_PPPOE: 2089002c70ffScarlsonj /* Note that poep_t alignment is uint16_t */ 2090002c70ffScarlsonj if ((!IS_P2ALIGNED(mp->b_rptr, sizeof (uint16_t)) || 2091002c70ffScarlsonj MBLKL(mp) < sizeof (poep_t)) && 2092002c70ffScarlsonj !pullupmsg(mp, sizeof (poep_t))) 2093002c70ffScarlsonj break; 2094002c70ffScarlsonj poep = (const poep_t *)mp->b_rptr; 2095002c70ffScarlsonj if (poep->poep_version_type != POE_VERSION) 2096002c70ffScarlsonj break; 20977c478bd9Sstevel@tonic-gate /* 20987c478bd9Sstevel@tonic-gate * First, extract a session ID number. All protocols have 20997c478bd9Sstevel@tonic-gate * this. 21007c478bd9Sstevel@tonic-gate */ 21017c478bd9Sstevel@tonic-gate isdata = (poep->poep_code == POECODE_DATA); 21027c478bd9Sstevel@tonic-gate sessid = ntohs(poep->poep_session_id); 21037c478bd9Sstevel@tonic-gate remlen = sizeof (*poep); 21047c478bd9Sstevel@tonic-gate msglen = ntohs(poep->poep_length); 21057c478bd9Sstevel@tonic-gate i = poep->poep_code; 21067c478bd9Sstevel@tonic-gate if (i == POECODE_PADI || i == POECODE_PADR) { 21077c478bd9Sstevel@tonic-gate /* These go to the server daemon only. */ 21087c478bd9Sstevel@tonic-gate tcl = tll->tll_defcl; 21097c478bd9Sstevel@tonic-gate } else if (i == POECODE_PADO || i == POECODE_PADS) { 21107c478bd9Sstevel@tonic-gate /* 21117c478bd9Sstevel@tonic-gate * These go to a client only, and are demuxed 21127c478bd9Sstevel@tonic-gate * by the Host-Uniq field (into which we stuff 21137c478bd9Sstevel@tonic-gate * our local ID number when generating 21147c478bd9Sstevel@tonic-gate * PADI/PADR). 21157c478bd9Sstevel@tonic-gate */ 2116002c70ffScarlsonj ucp = (const uchar_t *)(poep + 1); 21177c478bd9Sstevel@tonic-gate i = msglen; 21187c478bd9Sstevel@tonic-gate while (i > POET_HDRLEN) { 21197c478bd9Sstevel@tonic-gate if (POET_GET_TYPE(ucp) == POETT_END) { 21207c478bd9Sstevel@tonic-gate i = 0; 21217c478bd9Sstevel@tonic-gate break; 21227c478bd9Sstevel@tonic-gate } 21237c478bd9Sstevel@tonic-gate if (POET_GET_TYPE(ucp) == POETT_UNIQ && 21247c478bd9Sstevel@tonic-gate POET_GET_LENG(ucp) >= sizeof (uint32_t)) 21257c478bd9Sstevel@tonic-gate break; 21267c478bd9Sstevel@tonic-gate i -= POET_GET_LENG(ucp) + POET_HDRLEN; 21277c478bd9Sstevel@tonic-gate ucp = POET_NEXT(ucp); 21287c478bd9Sstevel@tonic-gate } 21297c478bd9Sstevel@tonic-gate if (i >= POET_HDRLEN + 4) 21307c478bd9Sstevel@tonic-gate sessid = GETLONG(ucp + POET_HDRLEN); 21317c478bd9Sstevel@tonic-gate tcl = tcl_by_minor((minor_t)sessid); 21327c478bd9Sstevel@tonic-gate } else { 21337c478bd9Sstevel@tonic-gate /* 21347c478bd9Sstevel@tonic-gate * Try minor number as session ID first, since 21357c478bd9Sstevel@tonic-gate * it's used that way on server side. It's 21367c478bd9Sstevel@tonic-gate * not used that way on the client, though, so 21377c478bd9Sstevel@tonic-gate * this might not work. If this isn't the 21387c478bd9Sstevel@tonic-gate * right one, then try the tll cache. If 21397c478bd9Sstevel@tonic-gate * neither is right, then search all open 21407c478bd9Sstevel@tonic-gate * clients. Did I mention that the PPPoE 21417c478bd9Sstevel@tonic-gate * protocol is badly designed? 21427c478bd9Sstevel@tonic-gate */ 21437c478bd9Sstevel@tonic-gate tcl = tcl_by_minor((minor_t)sessid); 21447c478bd9Sstevel@tonic-gate if (tcl == NULL || 21457c478bd9Sstevel@tonic-gate (!isdata && tcl->tcl_ctrl_tll != tll) || 21467c478bd9Sstevel@tonic-gate (isdata && tcl->tcl_data_tll != tll) || 21477c478bd9Sstevel@tonic-gate sessid != tcl->tcl_rsessid || 21487c478bd9Sstevel@tonic-gate bcmp(srcaddr, tcl->tcl_address.pta_pppoe.ptma_mac, 21497c478bd9Sstevel@tonic-gate sizeof (tcl->tcl_address.pta_pppoe.ptma_mac)) != 0) 21507c478bd9Sstevel@tonic-gate tcl = tll->tll_lastcl; 21517c478bd9Sstevel@tonic-gate if (tcl == NULL || 21527c478bd9Sstevel@tonic-gate (!isdata && tcl->tcl_ctrl_tll != tll) || 21537c478bd9Sstevel@tonic-gate (isdata && tcl->tcl_data_tll != tll) || 21547c478bd9Sstevel@tonic-gate sessid != tcl->tcl_rsessid || 21557c478bd9Sstevel@tonic-gate bcmp(srcaddr, tcl->tcl_address.pta_pppoe.ptma_mac, 21567c478bd9Sstevel@tonic-gate sizeof (tcl->tcl_address.pta_pppoe.ptma_mac)) != 0) 21577c478bd9Sstevel@tonic-gate tcl = NULL; 21587c478bd9Sstevel@tonic-gate if (tcl == NULL && sessid != 0) { 21597c478bd9Sstevel@tonic-gate struct poedat poedat; 21607c478bd9Sstevel@tonic-gate 21617c478bd9Sstevel@tonic-gate /* 21627c478bd9Sstevel@tonic-gate * Slow mode. Too bad. If you don't like it, 21637c478bd9Sstevel@tonic-gate * you can always choose a better protocol. 21647c478bd9Sstevel@tonic-gate */ 21657c478bd9Sstevel@tonic-gate poedat.sessid = sessid; 21667c478bd9Sstevel@tonic-gate poedat.tll = tll; 21677c478bd9Sstevel@tonic-gate poedat.srcaddr = srcaddr; 21687c478bd9Sstevel@tonic-gate poedat.tcl = NULL; 21697c478bd9Sstevel@tonic-gate poedat.isdata = isdata; 21707c478bd9Sstevel@tonic-gate vmem_walk(tcl_minor_arena, VMEM_ALLOC, 21717c478bd9Sstevel@tonic-gate tclvm_pppoe_search, &poedat); 21727c478bd9Sstevel@tonic-gate KLINCR(lks_walks); 21737c478bd9Sstevel@tonic-gate if ((tcl = poedat.tcl) != NULL) { 21747c478bd9Sstevel@tonic-gate tll->tll_lastcl = tcl; 21757c478bd9Sstevel@tonic-gate KCINCR(cks_walks); 21767c478bd9Sstevel@tonic-gate } 21777c478bd9Sstevel@tonic-gate } 21787c478bd9Sstevel@tonic-gate } 21797c478bd9Sstevel@tonic-gate break; 21807c478bd9Sstevel@tonic-gate } 21817c478bd9Sstevel@tonic-gate 21827c478bd9Sstevel@tonic-gate if (tcl == NULL || tcl->tcl_rq == NULL) { 2183002c70ffScarlsonj DTRACE_PROBE3(sppptun__recv__discard, int, sessid, 2184002c70ffScarlsonj tuncl_t *, tcl, mblk_t *, mp); 21857c478bd9Sstevel@tonic-gate if (tcl == NULL) { 21867c478bd9Sstevel@tonic-gate KLINCR(lks_in_nomatch); 21877c478bd9Sstevel@tonic-gate } 21887c478bd9Sstevel@tonic-gate if (isdata) { 21897c478bd9Sstevel@tonic-gate KLINCR(lks_indata_drops); 21907c478bd9Sstevel@tonic-gate if (tcl != NULL) 21917c478bd9Sstevel@tonic-gate tcl->tcl_stats.ppp_ierrors++; 21927c478bd9Sstevel@tonic-gate } else { 21937c478bd9Sstevel@tonic-gate KLINCR(lks_inctrl_drops); 21947c478bd9Sstevel@tonic-gate if (tcl != NULL) { 21957c478bd9Sstevel@tonic-gate KCINCR(cks_inctrl_drops); 21967c478bd9Sstevel@tonic-gate } 21977c478bd9Sstevel@tonic-gate } 21987c478bd9Sstevel@tonic-gate freemsg(mp); 21997c478bd9Sstevel@tonic-gate return (NULL); 22007c478bd9Sstevel@tonic-gate } 22017c478bd9Sstevel@tonic-gate 22027c478bd9Sstevel@tonic-gate if (tcl->tcl_data_tll == tll && isdata) { 22037c478bd9Sstevel@tonic-gate if (!adjmsg(mp, remlen) || 22047c478bd9Sstevel@tonic-gate (i = msgsize(mp)) < msglen || 22057c478bd9Sstevel@tonic-gate (i > msglen && !adjmsg(mp, msglen - i))) { 22067c478bd9Sstevel@tonic-gate KLINCR(lks_indata_drops); 22077c478bd9Sstevel@tonic-gate tcl->tcl_stats.ppp_ierrors++; 22087c478bd9Sstevel@tonic-gate freemsg(mp); 22097c478bd9Sstevel@tonic-gate return (NULL); 22107c478bd9Sstevel@tonic-gate } 22117c478bd9Sstevel@tonic-gate /* XXX -- address/control handling in pppd needs help. */ 22127c478bd9Sstevel@tonic-gate if (*mp->b_rptr != 0xFF) { 22137c478bd9Sstevel@tonic-gate if ((mp = prependb(mp, 2, 1)) == NULL) { 22147c478bd9Sstevel@tonic-gate KLINCR(lks_indata_drops); 22157c478bd9Sstevel@tonic-gate tcl->tcl_stats.ppp_ierrors++; 22167c478bd9Sstevel@tonic-gate return (NULL); 22177c478bd9Sstevel@tonic-gate } 22187c478bd9Sstevel@tonic-gate mp->b_rptr[0] = 0xFF; 22197c478bd9Sstevel@tonic-gate mp->b_rptr[1] = 0x03; 22207c478bd9Sstevel@tonic-gate } 22217c478bd9Sstevel@tonic-gate MTYPE(mp) = M_DATA; 22227c478bd9Sstevel@tonic-gate tcl->tcl_stats.ppp_ibytes += msgsize(mp); 22237c478bd9Sstevel@tonic-gate tcl->tcl_stats.ppp_ipackets++; 22247c478bd9Sstevel@tonic-gate KLINCR(lks_indata); 22257c478bd9Sstevel@tonic-gate } else { 22267c478bd9Sstevel@tonic-gate if (isdata || tcl->tcl_ctrl_tll != tll || 22277c478bd9Sstevel@tonic-gate (mnew = make_control(tcl, tll, PTCA_CONTROL, tcl)) == 22287c478bd9Sstevel@tonic-gate NULL) { 22297c478bd9Sstevel@tonic-gate KLINCR(lks_inctrl_drops); 22307c478bd9Sstevel@tonic-gate KCINCR(cks_inctrl_drops); 22317c478bd9Sstevel@tonic-gate freemsg(mp); 22327c478bd9Sstevel@tonic-gate return (NULL); 22337c478bd9Sstevel@tonic-gate } 22347c478bd9Sstevel@tonic-gate /* Fix up source address; peer might not be set yet. */ 22357c478bd9Sstevel@tonic-gate pap = &((struct ppptun_control *)mnew->b_rptr)->ptc_address; 22367c478bd9Sstevel@tonic-gate bcopy(srcaddr, pap->pta_pppoe.ptma_mac, 22377c478bd9Sstevel@tonic-gate sizeof (pap->pta_pppoe.ptma_mac)); 22387c478bd9Sstevel@tonic-gate mnew->b_cont = mp; 22397c478bd9Sstevel@tonic-gate mp = mnew; 22407c478bd9Sstevel@tonic-gate KLINCR(lks_inctrls); 22417c478bd9Sstevel@tonic-gate KCINCR(cks_inctrls); 22427c478bd9Sstevel@tonic-gate } 22437c478bd9Sstevel@tonic-gate *mpp = mp; 22447c478bd9Sstevel@tonic-gate return (tcl->tcl_rq); 22457c478bd9Sstevel@tonic-gate } 22467c478bd9Sstevel@tonic-gate 22477c478bd9Sstevel@tonic-gate /* 22487c478bd9Sstevel@tonic-gate * sppptun_urput() 22497c478bd9Sstevel@tonic-gate * 22507c478bd9Sstevel@tonic-gate * MT-Perimeters: 22517c478bd9Sstevel@tonic-gate * shared inner, shared outer. 22527c478bd9Sstevel@tonic-gate * 22537c478bd9Sstevel@tonic-gate * Description: 22547c478bd9Sstevel@tonic-gate * Upper read-side put procedure. Messages from the underlying 22557c478bd9Sstevel@tonic-gate * lower stream driver arrive here. See sppptun_recv for the 22567c478bd9Sstevel@tonic-gate * demultiplexing logic. 22577c478bd9Sstevel@tonic-gate */ 22587c478bd9Sstevel@tonic-gate static void 22597c478bd9Sstevel@tonic-gate sppptun_urput(queue_t *q, mblk_t *mp) 22607c478bd9Sstevel@tonic-gate { 22617c478bd9Sstevel@tonic-gate union DL_primitives *dlprim; 22627c478bd9Sstevel@tonic-gate mblk_t *mpnext; 22637c478bd9Sstevel@tonic-gate tunll_t *tll; 22647c478bd9Sstevel@tonic-gate queue_t *nextq; 22657c478bd9Sstevel@tonic-gate 2266002c70ffScarlsonj tll = q->q_ptr; 22677c478bd9Sstevel@tonic-gate ASSERT(!(tll->tll_flags & TLLF_NOTLOWER)); 22687c478bd9Sstevel@tonic-gate 22697c478bd9Sstevel@tonic-gate switch (MTYPE(mp)) { 22707c478bd9Sstevel@tonic-gate case M_DATA: 22717c478bd9Sstevel@tonic-gate /* 22727c478bd9Sstevel@tonic-gate * When we're bound over IP, data arrives here. The 22737c478bd9Sstevel@tonic-gate * packet starts with the IP header itself. 22747c478bd9Sstevel@tonic-gate */ 2275002c70ffScarlsonj if ((nextq = sppptun_recv(q, &mp, NULL)) != NULL) 22767c478bd9Sstevel@tonic-gate putnext(nextq, mp); 22777c478bd9Sstevel@tonic-gate break; 22787c478bd9Sstevel@tonic-gate 22797c478bd9Sstevel@tonic-gate case M_PROTO: 22807c478bd9Sstevel@tonic-gate case M_PCPROTO: 22817c478bd9Sstevel@tonic-gate /* Data arrives here for UDP or raw Ethernet, not IP. */ 22827c478bd9Sstevel@tonic-gate switch (tll->tll_style) { 22837c478bd9Sstevel@tonic-gate /* PPTP control messages are over TCP only. */ 22847c478bd9Sstevel@tonic-gate case PTS_PPTP: 22857c478bd9Sstevel@tonic-gate default: 22867c478bd9Sstevel@tonic-gate ASSERT(0); /* how'd that happen? */ 22877c478bd9Sstevel@tonic-gate break; 22887c478bd9Sstevel@tonic-gate 22897c478bd9Sstevel@tonic-gate case PTS_PPPOE: /* DLPI message */ 2290002c70ffScarlsonj if (MBLKL(mp) < sizeof (t_uscalar_t)) 2291002c70ffScarlsonj break; 22927c478bd9Sstevel@tonic-gate dlprim = (union DL_primitives *)mp->b_rptr; 22937c478bd9Sstevel@tonic-gate switch (dlprim->dl_primitive) { 2294002c70ffScarlsonj case DL_UNITDATA_IND: { 2295002c70ffScarlsonj size_t mlen = MBLKL(mp); 22967c478bd9Sstevel@tonic-gate 2297002c70ffScarlsonj if (mlen < DL_UNITDATA_IND_SIZE) 2298002c70ffScarlsonj break; 2299002c70ffScarlsonj if (dlprim->unitdata_ind.dl_src_addr_offset < 2300002c70ffScarlsonj DL_UNITDATA_IND_SIZE || 2301002c70ffScarlsonj dlprim->unitdata_ind.dl_src_addr_offset + 2302002c70ffScarlsonj dlprim->unitdata_ind.dl_src_addr_length > 2303002c70ffScarlsonj mlen) 2304002c70ffScarlsonj break; 2305002c70ffScarlsonj } 2306002c70ffScarlsonj /* FALLTHROUGH */ 2307002c70ffScarlsonj case DL_UNITDATA_REQ: /* For loopback support. */ 2308002c70ffScarlsonj if (dlprim->dl_primitive == DL_UNITDATA_REQ && 2309002c70ffScarlsonj MBLKL(mp) < DL_UNITDATA_REQ_SIZE) 2310002c70ffScarlsonj break; 2311002c70ffScarlsonj if ((mpnext = mp->b_cont) == NULL) 2312002c70ffScarlsonj break; 23137c478bd9Sstevel@tonic-gate MTYPE(mpnext) = M_DATA; 23147c478bd9Sstevel@tonic-gate nextq = sppptun_recv(q, &mpnext, 2315002c70ffScarlsonj dlprim->dl_primitive == DL_UNITDATA_IND ? 23167c478bd9Sstevel@tonic-gate mp->b_rptr + 2317002c70ffScarlsonj dlprim->unitdata_ind.dl_src_addr_offset : 23187c478bd9Sstevel@tonic-gate tll->tll_lcladdr.pta_pppoe.ptma_mac); 23197c478bd9Sstevel@tonic-gate if (nextq != NULL) 23207c478bd9Sstevel@tonic-gate putnext(nextq, mpnext); 23217c478bd9Sstevel@tonic-gate freeb(mp); 2322002c70ffScarlsonj return; 23237c478bd9Sstevel@tonic-gate 23247c478bd9Sstevel@tonic-gate default: 23257c478bd9Sstevel@tonic-gate urput_dlpi(q, mp); 2326002c70ffScarlsonj return; 23277c478bd9Sstevel@tonic-gate } 23287c478bd9Sstevel@tonic-gate break; 23297c478bd9Sstevel@tonic-gate } 2330002c70ffScarlsonj freemsg(mp); 23317c478bd9Sstevel@tonic-gate break; 23327c478bd9Sstevel@tonic-gate 23337c478bd9Sstevel@tonic-gate default: 23347c478bd9Sstevel@tonic-gate freemsg(mp); 23357c478bd9Sstevel@tonic-gate break; 23367c478bd9Sstevel@tonic-gate } 23377c478bd9Sstevel@tonic-gate } 23387c478bd9Sstevel@tonic-gate 23397c478bd9Sstevel@tonic-gate /* 23407c478bd9Sstevel@tonic-gate * sppptun_ursrv() 23417c478bd9Sstevel@tonic-gate * 23427c478bd9Sstevel@tonic-gate * MT-Perimeters: 23437c478bd9Sstevel@tonic-gate * exclusive inner, shared outer. 23447c478bd9Sstevel@tonic-gate * 23457c478bd9Sstevel@tonic-gate * Description: 23467c478bd9Sstevel@tonic-gate * Upper read-side service procedure. This procedure services the 23477c478bd9Sstevel@tonic-gate * client streams. We get here because the client (PPP) asserts 23487c478bd9Sstevel@tonic-gate * flow control down to us. 23497c478bd9Sstevel@tonic-gate */ 23507c478bd9Sstevel@tonic-gate static int 23517c478bd9Sstevel@tonic-gate sppptun_ursrv(queue_t *q) 23527c478bd9Sstevel@tonic-gate { 23537c478bd9Sstevel@tonic-gate mblk_t *mp; 23547c478bd9Sstevel@tonic-gate 23557c478bd9Sstevel@tonic-gate ASSERT(q->q_ptr != NULL); 23567c478bd9Sstevel@tonic-gate 23577c478bd9Sstevel@tonic-gate while ((mp = getq(q)) != NULL) { 23587c478bd9Sstevel@tonic-gate if (canputnext(q)) { 23597c478bd9Sstevel@tonic-gate putnext(q, mp); 23607c478bd9Sstevel@tonic-gate } else { 23617c478bd9Sstevel@tonic-gate (void) putbq(q, mp); 23627c478bd9Sstevel@tonic-gate break; 23637c478bd9Sstevel@tonic-gate } 23647c478bd9Sstevel@tonic-gate } 23657c478bd9Sstevel@tonic-gate return (0); 23667c478bd9Sstevel@tonic-gate } 23677c478bd9Sstevel@tonic-gate 23687c478bd9Sstevel@tonic-gate /* 23697c478bd9Sstevel@tonic-gate * Dummy constructor/destructor functions for kmem_cache_create. 23707c478bd9Sstevel@tonic-gate * We're just using kmem as an allocator of integers, not real 23717c478bd9Sstevel@tonic-gate * storage. 23727c478bd9Sstevel@tonic-gate */ 23737c478bd9Sstevel@tonic-gate 23747c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 23757c478bd9Sstevel@tonic-gate static int 23767c478bd9Sstevel@tonic-gate tcl_constructor(void *maddr, void *arg, int kmflags) 23777c478bd9Sstevel@tonic-gate { 23787c478bd9Sstevel@tonic-gate return (0); 23797c478bd9Sstevel@tonic-gate } 23807c478bd9Sstevel@tonic-gate 23817c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 23827c478bd9Sstevel@tonic-gate static void 23837c478bd9Sstevel@tonic-gate tcl_destructor(void *maddr, void *arg) 23847c478bd9Sstevel@tonic-gate { 23857c478bd9Sstevel@tonic-gate } 23867c478bd9Sstevel@tonic-gate 23877c478bd9Sstevel@tonic-gate /* 23887c478bd9Sstevel@tonic-gate * Total size occupied by one tunnel client. Each tunnel client 23897c478bd9Sstevel@tonic-gate * consumes one pointer for tcl_slots array, one tuncl_t structure and 23907c478bd9Sstevel@tonic-gate * two messages preallocated for close. 23917c478bd9Sstevel@tonic-gate */ 23927c478bd9Sstevel@tonic-gate #define TUNCL_SIZE (sizeof (tuncl_t) + sizeof (tuncl_t *) + \ 23937c478bd9Sstevel@tonic-gate 2 * sizeof (dblk_t)) 23947c478bd9Sstevel@tonic-gate 23957c478bd9Sstevel@tonic-gate /* 23967c478bd9Sstevel@tonic-gate * Clear all bits of x except the highest bit 23977c478bd9Sstevel@tonic-gate */ 23987c478bd9Sstevel@tonic-gate #define truncate(x) ((x) <= 2 ? (x) : (1 << (highbit(x) - 1))) 23997c478bd9Sstevel@tonic-gate 24007c478bd9Sstevel@tonic-gate /* 24017c478bd9Sstevel@tonic-gate * This function initializes some well-known global variables inside 24027c478bd9Sstevel@tonic-gate * the module. 24037c478bd9Sstevel@tonic-gate * 24047c478bd9Sstevel@tonic-gate * Called by sppptun_mod.c:_init() before installing the module. 24057c478bd9Sstevel@tonic-gate */ 24067c478bd9Sstevel@tonic-gate void 24077c478bd9Sstevel@tonic-gate sppptun_init(void) 24087c478bd9Sstevel@tonic-gate { 24097c478bd9Sstevel@tonic-gate tunll_list.q_forw = tunll_list.q_back = &tunll_list; 24107c478bd9Sstevel@tonic-gate } 24117c478bd9Sstevel@tonic-gate 24127c478bd9Sstevel@tonic-gate /* 24137c478bd9Sstevel@tonic-gate * This function allocates the initial internal storage for the 24147c478bd9Sstevel@tonic-gate * sppptun driver. 24157c478bd9Sstevel@tonic-gate * 24167c478bd9Sstevel@tonic-gate * Called by sppptun_mod.c:_init() after installing module. 24177c478bd9Sstevel@tonic-gate */ 24187c478bd9Sstevel@tonic-gate void 24197c478bd9Sstevel@tonic-gate sppptun_tcl_init(void) 24207c478bd9Sstevel@tonic-gate { 24217c478bd9Sstevel@tonic-gate uint_t i, j; 24227c478bd9Sstevel@tonic-gate 24237c478bd9Sstevel@tonic-gate rw_init(&tcl_rwlock, NULL, RW_DRIVER, NULL); 24247c478bd9Sstevel@tonic-gate rw_enter(&tcl_rwlock, RW_WRITER); 24257c478bd9Sstevel@tonic-gate tcl_nslots = sppptun_init_cnt; 24267c478bd9Sstevel@tonic-gate tcl_slots = kmem_zalloc(tcl_nslots * sizeof (tuncl_t *), KM_SLEEP); 24277c478bd9Sstevel@tonic-gate 24287c478bd9Sstevel@tonic-gate tcl_cache = kmem_cache_create("sppptun_map", sizeof (tuncl_t), 0, 24297c478bd9Sstevel@tonic-gate tcl_constructor, tcl_destructor, NULL, NULL, NULL, 0); 24307c478bd9Sstevel@tonic-gate 24317c478bd9Sstevel@tonic-gate /* Allocate integer space for minor numbers */ 24327c478bd9Sstevel@tonic-gate tcl_minor_arena = vmem_create("sppptun_minor", (void *)1, tcl_nslots, 24337c478bd9Sstevel@tonic-gate 1, NULL, NULL, NULL, 0, VM_SLEEP | VMC_IDENTIFIER); 24347c478bd9Sstevel@tonic-gate 24357c478bd9Sstevel@tonic-gate /* 24367c478bd9Sstevel@tonic-gate * Calculate available number of tunnels - how many tunnels 24377c478bd9Sstevel@tonic-gate * can we allocate in sppptun_pctofmem % of available 24387c478bd9Sstevel@tonic-gate * memory. The value is rounded up to the nearest power of 2. 24397c478bd9Sstevel@tonic-gate */ 24407c478bd9Sstevel@tonic-gate i = (sppptun_pctofmem * kmem_maxavail()) / (100 * TUNCL_SIZE); 24417c478bd9Sstevel@tonic-gate j = truncate(i); /* i with non-high bits stripped */ 24427c478bd9Sstevel@tonic-gate if (i != j) 24437c478bd9Sstevel@tonic-gate j *= 2; 24447c478bd9Sstevel@tonic-gate tcl_minormax = j; 24457c478bd9Sstevel@tonic-gate rw_exit(&tcl_rwlock); 24467c478bd9Sstevel@tonic-gate } 24477c478bd9Sstevel@tonic-gate 24487c478bd9Sstevel@tonic-gate /* 24497c478bd9Sstevel@tonic-gate * This function checks that there are no plumbed streams or other users. 24507c478bd9Sstevel@tonic-gate * 24517c478bd9Sstevel@tonic-gate * Called by sppptun_mod.c:_fini(). Assumes that we're exclusive on 24527c478bd9Sstevel@tonic-gate * both perimeters. 24537c478bd9Sstevel@tonic-gate */ 24547c478bd9Sstevel@tonic-gate int 24557c478bd9Sstevel@tonic-gate sppptun_tcl_fintest(void) 24567c478bd9Sstevel@tonic-gate { 2457002c70ffScarlsonj if (tunll_list.q_forw != &tunll_list || tcl_inuse > 0) 24587c478bd9Sstevel@tonic-gate return (EBUSY); 2459002c70ffScarlsonj else 24607c478bd9Sstevel@tonic-gate return (0); 24617c478bd9Sstevel@tonic-gate } 24627c478bd9Sstevel@tonic-gate 24637c478bd9Sstevel@tonic-gate /* 24647c478bd9Sstevel@tonic-gate * If no lower streams are plumbed, then this function deallocates all 24657c478bd9Sstevel@tonic-gate * internal storage in preparation for unload. 24667c478bd9Sstevel@tonic-gate * 24677c478bd9Sstevel@tonic-gate * Called by sppptun_mod.c:_fini(). Assumes that we're exclusive on 24687c478bd9Sstevel@tonic-gate * both perimeters. 24697c478bd9Sstevel@tonic-gate */ 24707c478bd9Sstevel@tonic-gate void 24717c478bd9Sstevel@tonic-gate sppptun_tcl_fini(void) 24727c478bd9Sstevel@tonic-gate { 24737c478bd9Sstevel@tonic-gate if (tcl_minor_arena != NULL) { 24747c478bd9Sstevel@tonic-gate vmem_destroy(tcl_minor_arena); 24757c478bd9Sstevel@tonic-gate tcl_minor_arena = NULL; 24767c478bd9Sstevel@tonic-gate } 24777c478bd9Sstevel@tonic-gate if (tcl_cache != NULL) { 24787c478bd9Sstevel@tonic-gate kmem_cache_destroy(tcl_cache); 24797c478bd9Sstevel@tonic-gate tcl_cache = NULL; 24807c478bd9Sstevel@tonic-gate } 24817c478bd9Sstevel@tonic-gate kmem_free(tcl_slots, tcl_nslots * sizeof (tuncl_t *)); 24827c478bd9Sstevel@tonic-gate tcl_slots = NULL; 24837c478bd9Sstevel@tonic-gate rw_destroy(&tcl_rwlock); 24847c478bd9Sstevel@tonic-gate ASSERT(tcl_slots == NULL); 24857c478bd9Sstevel@tonic-gate ASSERT(tcl_cache == NULL); 24867c478bd9Sstevel@tonic-gate ASSERT(tcl_minor_arena == NULL); 24877c478bd9Sstevel@tonic-gate } 2488