003 File Manager
Current Path:
/usr/src/sys/netgraph
usr
/
src
/
sys
/
netgraph
/
📁
..
📄
NOTES
(3.63 KB)
📁
atm
📁
bluetooth
📁
netflow
📄
netgraph.h
(41.17 KB)
📄
ng_UI.c
(6.29 KB)
📄
ng_UI.h
(2.36 KB)
📄
ng_async.c
(16.51 KB)
📄
ng_async.h
(4.05 KB)
📄
ng_atmllc.c
(7.25 KB)
📄
ng_atmllc.h
(1.85 KB)
📄
ng_base.c
(100.62 KB)
📄
ng_bpf.c
(14.66 KB)
📄
ng_bpf.h
(3.97 KB)
📄
ng_bridge.c
(29.37 KB)
📄
ng_bridge.h
(7.58 KB)
📄
ng_car.c
(19.62 KB)
📄
ng_car.h
(4.6 KB)
📄
ng_checksum.c
(15.85 KB)
📄
ng_checksum.h
(2.63 KB)
📄
ng_cisco.c
(15.47 KB)
📄
ng_cisco.h
(3.39 KB)
📄
ng_deflate.c
(17.09 KB)
📄
ng_deflate.h
(2.85 KB)
📄
ng_device.c
(10.65 KB)
📄
ng_device.h
(1.74 KB)
📄
ng_echo.c
(3.52 KB)
📄
ng_echo.h
(2.28 KB)
📄
ng_eiface.c
(16.31 KB)
📄
ng_eiface.h
(2.09 KB)
📄
ng_etf.c
(12.84 KB)
📄
ng_etf.h
(3.05 KB)
📄
ng_ether.c
(22.26 KB)
📄
ng_ether.h
(3.22 KB)
📄
ng_ether_echo.c
(4.17 KB)
📄
ng_ether_echo.h
(2.32 KB)
📄
ng_frame_relay.c
(13.21 KB)
📄
ng_frame_relay.h
(2.51 KB)
📄
ng_gif.c
(15.86 KB)
📄
ng_gif.h
(4.04 KB)
📄
ng_gif_demux.c
(10.83 KB)
📄
ng_gif_demux.h
(2.05 KB)
📄
ng_hole.c
(5.85 KB)
📄
ng_hole.h
(2.69 KB)
📄
ng_hub.c
(4.33 KB)
📄
ng_hub.h
(1.68 KB)
📄
ng_iface.c
(19.58 KB)
📄
ng_iface.h
(2.68 KB)
📄
ng_ip_input.c
(4.97 KB)
📄
ng_ip_input.h
(3.78 KB)
📄
ng_ipfw.c
(8.29 KB)
📄
ng_ipfw.h
(1.54 KB)
📄
ng_ksocket.c
(33.9 KB)
📄
ng_ksocket.h
(3.86 KB)
📄
ng_l2tp.c
(40.16 KB)
📄
ng_l2tp.h
(8.12 KB)
📄
ng_lmi.c
(28.15 KB)
📄
ng_lmi.h
(3.2 KB)
📄
ng_macfilter.c
(24.45 KB)
📄
ng_macfilter.h
(5.7 KB)
📄
ng_message.h
(14.69 KB)
📄
ng_mppc.c
(23.88 KB)
📄
ng_mppc.h
(3.29 KB)
📄
ng_nat.c
(23.43 KB)
📄
ng_nat.h
(6.87 KB)
📄
ng_one2many.c
(15.88 KB)
📄
ng_one2many.h
(4.56 KB)
📄
ng_parse.c
(43.85 KB)
📄
ng_parse.h
(18.49 KB)
📄
ng_patch.c
(15.54 KB)
📄
ng_patch.h
(3.64 KB)
📄
ng_pipe.c
(26.97 KB)
📄
ng_pipe.h
(5.56 KB)
📄
ng_ppp.c
(72.27 KB)
📄
ng_ppp.h
(9.77 KB)
📄
ng_pppoe.c
(58.34 KB)
📄
ng_pppoe.h
(9.64 KB)
📄
ng_pptpgre.c
(36.05 KB)
📄
ng_pptpgre.h
(6.04 KB)
📄
ng_pred1.c
(18.02 KB)
📄
ng_pred1.h
(2.73 KB)
📄
ng_rfc1490.c
(13.33 KB)
📄
ng_rfc1490.h
(2.62 KB)
📄
ng_sample.c
(15.14 KB)
📄
ng_sample.h
(3.53 KB)
📄
ng_socket.c
(29.91 KB)
📄
ng_socket.h
(2.73 KB)
📄
ng_socketvar.h
(2.51 KB)
📄
ng_source.c
(21.72 KB)
📄
ng_source.h
(4.96 KB)
📄
ng_split.c
(4.54 KB)
📄
ng_split.h
(1.84 KB)
📄
ng_sppp.c
(9.39 KB)
📄
ng_sppp.h
(1.03 KB)
📄
ng_tag.c
(19.05 KB)
📄
ng_tag.h
(4.55 KB)
📄
ng_tcpmss.c
(10.63 KB)
📄
ng_tcpmss.h
(2.73 KB)
📄
ng_tee.c
(10.61 KB)
📄
ng_tee.h
(3.51 KB)
📄
ng_tty.c
(11.96 KB)
📄
ng_tty.h
(2.49 KB)
📄
ng_vjc.c
(15.66 KB)
📄
ng_vjc.h
(3.5 KB)
📄
ng_vlan.c
(17.61 KB)
📄
ng_vlan.h
(3.47 KB)
Editing: ng_sppp.c
/* * ng_sppp.c Netgraph to Sppp module. */ /*- * Copyright (C) 2002-2004 Cronyx Engineering. * Copyright (C) 2002-2004 Roman Kurakin <rik@cronyx.ru> * * This software is distributed with NO WARRANTIES, not even the implied * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * Authors grant any other persons or organisations a permission to use, * modify and redistribute this software in source and binary forms, * as long as this message is kept with the software, all derivative * works or modified versions. * * Cronyx Id: ng_sppp.c,v 1.1.2.10 2004/03/01 15:17:21 rik Exp $ */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/systm.h> #include <sys/errno.h> #include <sys/kernel.h> #include <sys/malloc.h> #include <sys/mbuf.h> #include <sys/errno.h> #include <sys/sockio.h> #include <sys/socket.h> #include <sys/syslog.h> #include <sys/libkern.h> #include <net/if.h> #include <net/if_var.h> #include <net/if_types.h> #include <net/bpf.h> #include <net/if_sppp.h> #include <netinet/in.h> #include <netgraph/ng_message.h> #include <netgraph/netgraph.h> #include <netgraph/ng_parse.h> #include <netgraph/ng_sppp.h> #ifdef NG_SEPARATE_MALLOC static MALLOC_DEFINE(M_NETGRAPH_SPPP, "netgraph_sppp", "netgraph sppp node"); #else #define M_NETGRAPH_SPPP M_NETGRAPH #endif /* Node private data */ struct ng_sppp_private { struct ifnet *ifp; /* Our interface */ int unit; /* Interface unit number */ node_p node; /* Our netgraph node */ hook_p hook; /* Hook */ }; typedef struct ng_sppp_private *priv_p; /* Interface methods */ static void ng_sppp_start (struct ifnet *ifp); static int ng_sppp_ioctl (struct ifnet *ifp, u_long cmd, caddr_t data); /* Netgraph methods */ static ng_constructor_t ng_sppp_constructor; static ng_rcvmsg_t ng_sppp_rcvmsg; static ng_shutdown_t ng_sppp_shutdown; static ng_newhook_t ng_sppp_newhook; static ng_rcvdata_t ng_sppp_rcvdata; static ng_disconnect_t ng_sppp_disconnect; /* List of commands and how to convert arguments to/from ASCII */ static const struct ng_cmdlist ng_sppp_cmds[] = { { NGM_SPPP_COOKIE, NGM_SPPP_GET_IFNAME, "getifname", NULL, &ng_parse_string_type }, { 0 } }; /* Node type descriptor */ static struct ng_type typestruct = { .version = NG_ABI_VERSION, .name = NG_SPPP_NODE_TYPE, .constructor = ng_sppp_constructor, .rcvmsg = ng_sppp_rcvmsg, .shutdown = ng_sppp_shutdown, .newhook = ng_sppp_newhook, .rcvdata = ng_sppp_rcvdata, .disconnect = ng_sppp_disconnect, .cmdlist = ng_sppp_cmds, }; NETGRAPH_INIT(sppp, &typestruct); MODULE_DEPEND (ng_sppp, sppp, 1, 1, 1); /* We keep a bitmap indicating which unit numbers are free. Zero means the unit number is free, one means it's taken. */ static unsigned char *ng_sppp_units = NULL; static unsigned char ng_sppp_units_len = 0; static unsigned char ng_units_in_use = 0; /* * Find the first free unit number for a new interface. * Increase the size of the unit bitmap as necessary. */ static __inline void ng_sppp_get_unit (int *unit) { int index, bit; unsigned char mask; for (index = 0; index < ng_sppp_units_len && ng_sppp_units[index] == 0xFF; index++); if (index == ng_sppp_units_len) { /* extend array */ unsigned char *newarray; int newlen; newlen = (2 * ng_sppp_units_len) + sizeof (*ng_sppp_units); newarray = malloc (newlen * sizeof (*ng_sppp_units), M_NETGRAPH_SPPP, M_WAITOK); bcopy (ng_sppp_units, newarray, ng_sppp_units_len * sizeof (*ng_sppp_units)); bzero (newarray + ng_sppp_units_len, newlen - ng_sppp_units_len); if (ng_sppp_units != NULL) free (ng_sppp_units, M_NETGRAPH_SPPP); ng_sppp_units = newarray; ng_sppp_units_len = newlen; } mask = ng_sppp_units[index]; for (bit = 0; (mask & 1) != 0; bit++) mask >>= 1; KASSERT ((bit >= 0 && bit < NBBY), ("%s: word=%d bit=%d", __func__, ng_sppp_units[index], bit)); ng_sppp_units[index] |= (1 << bit); *unit = (index * NBBY) + bit; ng_units_in_use++; } /* * Free a no longer needed unit number. */ static __inline void ng_sppp_free_unit (int unit) { int index, bit; index = unit / NBBY; bit = unit % NBBY; KASSERT (index < ng_sppp_units_len, ("%s: unit=%d len=%d", __func__, unit, ng_sppp_units_len)); KASSERT ((ng_sppp_units[index] & (1 << bit)) != 0, ("%s: unit=%d is free", __func__, unit)); ng_sppp_units[index] &= ~(1 << bit); ng_units_in_use--; if (ng_units_in_use == 0) { free (ng_sppp_units, M_NETGRAPH_SPPP); ng_sppp_units_len = 0; ng_sppp_units = NULL; } } /************************************************************************ INTERFACE STUFF ************************************************************************/ /* * Process an ioctl for the interface */ static int ng_sppp_ioctl (struct ifnet *ifp, u_long command, caddr_t data) { int error = 0; error = sppp_ioctl (ifp, command, data); if (error) return error; return error; } /* * This routine should never be called */ static void ng_sppp_start (struct ifnet *ifp) { struct mbuf *m; int len, error = 0; priv_p priv = ifp->if_softc; /* Check interface flags */ /* * This has side effects. It is not good idea to stop sending if we * are not UP. If we are not running we still want to send LCP term * packets. */ /* if (!((ifp->if_flags & IFF_UP) && */ /* (ifp->if_drv_flags & IFF_DRV_RUNNING))) { */ /* return;*/ /* }*/ if (ifp->if_drv_flags & IFF_DRV_OACTIVE) return; if (!priv->hook) return; ifp->if_drv_flags |= IFF_DRV_OACTIVE; while ((m = sppp_dequeue (ifp)) != NULL) { BPF_MTAP (ifp, m); len = m->m_pkthdr.len; NG_SEND_DATA_ONLY (error, priv->hook, m); if (error) { ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; return; } } ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; } /************************************************************************ NETGRAPH NODE STUFF ************************************************************************/ /* * Constructor for a node */ static int ng_sppp_constructor (node_p node) { struct sppp *pp; struct ifnet *ifp; priv_p priv; /* Allocate node and interface private structures */ priv = malloc(sizeof(*priv), M_NETGRAPH_SPPP, M_WAITOK | M_ZERO); ifp = if_alloc(IFT_PPP); if (ifp == NULL) { free (priv, M_NETGRAPH_SPPP); return (ENOSPC); } pp = IFP2SP(ifp); /* Link them together */ ifp->if_softc = priv; priv->ifp = ifp; /* Get an interface unit number */ ng_sppp_get_unit(&priv->unit); /* Link together node and private info */ NG_NODE_SET_PRIVATE (node, priv); priv->node = node; /* Initialize interface structure */ if_initname (SP2IFP(pp), NG_SPPP_IFACE_NAME, priv->unit); ifp->if_start = ng_sppp_start; ifp->if_ioctl = ng_sppp_ioctl; ifp->if_flags = (IFF_POINTOPOINT|IFF_MULTICAST); /* Give this node the same name as the interface (if possible) */ if (ng_name_node(node, SP2IFP(pp)->if_xname) != 0) log (LOG_WARNING, "%s: can't acquire netgraph name\n", SP2IFP(pp)->if_xname); /* Attach the interface */ sppp_attach (ifp); if_attach (ifp); bpfattach (ifp, DLT_NULL, sizeof(u_int32_t)); /* Done */ return (0); } /* * Give our ok for a hook to be added */ static int ng_sppp_newhook (node_p node, hook_p hook, const char *name) { priv_p priv = NG_NODE_PRIVATE (node); if (strcmp (name, NG_SPPP_HOOK_DOWNSTREAM) != 0) return (EINVAL); if (priv->hook) return (EISCONN); priv->hook = hook; NG_HOOK_SET_PRIVATE (hook, priv); return (0); } /* * Receive a control message */ static int ng_sppp_rcvmsg (node_p node, item_p item, hook_p lasthook) { const priv_p priv = NG_NODE_PRIVATE (node); struct ng_mesg *msg = NULL; struct ng_mesg *resp = NULL; struct sppp *const pp = IFP2SP(priv->ifp); int error = 0; NGI_GET_MSG (item, msg); switch (msg->header.typecookie) { case NGM_SPPP_COOKIE: switch (msg->header.cmd) { case NGM_SPPP_GET_IFNAME: NG_MKRESPONSE (resp, msg, IFNAMSIZ, M_NOWAIT); if (!resp) { error = ENOMEM; break; } strlcpy(resp->data, SP2IFP(pp)->if_xname, IFNAMSIZ); break; default: error = EINVAL; break; } break; default: error = EINVAL; break; } NG_RESPOND_MSG (error, node, item, resp); NG_FREE_MSG (msg); return (error); } /* * Recive data from a hook. Pass the packet to the correct input routine. */ static int ng_sppp_rcvdata (hook_p hook, item_p item) { struct mbuf *m; const priv_p priv = NG_NODE_PRIVATE (NG_HOOK_NODE (hook)); struct sppp *const pp = IFP2SP(priv->ifp); NGI_GET_M (item, m); NG_FREE_ITEM (item); /* Sanity checks */ KASSERT (m->m_flags & M_PKTHDR, ("%s: not pkthdr", __func__)); if ((SP2IFP(pp)->if_flags & IFF_UP) == 0) { NG_FREE_M (m); return (ENETDOWN); } /* Update interface stats */ if_inc_counter(SP2IFP(pp), IFCOUNTER_IPACKETS, 1); /* Note receiving interface */ m->m_pkthdr.rcvif = SP2IFP(pp); /* Berkeley packet filter */ BPF_MTAP (SP2IFP(pp), m); /* Send packet */ sppp_input (SP2IFP(pp), m); return 0; } /* * Shutdown and remove the node and its associated interface. */ static int ng_sppp_shutdown (node_p node) { const priv_p priv = NG_NODE_PRIVATE(node); /* Detach from the packet filter list of interfaces. */ bpfdetach (priv->ifp); sppp_detach (priv->ifp); if_detach (priv->ifp); if_free(priv->ifp); ng_sppp_free_unit (priv->unit); free (priv, M_NETGRAPH_SPPP); NG_NODE_SET_PRIVATE (node, NULL); NG_NODE_UNREF (node); return (0); } /* * Hook disconnection. */ static int ng_sppp_disconnect (hook_p hook) { const priv_p priv = NG_NODE_PRIVATE(NG_HOOK_NODE(hook)); if (priv) priv->hook = NULL; return (0); }
Upload File
Create Folder