003 File Manager
Current Path:
/usr/src/usr.sbin/ppp
usr
/
src
/
usr.sbin
/
ppp
/
📁
..
📄
Makefile
(1.66 KB)
📄
Makefile.depend
(435 B)
📄
README.changes
(7.26 KB)
📄
README.nat
(14.85 KB)
📄
acf.c
(3.51 KB)
📄
acf.h
(1.5 KB)
📄
arp.c
(8.24 KB)
📄
arp.h
(1.76 KB)
📄
async.c
(5.39 KB)
📄
async.h
(1.9 KB)
📄
auth.c
(12.02 KB)
📄
auth.h
(2.69 KB)
📄
bundle.c
(56.37 KB)
📄
bundle.h
(7.7 KB)
📄
cbcp.c
(22.53 KB)
📄
cbcp.h
(2.51 KB)
📄
ccp.c
(23.33 KB)
📄
ccp.h
(5.53 KB)
📄
chap.c
(27 KB)
📄
chap.h
(2.69 KB)
📄
chap_ms.c
(12.22 KB)
📄
chap_ms.h
(2.48 KB)
📄
chat.c
(20.41 KB)
📄
chat.h
(2.92 KB)
📄
command.c
(101.76 KB)
📄
command.h
(3.02 KB)
📄
datalink.c
(42.89 KB)
📄
datalink.h
(6.11 KB)
📄
deflate.c
(15.89 KB)
📄
deflate.h
(1.52 KB)
📄
defs.c
(8.61 KB)
📄
defs.h
(5.41 KB)
📄
descriptor.h
(2.24 KB)
📄
ether.c
(20.81 KB)
📄
ether.h
(1.73 KB)
📄
exec.c
(11.47 KB)
📄
exec.h
(1.67 KB)
📄
filter.c
(15.76 KB)
📄
filter.h
(3.8 KB)
📄
fsm.c
(31.01 KB)
📄
fsm.h
(7.02 KB)
📄
hdlc.c
(15.17 KB)
📄
hdlc.h
(3.9 KB)
📄
i4b.h
(1.73 KB)
📄
id.c
(6.05 KB)
📄
id.h
(3.01 KB)
📄
iface.c
(22.41 KB)
📄
iface.h
(2.97 KB)
📄
ip.c
(30.21 KB)
📄
ip.h
(2.09 KB)
📄
ipcp.c
(42.99 KB)
📄
ipcp.h
(5.14 KB)
📄
iplist.c
(5.54 KB)
📄
iplist.h
(1.99 KB)
📄
ipv6cp.c
(21.9 KB)
📄
ipv6cp.h
(3.26 KB)
📄
layer.h
(1.97 KB)
📄
lcp.c
(39.22 KB)
📄
lcp.h
(6.3 KB)
📄
link.c
(10.36 KB)
📄
link.h
(3.42 KB)
📄
log.c
(11.33 KB)
📄
log.h
(4.14 KB)
📄
lqr.c
(17.5 KB)
📄
lqr.h
(3.31 KB)
📄
main.c
(17.93 KB)
📄
main.h
(1.6 KB)
📄
mbuf.c
(10.02 KB)
📄
mbuf.h
(4 KB)
📄
mp.c
(33.66 KB)
📄
mp.h
(4.87 KB)
📄
mppe.c
(20.27 KB)
📄
mppe.h
(1.57 KB)
📄
nat_cmd.c
(15.37 KB)
📄
nat_cmd.h
(1.88 KB)
📄
ncp.c
(13.17 KB)
📄
ncp.h
(4.36 KB)
📄
ncpaddr.c
(23.06 KB)
📄
ncpaddr.h
(4.63 KB)
📄
netgraph.c
(20.65 KB)
📄
netgraph.h
(1.72 KB)
📄
pap.c
(8.83 KB)
📄
pap.h
(1.78 KB)
📄
physical.c
(29.01 KB)
📄
physical.h
(6.5 KB)
📄
ppp.8
(149.48 KB)
📄
ppp.conf
(1.23 KB)
📄
pred.c
(8.83 KB)
📄
pred.h
(1.59 KB)
📄
probe.c
(2.29 KB)
📄
probe.h
(1.57 KB)
📄
prompt.c
(12.92 KB)
📄
prompt.h
(3.87 KB)
📄
proto.c
(3.22 KB)
📄
proto.h
(2.4 KB)
📄
radius.c
(39.38 KB)
📄
radius.h
(4.6 KB)
📄
route.c
(25.91 KB)
📄
route.h
(3.3 KB)
📄
server.c
(10.9 KB)
📄
server.h
(2.26 KB)
📄
sig.c
(3.45 KB)
📄
sig.h
(1.6 KB)
📄
slcompress.c
(17.2 KB)
📄
slcompress.h
(6.48 KB)
📄
sync.c
(2.7 KB)
📄
sync.h
(1.44 KB)
📄
systems.c
(11.45 KB)
📄
systems.h
(2.02 KB)
📄
tcp.c
(5.63 KB)
📄
tcp.h
(1.66 KB)
📄
tcpmss.c
(5.06 KB)
📄
tcpmss.h
(1.44 KB)
📄
throughput.c
(8.84 KB)
📄
throughput.h
(2.91 KB)
📄
timer.c
(8.14 KB)
📄
timer.h
(2.31 KB)
📄
tty.c
(20.63 KB)
📄
tty.h
(1.73 KB)
📄
tun.c
(3.27 KB)
📄
tun.h
(1.58 KB)
📄
ua.h
(2.98 KB)
📄
udp.c
(8.7 KB)
📄
udp.h
(1.67 KB)
📄
vjcomp.c
(5.68 KB)
📄
vjcomp.h
(1.53 KB)
Editing: arp.c
/* * sys-bsd.c - System-dependent procedures for setting up * PPP interfaces on bsd-4.4-ish systems (including 386BSD, NetBSD, etc.) * * SPDX-License-Identifier: BSD-1-Clause * * Copyright (c) 1989 Carnegie Mellon University. * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that the above copyright notice and this paragraph are * duplicated in all such forms and that any documentation, * advertising materials, and other materials related to such * distribution and use acknowledge that the software was developed * by Carnegie Mellon University. The name of the * University may not be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * $FreeBSD$ * */ /* * TODO: */ #include <sys/param.h> #include <sys/socket.h> #include <net/if.h> #include <net/route.h> #include <net/if_dl.h> #include <netinet/in.h> #include <netinet/if_ether.h> #include <arpa/inet.h> #include <netinet/in_systm.h> #include <netinet/ip.h> #include <sys/un.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/sysctl.h> #include <termios.h> #include <unistd.h> #include "layer.h" #include "mbuf.h" #include "log.h" #include "id.h" #include "timer.h" #include "fsm.h" #include "defs.h" #include "iplist.h" #include "throughput.h" #include "slcompress.h" #include "lqr.h" #include "hdlc.h" #include "ncpaddr.h" #include "ipcp.h" #include "ipv6cp.h" #include "descriptor.h" #include "lcp.h" #include "ccp.h" #include "link.h" #include "mp.h" #include "ncp.h" #include "filter.h" #ifndef NORADIUS #include "radius.h" #endif #include "bundle.h" #include "iface.h" #include "arp.h" /* * SET_SA_FAMILY - set the sa_family field of a struct sockaddr, * if it exists. */ #define SET_SA_FAMILY(addr, family) \ memset((char *) &(addr), '\0', sizeof(addr)); \ addr.sa_family = (family); \ addr.sa_len = sizeof(addr); #if RTM_VERSION >= 3 /* * arp_SetProxy - Make a proxy ARP entry for the peer. */ static struct { struct rt_msghdr hdr; struct sockaddr_in dst; struct sockaddr_dl hwa; char extra[128]; } arpmsg; static int arp_ProxySub(struct bundle *bundle, struct in_addr addr, int add) { int routes; /* * Get the hardware address of an interface on the same subnet as our local * address. */ memset(&arpmsg, 0, sizeof arpmsg); if (!arp_EtherAddr(addr, &arpmsg.hwa, 0)) { log_Printf(LogWARN, "%s: Cannot determine ethernet address for proxy ARP\n", inet_ntoa(addr)); return 0; } routes = ID0socket(PF_ROUTE, SOCK_RAW, AF_INET); if (routes < 0) { log_Printf(LogERROR, "arp_SetProxy: opening routing socket: %s\n", strerror(errno)); return 0; } arpmsg.hdr.rtm_type = add ? RTM_ADD : RTM_DELETE; arpmsg.hdr.rtm_flags = RTF_ANNOUNCE | RTF_HOST | RTF_STATIC | RTF_LLDATA; arpmsg.hdr.rtm_version = RTM_VERSION; arpmsg.hdr.rtm_seq = ++bundle->routing_seq; arpmsg.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY; arpmsg.hdr.rtm_inits = RTV_EXPIRE; arpmsg.dst.sin_len = sizeof(struct sockaddr_in); arpmsg.dst.sin_family = AF_INET; arpmsg.dst.sin_addr.s_addr = addr.s_addr; arpmsg.hdr.rtm_msglen = (char *) &arpmsg.hwa - (char *) &arpmsg + arpmsg.hwa.sdl_len; if (ID0write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0 && !(!add && errno == ESRCH)) { log_Printf(LogERROR, "%s proxy arp entry %s: %s\n", add ? "Add" : "Delete", inet_ntoa(addr), strerror(errno)); close(routes); return 0; } close(routes); return 1; } int arp_SetProxy(struct bundle *bundle, struct in_addr addr) { return (arp_ProxySub(bundle, addr, 1)); } /* * arp_ClearProxy - Delete the proxy ARP entry for the peer. */ int arp_ClearProxy(struct bundle *bundle, struct in_addr addr) { return (arp_ProxySub(bundle, addr, 0)); } #else /* RTM_VERSION */ /* * arp_SetProxy - Make a proxy ARP entry for the peer. */ int arp_SetProxy(struct bundle *bundle, struct in_addr addr, int s) { struct arpreq arpreq; struct { struct sockaddr_dl sdl; char space[128]; } dls; memset(&arpreq, '\0', sizeof arpreq); /* * Get the hardware address of an interface on the same subnet as our local * address. */ if (!arp_EtherAddr(addr, &dls.sdl, 1)) { log_Printf(LOG_PHASE_BIT, "Cannot determine ethernet address for " "proxy ARP\n"); return 0; } arpreq.arp_ha.sa_len = sizeof(struct sockaddr); arpreq.arp_ha.sa_family = AF_UNSPEC; memcpy(arpreq.arp_ha.sa_data, LLADDR(&dls.sdl), dls.sdl.sdl_alen); SET_SA_FAMILY(arpreq.arp_pa, AF_INET); ((struct sockaddr_in *)&arpreq.arp_pa)->sin_addr.s_addr = addr.s_addr; arpreq.arp_flags = ATF_PERM | ATF_PUBL; if (ID0ioctl(s, SIOCSARP, (caddr_t) & arpreq) < 0) { log_Printf(LogERROR, "arp_SetProxy: ioctl(SIOCSARP): %s\n", strerror(errno)); return 0; } return 1; } /* * arp_ClearProxy - Delete the proxy ARP entry for the peer. */ int arp_ClearProxy(struct bundle *bundle, struct in_addr addr, int s) { struct arpreq arpreq; memset(&arpreq, '\0', sizeof arpreq); SET_SA_FAMILY(arpreq.arp_pa, AF_INET); ((struct sockaddr_in *)&arpreq.arp_pa)->sin_addr.s_addr = addr.s_addr; if (ID0ioctl(s, SIOCDARP, (caddr_t) & arpreq) < 0) { log_Printf(LogERROR, "arp_ClearProxy: ioctl(SIOCDARP): %s\n", strerror(errno)); return 0; } return 1; } #endif /* RTM_VERSION */ /* * arp_EtherAddr - get the hardware address of an interface on the * the same subnet as ipaddr. */ int arp_EtherAddr(struct in_addr ipaddr, struct sockaddr_dl *hwaddr, int verbose) { int mib[6], skip; size_t needed; char *buf, *ptr, *end; struct if_msghdr *ifm; struct ifa_msghdr *ifam; struct sockaddr_dl *dl; struct sockaddr *sa[RTAX_MAX]; mib[0] = CTL_NET; mib[1] = PF_ROUTE; mib[2] = 0; mib[3] = 0; mib[4] = NET_RT_IFLIST; mib[5] = 0; if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) { log_Printf(LogERROR, "arp_EtherAddr: sysctl: estimate: %s\n", strerror(errno)); return 0; } if ((buf = malloc(needed)) == NULL) return 0; if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) { free(buf); return 0; } end = buf + needed; ptr = buf; while (ptr < end) { ifm = (struct if_msghdr *)ptr; /* On if_msghdr */ if (ifm->ifm_type != RTM_IFINFO) break; dl = (struct sockaddr_dl *)(ifm + 1); /* Single _dl at end */ skip = (ifm->ifm_flags & (IFF_UP | IFF_BROADCAST | IFF_POINTOPOINT | IFF_NOARP | IFF_LOOPBACK)) != (IFF_UP | IFF_BROADCAST); ptr += ifm->ifm_msglen; /* First ifa_msghdr */ while (ptr < end) { ifam = (struct ifa_msghdr *)ptr; /* Next ifa_msghdr (alias) */ if (ifam->ifam_type != RTM_NEWADDR) /* finished ? */ break; ptr += ifam->ifam_msglen; if (skip || (ifam->ifam_addrs & (RTA_NETMASK|RTA_IFA)) != (RTA_NETMASK|RTA_IFA)) continue; /* Found a candidate. Do the addresses match ? */ if (log_IsKept(LogDEBUG) && ptr == (char *)ifm + ifm->ifm_msglen + ifam->ifam_msglen) log_Printf(LogDEBUG, "%.*s interface is a candidate for proxy\n", dl->sdl_nlen, dl->sdl_data); iface_ParseHdr(ifam, sa); if (sa[RTAX_IFA]->sa_family == AF_INET) { struct sockaddr_in *ifa, *netmask; ifa = (struct sockaddr_in *)sa[RTAX_IFA]; netmask = (struct sockaddr_in *)sa[RTAX_NETMASK]; if (log_IsKept(LogDEBUG)) { char a[16]; strncpy(a, inet_ntoa(netmask->sin_addr), sizeof a - 1); a[sizeof a - 1] = '\0'; log_Printf(LogDEBUG, "Check addr %s, mask %s\n", inet_ntoa(ifa->sin_addr), a); } if ((ifa->sin_addr.s_addr & netmask->sin_addr.s_addr) == (ipaddr.s_addr & netmask->sin_addr.s_addr)) { log_Printf(verbose ? LogPHASE : LogDEBUG, "Found interface %.*s for %s\n", dl->sdl_nlen, dl->sdl_data, inet_ntoa(ipaddr)); memcpy(hwaddr, dl, dl->sdl_len); free(buf); return 1; } } } } free(buf); return 0; }
Upload File
Create Folder