1/* 2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24/* ----------------------------------------------------------------------------- 25 * 26 * History : 27 * 28 * Jun 2000 - add support for ppp generic interfaces 29 30 * Nov 1999 - Christophe Allie - created. 31 * basic support fo ppp family 32 * 33 * Theory of operation : 34 * 35 * this file creates is loaded as a Kernel Extension. 36 * it creates the necessary ppp components and plumbs everything together. 37 * 38----------------------------------------------------------------------------- */ 39 40 41/* ----------------------------------------------------------------------------- 42 Includes 43----------------------------------------------------------------------------- */ 44 45#include <sys/param.h> 46#include <sys/socket.h> 47#include <sys/syslog.h> 48#include <kern/thread.h> 49#include <sys/systm.h> 50#include <kern/locks.h> 51#include <net/if.h> 52#include <netinet/in.h> 53 54#include "ppp_defs.h" // public ppp values 55#include "if_ppp.h" // public ppp API 56#include "if_ppplink.h" // public link API 57 58#include "ppp_domain.h" 59#include "ppp_if.h" 60#include "ppp_link.h" 61#include "ppp_comp.h" 62#include "ppp_compress.h" 63 64#include "ppp_serial.h" 65#include "ppp_ip.h" 66#include "ppp_ipv6.h" 67 68 69/* ----------------------------------------------------------------------------- 70 Definitions 71----------------------------------------------------------------------------- */ 72 73 74/* ----------------------------------------------------------------------------- 75 Forward declarations 76----------------------------------------------------------------------------- */ 77 78 79/* ----------------------------------------------------------------------------- 80 PPP globals 81----------------------------------------------------------------------------- */ 82static int ppp_inited = 0; 83extern lck_mtx_t *ppp_domain_mutex; 84 85/* ----------------------------------------------------------------------------- 86 NKE entry point, start routine 87----------------------------------------------------------------------------- */ 88int ppp_module_start(struct kmod_info *ki, void *data) 89{ 90 int ret; 91 92 if (ppp_inited) 93 return KERN_SUCCESS; 94 95 /* add the ppp domain */ 96 ppp_domain_init(); 97 98 lck_mtx_lock(ppp_domain_mutex); 99 /* register the ppp network and ppp link module */ 100 ret = ppp_proto_add(); 101 lck_mtx_unlock(ppp_domain_mutex); 102 LOGRETURN(ret, ret, "pppserial_init: ppp_proto_add error = 0x%x\n"); 103 104 /* now init the if and link structures */ 105 ppp_if_init(); 106 ppp_link_init(); 107 ppp_comp_init(); 108 109 /* init ip protocol */ 110 ppp_ip_init(0); 111 ppp_ipv6_init(0); 112 113 /* add the ppp serial link support */ 114 ret = pppserial_init(); 115 LOGRETURN(ret, KERN_FAILURE, "pppserial_init: ppp_fam_init error = 0x%x\n"); 116 117 /* NKE is ready ! */ 118 ppp_inited = 1; 119 return KERN_SUCCESS; 120} 121 122/* ----------------------------------------------------------------------------- 123 NKE entry point, stop routine 124----------------------------------------------------------------------------- */ 125int ppp_module_stop(struct kmod_info *ki, void *data) 126{ 127 int ret; 128 129 if (!ppp_inited) 130 return(KERN_SUCCESS); 131 132 /* remove the ppp serial link support */ 133 ret = pppserial_dispose(); 134 LOGRETURN(ret, ret, "ppp_terminate: pppserial_dispose error = 0x%x\n"); 135 136 /* remove ip protocol */ 137 ret = ppp_ipv6_dispose(0); 138 LOGRETURN(ret, ret, "ppp_terminate: ppp_ipv6_dispose error = 0x%x\n"); 139 ret = ppp_ip_dispose(0); 140 LOGRETURN(ret, ret, "ppp_terminate: ppp_ip_dispose error = 0x%x\n"); 141 142 lck_mtx_lock(ppp_domain_mutex); 143 /* dispose the link and if layers */ 144 ret = ppp_if_dispose(); 145 LOGGOTOFAIL(ret, "ppp_terminate: ppp_if_dispose error = 0x%x\n"); 146 ret = ppp_link_dispose(); 147 LOGGOTOFAIL(ret, "ppp_terminate: ppp_link_dispose error = 0x%x\n"); 148 ret = ppp_comp_dispose(); 149 LOGGOTOFAIL(ret, "ppp_terminate: ppp_comp_dispose error = 0x%x\n"); 150 151 /* remove the pppdomain */ 152 ret = ppp_proto_remove(); 153 LOGGOTOFAIL(ret, "ppp_terminate: ppp_proto_remove error = 0x%x\n"); 154 155 lck_mtx_unlock(ppp_domain_mutex); 156 157 /* remove the pppdomain */ 158 ret = ppp_domain_dispose(); 159 LOGRETURN(ret, KERN_FAILURE, "ppp_terminate: ppp_domain_dispose error = 0x%x\n"); 160 161 return KERN_SUCCESS; 162fail: 163 lck_mtx_unlock(ppp_domain_mutex); 164 return KERN_FAILURE; 165} 166