From 84b263706cf1e1230ca2482b9b74e7f901dd2446 Mon Sep 17 00:00:00 2001 From: christos Date: Thu, 28 Nov 2013 22:33:42 +0000 Subject: [PATCH] Merge local changes, add build glue. --- external/bsd/ppp/Makefile | 5 + external/bsd/ppp/dist/chat/chat.8 | 317 ++- external/bsd/ppp/dist/chat/chat.c | 127 +- external/bsd/ppp/dist/pppd/auth.c | 45 +- external/bsd/ppp/dist/pppd/cbcp.c | 30 +- external/bsd/ppp/dist/pppd/cbcp.h | 2 + external/bsd/ppp/dist/pppd/ccp.c | 10 +- external/bsd/ppp/dist/pppd/ccp.h | 4 +- external/bsd/ppp/dist/pppd/chap-md5.c | 30 +- external/bsd/ppp/dist/pppd/chap-md5.h | 2 + external/bsd/ppp/dist/pppd/chap-new.c | 8 + external/bsd/ppp/dist/pppd/chap-new.h | 2 + external/bsd/ppp/dist/pppd/chap_ms.c | 91 +- external/bsd/ppp/dist/pppd/chap_ms.h | 2 + external/bsd/ppp/dist/pppd/demand.c | 25 +- external/bsd/ppp/dist/pppd/eap.c | 68 +- external/bsd/ppp/dist/pppd/eap.h | 2 + external/bsd/ppp/dist/pppd/ecp.c | 8 +- external/bsd/ppp/dist/pppd/ecp.h | 2 + external/bsd/ppp/dist/pppd/eui64.c | 9 +- external/bsd/ppp/dist/pppd/eui64.h | 2 + external/bsd/ppp/dist/pppd/fsm.c | 14 +- external/bsd/ppp/dist/pppd/fsm.h | 2 + external/bsd/ppp/dist/pppd/ipcp.c | 9 +- external/bsd/ppp/dist/pppd/ipcp.h | 2 + external/bsd/ppp/dist/pppd/ipv6cp.c | 19 +- external/bsd/ppp/dist/pppd/ipv6cp.h | 2 + external/bsd/ppp/dist/pppd/ipxcp.c | 11 +- external/bsd/ppp/dist/pppd/ipxcp.h | 2 + external/bsd/ppp/dist/pppd/lcp.c | 9 +- external/bsd/ppp/dist/pppd/lcp.h | 2 + external/bsd/ppp/dist/pppd/magic.c | 9 +- external/bsd/ppp/dist/pppd/magic.h | 2 + external/bsd/ppp/dist/pppd/main.c | 20 +- external/bsd/ppp/dist/pppd/mppe.h | 2 + external/bsd/ppp/dist/pppd/multilink.c | 8 +- external/bsd/ppp/dist/pppd/options.c | 122 +- external/bsd/ppp/dist/pppd/patchlevel.h | 2 + external/bsd/ppp/dist/pppd/pathnames.h | 15 +- external/bsd/ppp/dist/pppd/pppcrypt.c | 26 +- external/bsd/ppp/dist/pppd/pppcrypt.h | 2 + external/bsd/ppp/dist/pppd/pppd.8 | 1 + external/bsd/ppp/dist/pppd/pppd.h | 17 +- external/bsd/ppp/dist/pppd/session.c | 26 +- external/bsd/ppp/dist/pppd/session.h | 2 + external/bsd/ppp/dist/pppd/tty.c | 8 + external/bsd/ppp/dist/pppd/upap.c | 9 +- external/bsd/ppp/dist/pppd/upap.h | 2 + external/bsd/ppp/dist/pppd/utils.c | 56 +- external/bsd/ppp/dist/pppdump/.gitignore | 1 - external/bsd/ppp/dist/pppdump/bsd-comp.c | 50 +- external/bsd/ppp/dist/pppdump/deflate.c | 47 +- external/bsd/ppp/dist/pppdump/pppdump.c | 50 +- external/bsd/ppp/dist/pppstats/.gitignore | 1 - external/bsd/ppp/dist/pppstats/pppstats.c | 22 +- external/bsd/ppp/ppp2netbsd | 70 + external/bsd/ppp/usr.sbin/Makefile | 5 + external/bsd/ppp/usr.sbin/Makefile.inc | 13 + external/bsd/ppp/usr.sbin/chat/Makefile | 10 + .../bsd/ppp/usr.sbin/plugins/minconn/Makefile | 16 + .../ppp/usr.sbin/plugins/passwordfd/Makefile | 16 + .../bsd/ppp/usr.sbin/plugins/status/Makefile | 14 + .../bsd/ppp/usr.sbin/plugins/status/status.c | 146 ++ external/bsd/ppp/usr.sbin/pppd/Makefile | 42 + external/bsd/ppp/usr.sbin/pppd/sys-bsd.c | 2071 +++++++++++++++++ external/bsd/ppp/usr.sbin/pppd/tdb.c | 1293 ++++++++++ external/bsd/ppp/usr.sbin/pppd/tdb.h | 79 + external/bsd/ppp/usr.sbin/pppdump/Makefile | 14 + external/bsd/ppp/usr.sbin/pppdump/pppdump.h | 37 + external/bsd/ppp/usr.sbin/pppstats/Makefile | 12 + 70 files changed, 4714 insertions(+), 487 deletions(-) create mode 100644 external/bsd/ppp/Makefile delete mode 100644 external/bsd/ppp/dist/pppdump/.gitignore delete mode 100644 external/bsd/ppp/dist/pppstats/.gitignore create mode 100755 external/bsd/ppp/ppp2netbsd create mode 100644 external/bsd/ppp/usr.sbin/Makefile create mode 100644 external/bsd/ppp/usr.sbin/Makefile.inc create mode 100644 external/bsd/ppp/usr.sbin/chat/Makefile create mode 100644 external/bsd/ppp/usr.sbin/plugins/minconn/Makefile create mode 100644 external/bsd/ppp/usr.sbin/plugins/passwordfd/Makefile create mode 100644 external/bsd/ppp/usr.sbin/plugins/status/Makefile create mode 100644 external/bsd/ppp/usr.sbin/plugins/status/status.c create mode 100644 external/bsd/ppp/usr.sbin/pppd/Makefile create mode 100644 external/bsd/ppp/usr.sbin/pppd/sys-bsd.c create mode 100644 external/bsd/ppp/usr.sbin/pppd/tdb.c create mode 100644 external/bsd/ppp/usr.sbin/pppd/tdb.h create mode 100644 external/bsd/ppp/usr.sbin/pppdump/Makefile create mode 100644 external/bsd/ppp/usr.sbin/pppdump/pppdump.h create mode 100644 external/bsd/ppp/usr.sbin/pppstats/Makefile diff --git a/external/bsd/ppp/Makefile b/external/bsd/ppp/Makefile new file mode 100644 index 000000000000..5ffaae37810d --- /dev/null +++ b/external/bsd/ppp/Makefile @@ -0,0 +1,5 @@ +# $NetBSD: Makefile,v 1.1 2013/11/28 22:33:42 christos Exp $ + +SUBDIR= usr.sbin + +.include diff --git a/external/bsd/ppp/dist/chat/chat.8 b/external/bsd/ppp/dist/chat/chat.8 index eef5ba0b49ea..be50671b4e08 100644 --- a/external/bsd/ppp/dist/chat/chat.8 +++ b/external/bsd/ppp/dist/chat/chat.8 @@ -1,4 +1,4 @@ -.\" -*- nroff -*- +.\" $NetBSD: chat.8,v 1.2 2013/11/28 22:33:42 christos Exp $ .\" manual page [] for chat 1.8 .\" Id: chat.8,v 1.11 2004/11/13 12:22:49 paulus Exp .\" SH section heading @@ -18,35 +18,47 @@ chat \- Automated conversational script with a modem .SH DESCRIPTION .LP The \fIchat\fR program defines a conversational exchange between the -computer and the modem. Its primary purpose is to establish the +computer and the modem. +Its primary purpose is to establish the connection between the Point-to-Point Protocol Daemon (\fIpppd\fR) and the remote's \fIpppd\fR process. .SH OPTIONS .TP -.B \-f \fI -Read the chat script from the chat \fIfile\fR. The use of this option -is mutually exclusive with the chat script parameters. The user must -have read access to the file. Multiple lines are permitted in the -file. Space or horizontal tab characters should be used to separate +.B \-f \fI\*[Lt]chat file\*[Gt] +Read the chat script from the chat \fIfile\fR. +The use of this option +is mutually exclusive with the chat script parameters. +The user must +have read access to the file. +Multiple lines are permitted in the +file. +Space or horizontal tab characters should be used to separate the strings. .TP -.B \-t \fI -Set the timeout for the expected string to be received. If the string +.B \-t \fI\*[Lt]timeout\*[Gt] +Set the timeout for the expected string to be received. +If the string is not received within the time limit then the reply string is not -sent. An alternate reply may be sent or the script will fail if there -is no alternate reply string. A failed script will cause the +sent. +An alternate reply may be sent or the script will fail if there +is no alternate reply string. +A failed script will cause the \fIchat\fR program to terminate with a non-zero error code. .TP -.B \-r \fI -Set the file for output of the report strings. If you use the keyword -\fIREPORT\fR, the resulting strings are written to this file. If this +.B \-r \fI\*[Lt]report file\*[Gt] +Set the file for output of the report strings. +If you use the keyword +\fIREPORT\fR, the resulting strings are written to this file. +If this option is not used and you still use \fIREPORT\fR keywords, the \fIstderr\fR file is used for the report strings. .TP .B \-e -Start with the echo option turned on. Echoing may also be turned on +Start with the echo option turned on. +Echoing may also be turned on or off at specific points in the chat script by using the \fIECHO\fR -keyword. When echoing is enabled, all output from the modem is echoed +keyword. +When echoing is enabled, all output from the modem is echoed to \fIstderr\fR. .TP .B \-E @@ -54,33 +66,40 @@ Enables environment variable substitution within chat scripts using the standard \fI$xxx\fR syntax. .TP .B \-v -Request that the \fIchat\fR script be executed in a verbose mode. The +Request that the \fIchat\fR script be executed in a verbose mode. +The \fIchat\fR program will then log the execution state of the chat script as well as all text received from the modem and the output -strings sent to the modem. The default is to log through the SYSLOG; +strings sent to the modem. + The default is to log through the SYSLOG; the logging method may be altered with the \-S and \-s flags. .TP .B \-V Request that the \fIchat\fR script be executed in a stderr verbose -mode. The \fIchat\fR program will then log all text received from the -modem and the output strings sent to the modem to the stderr device. This +mode. +The \fIchat\fR program will then log all text received from the +modem and the output strings sent to the modem to the stderr device. +This device is usually the local console at the station running the chat or pppd program. .TP .B \-s -Use stderr. All log messages from '\-v' and all error messages will be +Use stderr. + All log messages from '\-v' and all error messages will be sent to stderr. .TP .B \-S -Do not use the SYSLOG. By default, error messages are sent to the -SYSLOG. The use of \-S will prevent both log messages from '\-v' and +Do not use the SYSLOG. + By default, error messages are sent to the +SYSLOG. + The use of \-S will prevent both log messages from '\-v' and error messages from being sent to the SYSLOG. .TP -.B \-T \fI +.B \-T \fI\*[Lt]phone number\*[Gt] Pass in an arbitrary string, usually a phone number, that will be substituted for the \eT substitution metacharacter in a send string. .TP -.B \-U \fI +.B \-U \fI\*[Lt]phone number 2\*[Gt] Pass in a second string, usually a phone number, that will be substituted for the \eU substitution metacharacter in a send string. This is useful when dialing an ISDN terminal adapter that requires two @@ -100,29 +119,37 @@ separated by a dash as in the following example: ogin:\-BREAK\-ogin: ppp ssword: hello2u2 .LP This line indicates that the \fIchat\fR program should expect the string -"ogin:". If it fails to receive a login prompt within the time interval +"ogin:". +If it fails to receive a login prompt within the time interval allotted, it is to send a break sequence to the remote and then expect the -string "ogin:". If the first "ogin:" is received then the break sequence is +string "ogin:". +If the first "ogin:" is received then the break sequence is not generated. .LP Once it received the login prompt the \fIchat\fR program will send the -string ppp and then expect the prompt "ssword:". When it receives the +string ppp and then expect the prompt "ssword:". +When it receives the prompt for the password, it will send the password hello2u2. .LP -A carriage return is normally sent following the reply string. It is not +A carriage return is normally sent following the reply string. +It is not expected in the "expect" string unless it is specifically requested by using the \er character sequence. .LP The expect sequence should contain only what is needed to identify the -string. Since it is normally stored on a disk file, it should not contain -variable information. It is generally not acceptable to look for time +string. +Since it is normally stored on a disk file, it should not contain +variable information. +It is generally not acceptable to look for time strings, network identification strings, or other variable pieces of data as an expect string. .LP To help correct for characters which may be corrupted during the initial -sequence, look for the string "ogin:" rather than "login:". It is possible +sequence, look for the string "ogin:" rather than "login:". +It is possible that the leading "l" character may be received in error and you may never -find the string even though it was sent by the system. For this reason, +find the string even though it was sent by the system. +For this reason, scripts look for "ogin:" rather than "login:" and "ssword:" rather than "password:". .LP @@ -132,21 +159,27 @@ ogin: ppp ssword: hello2u2 .LP In other words, expect ....ogin:, send ppp, expect ...ssword:, send hello2u2. .LP -In actual practice, simple scripts are rare. At the vary least, you +In actual practice, simple scripts are rare. +At the vary least, you should include sub-expect sequences should the original string not be -received. For example, consider the following script: +received. +For example, consider the following script: .IP ogin:\-\-ogin: ppp ssword: hello2u2 .LP -This would be a better script than the simple one used earlier. This would look +This would be a better script than the simple one used earlier. +This would look for the same login: prompt, however, if one was not received, a single -return sequence is sent and then it will look for login: again. Should line +return sequence is sent and then it will look for login: again. +Should line noise obscure the first login prompt then sending the empty line will usually generate a login prompt again. .SH COMMENTS -Comments can be embedded in the chat script. A comment is a line which -starts with the \fB#\fR (hash) character in column 1. Such comment -lines are just ignored by the chat program. If a '#' character is to +Comments can be embedded in the chat script. +A comment is a line which +starts with the \fB#\fR (hash) character in column 1. +Such comment lines are just ignored by the chat program. +If a '#' character is to be expected as the first character of the expect sequence, you should quote the expect string. If you want to wait for a prompt that starts with a # (hash) @@ -160,36 +193,47 @@ character, you would have to write something like this: .SH SENDING DATA FROM A FILE If the string to send starts with an at sign (@), the rest of the string is taken to be the name of a file to read to get the string to -send. If the last character of the data read is a newline, it is -removed. The file can be a named pipe (or fifo) instead of a regular -file. This provides a way for \fBchat\fR to communicate with another +send. +If the last character of the data read is a newline, it is removed. +The file can be a named pipe (or fifo) instead of a regular file. +This provides a way for \fBchat\fR to communicate with another program, for example, a program to prompt the user and receive a password typed in. .LP .SH ABORT STRINGS -Many modems will report the status of the call as a string. These -strings may be \fBCONNECTED\fR or \fBNO CARRIER\fR or \fBBUSY\fR. It -is often desirable to terminate the script should the modem fail to -connect to the remote. The difficulty is that a script would not know -exactly which modem string it may receive. On one attempt, it may +Many modems will report the status of the call as a string. +These +strings may be \fBCONNECTED\fR or \fBNO CARRIER\fR or \fBBUSY\fR. +It is often desirable to terminate the script should the modem fail to +connect to the remote. +The difficulty is that a script would not know +exactly which modem string it may receive. +On one attempt, it may receive \fBBUSY\fR while the next time it may receive \fBNO CARRIER\fR. .LP These "abort" strings may be specified in the script using the \fIABORT\fR -sequence. It is written in the script as in the following example: +sequence. +It is written in the script as in the following example: .IP ABORT BUSY ABORT 'NO CARRIER' '' ATZ OK ATDT5551212 CONNECT .LP -This sequence will expect nothing; and then send the string ATZ. The -expected response to this is the string \fIOK\fR. When it receives \fIOK\fR, -the string ATDT5551212 to dial the telephone. The expected string is -\fICONNECT\fR. If the string \fICONNECT\fR is received the remainder of the -script is executed. However, should the modem find a busy telephone, it will -send the string \fIBUSY\fR. This will cause the string to match the abort -character sequence. The script will then fail because it found a match to -the abort string. If it received the string \fINO CARRIER\fR, it will abort -for the same reason. Either string may be received. Either string will -terminate the \fIchat\fR script. +This sequence will expect nothing; and then send the string ATZ. +The expected response to this is the string \fIOK\fR. +When it receives \fIOK\fR, +the string ATDT5551212 to dial the telephone. +The expected string is +\fICONNECT\fR. +If the string \fICONNECT\fR is received the remainder of the +script is executed. +However, should the modem find a busy telephone, it will +send the string \fIBUSY\fR. +This will cause the string to match the abort character sequence. +The script will then fail because it found a match to the abort string. +If it received the string \fINO CARRIER\fR, it will abort +for the same reason. +Either string may be received. +Either string will terminate the \fIchat\fR script. .SH CLR_ABORT STRINGS This sequence allows for clearing previously set \fBABORT\fR strings. \fBABORT\fR strings are kept in an array of a pre-determined size (at @@ -197,18 +241,21 @@ compilation time); \fBCLR_ABORT\fR will reclaim the space for cleared entries so that new strings can use that space. .SH SAY STRINGS The \fBSAY\fR directive allows the script to send strings to the user -at the terminal via standard error. If \fBchat\fR is being run by +at the terminal via standard error. + If \fBchat\fR is being run by pppd, and pppd is running as a daemon (detached from its controlling terminal), standard error will normally be redirected to the file /etc/ppp/connect\-errors. .LP -\fBSAY\fR strings must be enclosed in single or double quotes. If +\fBSAY\fR strings must be enclosed in single or double quotes. +If carriage return and line feed are needed in the string to be output, you must explicitly add them to your string. .LP The SAY strings could be used to give progress messages in sections of the script where you want to have 'ECHO OFF' but still let the user -know what is happening. An example is: +know what is happening. + An example is: .IP ABORT BUSY .br @@ -220,7 +267,8 @@ SAY "Dialling your ISP...\en" .br TIMEOUT 120 .br -SAY "Waiting up to 2 minutes for connection ... " +SAY "Waiting up to 2 minutes for connection ... +" .br CONNECT '' .br @@ -236,39 +284,47 @@ SAY "Logged in OK ...\en" \fIetc ...\fR .LP This sequence will only present the SAY strings to the user and all -the details of the script will remain hidden. For example, if the +the details of the script will remain hidden. +For example, if the above script works, the user will see: .IP Dialling your ISP... .br -Waiting up to 2 minutes for connection ... Connected, now logging in ... +Waiting up to 2 minutes for connection ... +Connected, now logging in ... .br Logged in OK ... .LP .SH REPORT STRINGS -A \fBreport\fR string is similar to the ABORT string. The difference +A \fBreport\fR string is similar to the ABORT string. +The difference is that the strings, and all characters to the next control character such as a carriage return, are written to the report file. .LP The report strings may be used to isolate the transmission rate of the -modem's connect string and return the value to the chat user. The -analysis of the report string logic occurs in conjunction with the -other string processing such as looking for the expect string. The use +modem's connect string and return the value to the chat user. +The analysis of the report string logic occurs in conjunction with the +other string processing such as looking for the expect string. +The use of the same string for a report and abort sequence is probably not very useful, however, it is possible. .LP The report strings to no change the completion code of the program. .LP These "report" strings may be specified in the script using the \fIREPORT\fR -sequence. It is written in the script as in the following example: +sequence. +It is written in the script as in the following example: .IP REPORT CONNECT ABORT BUSY '' ATDT5551212 CONNECT '' ogin: account .LP This sequence will expect nothing; and then send the string -ATDT5551212 to dial the telephone. The expected string is -\fICONNECT\fR. If the string \fICONNECT\fR is received the remainder -of the script is executed. In addition the program will write to the +ATDT5551212 to dial the telephone. +The expected string is +\fICONNECT\fR. +If the string \fICONNECT\fR is received the remainder +of the script is executed. +In addition the program will write to the expect\-file the string "CONNECT" plus any characters which follow it such as the connection rate. .SH CLR_REPORT STRINGS @@ -278,11 +334,15 @@ compilation time); \fBCLR_REPORT\fR will reclaim the space for cleared entries so that new strings can use that space. .SH ECHO The echo options controls whether the output from the modem is echoed -to \fIstderr\fR. This option may be set with the \fI\-e\fR option, but -it can also be controlled by the \fIECHO\fR keyword. The "expect\-send" +to \fIstderr\fR. +This option may be set with the \fI\-e\fR option, but +it can also be controlled by the \fIECHO\fR keyword. +The "expect\-send" pair \fIECHO\fR \fION\fR enables echoing, and \fIECHO\fR \fIOFF\fR -disables it. With this keyword you can select which parts of the -conversation should be visible. For instance, with the following +disables it. +With this keyword you can select which parts of the +conversation should be visible. +For instance, with the following script: .IP ABORT 'BUSY' @@ -306,16 +366,20 @@ but starting with the \fICONNECT\fR (or \fIBUSY\fR) message, everything will be echoed. .SH HANGUP The HANGUP options control whether a modem hangup should be considered -as an error or not. This option is useful in scripts for dialling -systems which will hang up and call your system back. The HANGUP +as an error or not. + This option is useful in scripts for dialling +systems which will hang up and call your system back. + The HANGUP options can be \fBON\fR or \fBOFF\fR. .br When HANGUP is set OFF and the modem hangs up (e.g., after the first stage of logging in to a callback system), \fBchat\fR will continue running the script (e.g., waiting for the incoming call and second -stage login prompt). As soon as the incoming call is connected, you +stage login prompt). +As soon as the incoming call is connected, you should use the \fBHANGUP ON\fR directive to reinstall normal hang up -signal behavior. Here is an (simple) example script: +signal behavior. + Here is an (simple) example script: .IP ABORT 'BUSY' .br @@ -348,8 +412,8 @@ ogin:\-\-BREAK\-\-ogin: real_account \fIetc ...\fR .LP .SH TIMEOUT -The initial timeout value is 45 seconds. This may be changed using the \fB\-t\fR -parameter. +The initial timeout value is 45 seconds. +This may be changed using the \fB\-t\fR parameter. .LP To change the timeout value for the next expect string, the following example may be used: @@ -357,47 +421,60 @@ example may be used: ATZ OK ATDT5551212 CONNECT TIMEOUT 10 ogin:\-\-ogin: TIMEOUT 5 assword: hello2u2 .LP This will change the timeout to 10 seconds when it expects the login: -prompt. The timeout is then changed to 5 seconds when it looks for the +prompt. +The timeout is then changed to 5 seconds when it looks for the password prompt. .LP The timeout, once changed, remains in effect until it is changed again. .SH SENDING EOT The special reply string of \fIEOT\fR indicates that the chat program -should send an EOT character to the remote. This is normally the -End-of-file character sequence. A return character is not sent +should send an EOT character to the remote. +This is normally the +End-of-file character sequence. +A return character is not sent following the EOT. The EOT sequence may be embedded into the send string using the sequence \fI^D\fR. .SH GENERATING BREAK The special reply string of \fIBREAK\fR will cause a break condition -to be sent. The break is a special signal on the transmitter. The +to be sent. +The break is a special signal on the transmitter. +The normal processing on the receiver is to change the transmission rate. It may be used to cycle through the available transmission rates on the remote until you are able to receive a valid login prompt. The break sequence may be embedded into the send string using the \fI\eK\fR sequence. .SH ESCAPE SEQUENCES -The expect and reply strings may contain escape sequences. All of the -sequences are legal in the reply string. Many are legal in the expect. +The expect and reply strings may contain escape sequences. +All of the +sequences are legal in the reply string. +Many are legal in the expect. Those which are not valid in the expect sequence are so indicated. .TP .B '' -Expects or sends a null string. If you send a null string then it will still -send the return character. This sequence may either be a pair of apostrophe +Expects or sends a null string. +If you send a null string then it will still +send the return character. +This sequence may either be a pair of apostrophe or quote characters. .TP .B \eb represents a backspace character. .TP .B \ec -Suppresses the newline at the end of the reply string. This is the only -method to send a string without a trailing return character. It must -be at the end of the send string. For example, +Suppresses the newline at the end of the reply string. +This is the only +method to send a string without a trailing return character. +It must +be at the end of the send string. +For example, the sequence hello\ec will simply send the characters h, e, l, l, o. .I (not valid in expect.) .TP .B \ed -Delay for one second. The program uses sleep(1) which will delay to a +Delay for one second. +The program uses sleep(1) which will delay to a maximum of one second. .I (not valid in expect.) .TP @@ -409,15 +486,18 @@ Insert a BREAK Send a newline or linefeed character. .TP .B \eN -Send a null character. The same sequence may be represented by \e0. +Send a null character. +The same sequence may be represented by \e0. .I (not valid in expect.) .TP .B \ep -Pause for a fraction of a second. The delay is 1/10th of a second. +Pause for a fraction of a second. +The delay is 1/10th of a second. .I (not valid in expect.) .TP .B \eq -Suppress writing the string to the SYSLOG file. The string ?????? is +Suppress writing the string to the SYSLOG file. +The string ?????? is written to the log in its place. .I (not valid in expect.) .TP @@ -425,8 +505,10 @@ written to the log in its place. Send or expect a carriage return. .TP .B \es -Represents a space character in the string. This may be used when it -is not desirable to quote the strings which contains spaces. The +Represents a space character in the string. +This may be used when it +is not desirable to quote the strings which contains spaces. +The sequence 'HI TIM' and HI\esTIM are the same. .TP .B \et @@ -454,8 +536,10 @@ For example, the character DC1 (17) is shown as \^^Q. .I (some characters are not valid in expect.) .SH ENVIRONMENT VARIABLES Environment variables are available within chat scripts, if the \fI\-E\fR -option was specified in the command line. The metacharacter \fI$\fR is used -to introduce the name of the environment variable to substitute. If the +option was specified in the command line. +The metacharacter \fI$\fR is used +to introduce the name of the environment variable to substitute. +If the substitution fails, because the requested environment variable is not set, \fInothing\fR is replaced for the variable. .SH TERMINATION CODES @@ -463,22 +547,26 @@ The \fIchat\fR program will terminate with the following completion codes. .TP .B 0 -The normal termination of the program. This indicates that the script +The normal termination of the program. +This indicates that the script was executed without error to the normal conclusion. .TP .B 1 One or more of the parameters are invalid or an expect string was too -large for the internal buffers. This indicates that the program as not +large for the internal buffers. +This indicates that the program as not properly executed. .TP .B 2 -An error occurred during the execution of the program. This may be due +An error occurred during the execution of the program. +This may be due to a read or write operation failing for some reason or chat receiving a signal such as SIGINT. .TP .B 3 A timeout event occurred when there was an \fIexpect\fR string without -having a "\-subsend" string. This may mean that you did not program the +having a "\-subsend" string. +This may mean that you did not program the script correctly for the condition or that some unexpected event has occurred and the expected string could not be found. .TP @@ -499,16 +587,13 @@ The other termination codes are also strings marked as an \fIABORT\fR condition. .LP Using the termination code, it is possible to determine which event -terminated the script. It is possible to decide if the string "BUSY" -was received from the modem as opposed to "NO DIAL TONE". While the +terminated the script. +It is possible to decide if the string "BUSY" +was received from the modem as opposed to "NO DIAL TONE". +While the first event may be retried, the second will probably have little chance of succeeding during a retry. -.SH SEE ALSO -Additional information about \fIchat\fR scripts may be found with UUCP -documentation. The \fIchat\fR script was taken from the ideas proposed -by the scripts used by the \fIuucico\fR program. -.LP -uucico(1), uucp(1) .SH COPYRIGHT -The \fIchat\fR program is in public domain. This is not the GNU public -license. If it breaks then you get to keep both pieces. +The \fIchat\fR program is in public domain. +This is not the GNU public license. +If it breaks then you get to keep both pieces. diff --git a/external/bsd/ppp/dist/chat/chat.c b/external/bsd/ppp/dist/chat/chat.c index 64f01584c627..5d06061eaf8d 100644 --- a/external/bsd/ppp/dist/chat/chat.c +++ b/external/bsd/ppp/dist/chat/chat.c @@ -85,10 +85,14 @@ #ifndef __STDC__ #define const #endif - +#include +#if 0 #ifndef lint static const char rcsid[] = "Id: chat.c,v 1.30 2004/01/17 05:47:55 carlsonj Exp "; #endif +#else +__RCSID("$NetBSD: chat.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); +#endif #include #include @@ -147,20 +151,9 @@ extern char *sys_errlist[]; "unknown error") #endif -/*************** Micro getopt() *********************************************/ -#define OPTION(c,v) (_O&2&&**v?*(*v)++:!c||_O&4?0:(!(_O&1)&& \ - (--c,++v),_O=4,c&&**v=='-'&&v[0][1]?*++*v=='-'\ - &&!v[0][1]?(--c,++v,0):(_O=2,*(*v)++):0)) -#define OPTARG(c,v) (_O&2?**v||(++v,--c)?(_O=1,--c,*v++): \ - (_O=4,(char*)0):(char*)0) -#define OPTONLYARG(c,v) (_O&2&&**v?(_O=1,--c,*v++):(char*)0) -#define ARG(c,v) (c?(--c,*v++):(char*)0) - -static int _O = 0; /* Internal state */ -/*************** Micro getopt() *********************************************/ - char *program_name; +#define BUFFER_SIZE 256 #define MAX_ABORTS 50 #define MAX_REPORTS 50 #define DEFAULT_CHAT_TIMEOUT 45 @@ -198,12 +191,12 @@ struct termios saved_tty_parameters; #endif char *abort_string[MAX_ABORTS], *fail_reason = (char *)0, - fail_buffer[50]; + fail_buffer[BUFFER_SIZE]; int n_aborts = 0, abort_next = 0, timeout_next = 0, echo_next = 0; int clear_abort_next = 0; char *report_string[MAX_REPORTS] ; -char report_buffer[256] ; +char report_buffer[BUFFER_SIZE] ; int n_reports = 0, report_next = 0, report_gathering = 0 ; int clear_report_next = 0; @@ -226,15 +219,15 @@ void echo_stderr __P((int)); void break_sequence __P((void)); void terminate __P((int status)); void do_file __P((char *chat_file)); -int get_string __P((register char *string)); -int put_string __P((register char *s)); +int get_string __P((char *string)); +int put_string __P((char *s)); int write_char __P((int c)); int put_char __P((int c)); int get_char __P((void)); -void chat_send __P((register char *s)); +void chat_send __P((char *s)); char *character __P((int c)); -void chat_expect __P((register char *s)); -char *clean __P((register char *s, int sending)); +void chat_expect __P((char *s)); +char *clean __P((char *s, int sending)); void break_sequence __P((void)); void terminate __P((int status)); void pack_array __P((char **array, int end)); @@ -289,12 +282,12 @@ main(argc, argv) char **argv; { int option; - char *arg; + int i; program_name = *argv; tzset(); - while ((option = OPTION(argc, argv)) != 0) { + while ((option = getopt(argc, argv, ":eEvVf:t:r:sST:U:")) != -1) { switch (option) { case 'e': ++echo; @@ -321,25 +314,24 @@ main(argc, argv) break; case 'f': - if ((arg = OPTARG(argc, argv)) != NULL) - chat_file = copy_of(arg); + if (optarg != NULL) + chat_file = copy_of(optarg); else usage(); break; case 't': - if ((arg = OPTARG(argc, argv)) != NULL) - timeout = atoi(arg); + if (optarg != NULL) + timeout = atoi(optarg); else usage(); break; case 'r': - arg = OPTARG (argc, argv); - if (arg) { + if (optarg) { if (report_fp != NULL) fclose (report_fp); - report_file = copy_of (arg); + report_file = copy_of (optarg); report_fp = fopen (report_file, "a"); if (report_fp != NULL) { if (verbose) @@ -351,15 +343,15 @@ main(argc, argv) break; case 'T': - if ((arg = OPTARG(argc, argv)) != NULL) - phone_num = copy_of(arg); + if (optarg != NULL) + phone_num = copy_of(optarg); else usage(); break; case 'U': - if ((arg = OPTARG(argc, argv)) != NULL) - phone_num2 = copy_of(arg); + if (optarg != NULL) + phone_num2 = copy_of(optarg); else usage(); break; @@ -369,6 +361,8 @@ main(argc, argv) break; } } + argc -= optind; + argv += optind; /* * Default the report file to the stderr location */ @@ -391,17 +385,15 @@ main(argc, argv) init(); if (chat_file != NULL) { - arg = ARG(argc, argv); - if (arg != NULL) + if (argc) usage(); else do_file (chat_file); } else { - while ((arg = ARG(argc, argv)) != NULL) { - chat_expect(arg); - - if ((arg = ARG(argc, argv)) != NULL) - chat_send(arg); + for (i = 0; i < argc; i++) { + chat_expect(argv[i]); + if (++i < argc) + chat_send(argv[i]); } } @@ -508,6 +500,7 @@ void msgf __V((const char *fmt, ...)) #endif vfmtmsg(line, sizeof(line), fmt, args); + va_end(args); if (to_log) syslog(LOG_INFO, "%s", line); if (to_stderr) @@ -533,6 +526,7 @@ void fatal __V((int code, const char *fmt, ...)) #endif vfmtmsg(line, sizeof(line), fmt, args); + va_end(args); if (to_log) syslog(LOG_ERR, "%s", line); if (to_stderr) @@ -614,7 +608,7 @@ void set_tty_parameters() have_tty_parameters = 1; t.c_iflag |= IGNBRK | ISTRIP | IGNPAR; - t.c_oflag = 0; + t.c_oflag |= OPOST | ONLCR; t.c_lflag = 0; t.c_cc[VERASE] = t.c_cc[VKILL] = 0; @@ -649,7 +643,7 @@ int status; int c, rep_len; rep_len = strlen(report_buffer); - while (rep_len + 1 <= sizeof(report_buffer)) { + while (rep_len < sizeof(report_buffer) - 1) { alarm(1); c = get_char(); alarm(0); @@ -682,7 +676,7 @@ int status; * 'Clean up' this string. */ char *clean(s, sending) -register char *s; +char *s; int sending; /* set to 1 when sending (putting) this string. */ { char cur_chr; @@ -1022,11 +1016,11 @@ int c; c &= 0x7F; if (c < 32) - sprintf(string, "%s^%c", meta, (int)c + '@'); + snprintf(string, sizeof(string), "%s^%c", meta, (int)c + '@'); else if (c == 127) - sprintf(string, "%s^?", meta); + snprintf(string, sizeof(string), "%s^?", meta); else - sprintf(string, "%s%c", meta, c); + snprintf(string, sizeof(string), "%s%c", meta, c); return (string); } @@ -1035,7 +1029,7 @@ int c; * process the reply string */ void chat_send (s) -register char *s; +char *s; { char file_data[STR_LEN]; @@ -1297,10 +1291,11 @@ int c; } int put_string (s) -register char *s; +char *s; { + char *ss; quiet = 0; - s = clean(s, 1); + s = ss = clean(s, 1); if (verbose) { if (quiet) @@ -1312,11 +1307,13 @@ register char *s; alarm(timeout); alarmed = 0; while (*s) { - register char c = *s++; + char c = *s++; if (c != '\\') { - if (!write_char (c)) + if (!write_char (c)) { + free(ss); return 0; + } continue; } @@ -1335,14 +1332,17 @@ register char *s; break; default: - if (!write_char (c)) + if (!write_char (c)) { + free(ss); return 0; + } break; } } alarm(0); alarmed = 0; + free(ss); return (1); } @@ -1380,11 +1380,11 @@ int n; * 'Wait for' this string to appear on this file descriptor. */ int get_string(string) -register char *string; +char *string; { char temp[STR_LEN]; - int c, printed = 0, len, minlen; - register char *s = temp, *end = s + STR_LEN; + int c, len, minlen; + char *s = temp, *end = s + STR_LEN; char *logged = temp; fail_reason = (char *)0; @@ -1398,12 +1398,14 @@ register char *string; if (len > STR_LEN) { msgf("expect string is too long"); exit_code = 1; + free(string); return 0; } if (len == 0) { if (verbose) msgf("got it"); + free(string); return (1); } @@ -1447,6 +1449,8 @@ register char *string; strftime (report_buffer, 20, "%b %d %H:%M:%S ", tm_now); strcat (report_buffer, report_string[n]); + strlcat(report_buffer, report_string[n], + sizeof(report_buffer)); report_string[n] = (char *) NULL; report_gathering = 1; @@ -1477,6 +1481,7 @@ register char *string; alarm(0); alarmed = 0; + free(string); return (1); } @@ -1492,7 +1497,9 @@ register char *string; alarm(0); alarmed = 0; exit_code = n + 4; - strcpy(fail_reason = fail_buffer, abort_string[n]); + strlcpy(fail_buffer, abort_string[n], sizeof(fail_buffer)); + fail_reason = fail_buffer; + free(string); return (0); } } @@ -1514,16 +1521,10 @@ register char *string; } alarm(0); - - if (verbose && printed) { - if (alarmed) - msgf(" -- read timed out"); - else - msgf(" -- read failed: %m"); - } exit_code = 3; alarmed = 0; + free(string); return (0); } diff --git a/external/bsd/ppp/dist/pppd/auth.c b/external/bsd/ppp/dist/pppd/auth.c index 13eb67026409..f5ffc42b00db 100644 --- a/external/bsd/ppp/dist/pppd/auth.c +++ b/external/bsd/ppp/dist/pppd/auth.c @@ -1,3 +1,5 @@ +/* $NetBSD: auth.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * auth.c - PPP authentication and phase control. * @@ -68,7 +70,13 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include +#if 0 #define RCSID "Id: auth.c,v 1.117 2008/07/01 12:27:56 paulus Exp " +static const char rcsid[] = RCSID; +#else +__RCSID("$NetBSD: auth.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); +#endif #include #include @@ -81,7 +89,6 @@ #include #include #include -#include #include #if defined(_PATH_LASTLOG) && defined(__linux__) #include @@ -115,7 +122,6 @@ #include "pathnames.h" #include "session.h" -static const char rcsid[] = RCSID; /* Bits in scan_authfile return value */ #define NONWILD_SERVER 1 @@ -415,34 +421,37 @@ setupapfile(argv) int l; uid_t euid; char u[MAXNAMELEN], p[MAXSECRETLEN]; - char *fname; lcp_allowoptions[0].neg_upap = 1; + if (*argv == NULL) + novm("+ua file name"); + + if (uafname != NULL) + free(uafname); /* open user info file */ - fname = strdup(*argv); - if (fname == NULL) + uafname = strdup(*argv); + if (uafname == NULL) novm("+ua file name"); euid = geteuid(); if (seteuid(getuid()) == -1) { - option_error("unable to reset uid before opening %s: %m", fname); + option_error("unable to reset uid before opening %s: %m", uafname); return 0; } - ufile = fopen(fname, "r"); + ufile = fopen(uafname, "r"); if (seteuid(euid) == -1) fatal("unable to regain privileges: %m"); if (ufile == NULL) { - option_error("unable to open user login data file %s", fname); + option_error("unable to open user login data file %s", uafname); return 0; } - check_access(ufile, fname); - uafname = fname; + check_access(ufile, uafname); /* get username */ if (fgets(u, MAXNAMELEN - 1, ufile) == NULL || fgets(p, MAXSECRETLEN - 1, ufile) == NULL) { fclose(ufile); - option_error("unable to read user login data file %s", fname); + option_error("unable to read user login data file %s", uafname); return 0; } fclose(ufile); @@ -455,11 +464,11 @@ setupapfile(argv) if (l > 0 && p[l-1] == '\n') p[l-1] = 0; - if (override_value("user", option_priority, fname)) { + if (override_value("user", option_priority, uafname)) { strlcpy(user, u, sizeof(user)); explicit_user = 1; } - if (override_value("passwd", option_priority, fname)) { + if (override_value("passwd", option_priority, uafname)) { strlcpy(passwd, p, sizeof(passwd)); explicit_passwd = 1; } @@ -871,7 +880,8 @@ start_networks(unit) #ifdef PPP_FILTER if (!demand) - set_filters(&pass_filter, &active_filter); + set_filters(&pass_filter_in, &pass_filter_out, + &active_filter_in, &active_filter_out); #endif /* Start CCP and ECP */ for (i = 0; (protp = protocols[i]) != NULL; ++i) @@ -2223,14 +2233,15 @@ scan_authfile(f, client, server, secret, addrs, opts, filename, flags) */ app = &alist; for (;;) { + size_t len; if (!getword(f, word, &newline, filename) || newline) break; - ap = (struct wordlist *) - malloc(sizeof(struct wordlist) + strlen(word) + 1); + len = strlen(word) + 1; + ap = (struct wordlist *)malloc(sizeof(struct wordlist) + len); if (ap == NULL) novm("authorized addresses"); ap->word = (char *) (ap + 1); - strcpy(ap->word, word); + memcpy(ap->word, word, len); *app = ap; app = &ap->next; } diff --git a/external/bsd/ppp/dist/pppd/cbcp.c b/external/bsd/ppp/dist/pppd/cbcp.c index d83397a813d5..6f3bd76ac39f 100644 --- a/external/bsd/ppp/dist/pppd/cbcp.c +++ b/external/bsd/ppp/dist/pppd/cbcp.c @@ -1,3 +1,5 @@ +/* $NetBSD: cbcp.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * cbcp - Call Back Configuration Protocol. * @@ -33,7 +35,13 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include +#if 0 #define RCSID "Id: cbcp.c,v 1.17 2006/05/22 00:04:07 paulus Exp " +static const char rcsid[] = RCSID; +#else +__RCSID("$NetBSD: cbcp.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); +#endif #include #include @@ -45,8 +53,6 @@ #include "fsm.h" #include "lcp.h" -static const char rcsid[] = RCSID; - /* * Options. */ @@ -166,7 +172,7 @@ cbcp_input(unit, inpacket, pktlen) if (pktlen < CBCP_MINLEN) { if (debug) - dbglog("CBCP packet is too small"); + dbglog("CBCP: Packet too short (%d)", pktlen); return; } @@ -176,7 +182,7 @@ cbcp_input(unit, inpacket, pktlen) if (len > pktlen || len < CBCP_MINLEN) { if (debug) - dbglog("CBCP packet: invalid length %d", len); + dbglog("CBCP: Invalid packet length (%d/%d)", len, pktlen); return; } @@ -280,6 +286,7 @@ cbcp_printpkt(p, plen, printer, arg) char str[256]; GETCHAR(addrt, p); + __USE(addrt); memcpy(str, p, olen - 4); str[olen - 4] = 0; printer(arg, " number = %s", str); @@ -318,11 +325,16 @@ cbcp_recvreq(us, pckt, pcktlen) GETCHAR(type, pckt); GETCHAR(opt_len, pckt); - if (opt_len < 2 || opt_len > len) + if (opt_len < 2 || opt_len > len) { + if (debug) + dbglog("CBCP: Malformed option length (%d/%d)", opt_len, len); break; + } - if (opt_len > 2) + if (opt_len > 2) { GETCHAR(delay, pckt); + __USE(delay); + } us->us_allowed |= (1 << type); @@ -335,6 +347,7 @@ cbcp_recvreq(us, pckt, pcktlen) dbglog("user callback allowed"); if (opt_len > 4) { GETCHAR(addr_type, pckt); + __USE(addr_type); memcpy(address, pckt, opt_len - 4); address[opt_len - 4] = 0; if (address[0]) @@ -457,11 +470,14 @@ cbcp_recvack(us, pckt, len) GETCHAR(opt_len, pckt); if (opt_len >= 2 && opt_len <= len) { - if (opt_len > 2) + if (opt_len > 2) { GETCHAR(delay, pckt); + __USE(delay); + } if (opt_len > 4) { GETCHAR(addr_type, pckt); + __USE(addr_type); memcpy(address, pckt, opt_len - 4); address[opt_len - 4] = 0; if (address[0]) diff --git a/external/bsd/ppp/dist/pppd/cbcp.h b/external/bsd/ppp/dist/pppd/cbcp.h index c2ab3f68991f..ff226d7f0904 100644 --- a/external/bsd/ppp/dist/pppd/cbcp.h +++ b/external/bsd/ppp/dist/pppd/cbcp.h @@ -1,3 +1,5 @@ +/* $NetBSD: cbcp.h,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + #ifndef CBCP_H #define CBCP_H diff --git a/external/bsd/ppp/dist/pppd/ccp.c b/external/bsd/ppp/dist/pppd/ccp.c index f54e89d544a4..b7f56db87945 100644 --- a/external/bsd/ppp/dist/pppd/ccp.c +++ b/external/bsd/ppp/dist/pppd/ccp.c @@ -1,3 +1,5 @@ +/* $NetBSD: ccp.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * ccp.c - PPP Compression Control Protocol. * @@ -28,7 +30,13 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include +#if 0 #define RCSID "Id: ccp.c,v 1.50 2005/06/26 19:34:41 carlsonj Exp " +static const char rcsid[] = RCSID; +#else +__RCSID("$NetBSD: ccp.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); +#endif #include #include @@ -43,8 +51,6 @@ #include "lcp.h" /* lcp_close(), lcp_fsm */ #endif -static const char rcsid[] = RCSID; - /* * Unfortunately there is a bug in zlib which means that using a * size of 8 (window size = 256) for Deflate compression will cause diff --git a/external/bsd/ppp/dist/pppd/ccp.h b/external/bsd/ppp/dist/pppd/ccp.h index 8d23af5d1eed..5173f35e2a23 100644 --- a/external/bsd/ppp/dist/pppd/ccp.h +++ b/external/bsd/ppp/dist/pppd/ccp.h @@ -1,3 +1,5 @@ +/* $NetBSD: ccp.h,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * ccp.h - Definitions for PPP Compression Control Protocol. * @@ -37,7 +39,7 @@ typedef struct ccp_options { bool predictor_2; /* do Predictor-2? */ bool deflate_correct; /* use correct code for deflate? */ bool deflate_draft; /* use draft RFC code for deflate? */ - bool mppe; /* do MPPE? */ + u_short mppe; /* do MPPE? */ u_short bsd_bits; /* # bits/code for BSD Compress */ u_short deflate_size; /* lg(window size) for Deflate */ short method; /* code for chosen compression method */ diff --git a/external/bsd/ppp/dist/pppd/chap-md5.c b/external/bsd/ppp/dist/pppd/chap-md5.c index 206707f51589..4b7290aaebef 100644 --- a/external/bsd/ppp/dist/pppd/chap-md5.c +++ b/external/bsd/ppp/dist/pppd/chap-md5.c @@ -1,3 +1,5 @@ +/* $NetBSD: chap-md5.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * chap-md5.c - New CHAP/MD5 implementation. * @@ -28,15 +30,21 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include +#if 0 #define RCSID "Id: chap-md5.c,v 1.4 2004/11/09 22:39:25 paulus Exp " +static const char rcsid[] = RCSID; +#else +__RCSID("$NetBSD: chap-md5.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); +#endif #include #include +#include #include "pppd.h" #include "chap-new.h" #include "chap-md5.h" #include "magic.h" -#include "md5.h" #define MD5_HASH_SIZE 16 #define MD5_MIN_CHALLENGE 16 @@ -68,11 +76,11 @@ chap_md5_verify_response(int id, char *name, response_len = *response++; if (response_len == MD5_HASH_SIZE) { /* Generate hash of ID, secret, challenge */ - MD5_Init(&ctx); - MD5_Update(&ctx, &idbyte, 1); - MD5_Update(&ctx, secret, secret_len); - MD5_Update(&ctx, challenge, challenge_len); - MD5_Final(hash, &ctx); + MD5Init(&ctx); + MD5Update(&ctx, &idbyte, 1); + MD5Update(&ctx, secret, secret_len); + MD5Update(&ctx, challenge, challenge_len); + MD5Final(hash, &ctx); /* Test if our hash matches the peer's response */ if (memcmp(hash, response, MD5_HASH_SIZE) == 0) { @@ -93,11 +101,11 @@ chap_md5_make_response(unsigned char *response, int id, char *our_name, unsigned char idbyte = id; int challenge_len = *challenge++; - MD5_Init(&ctx); - MD5_Update(&ctx, &idbyte, 1); - MD5_Update(&ctx, (u_char *)secret, secret_len); - MD5_Update(&ctx, challenge, challenge_len); - MD5_Final(&response[1], &ctx); + MD5Init(&ctx); + MD5Update(&ctx, &idbyte, 1); + MD5Update(&ctx, secret, secret_len); + MD5Update(&ctx, challenge, challenge_len); + MD5Final(&response[1], &ctx); response[0] = MD5_HASH_SIZE; } diff --git a/external/bsd/ppp/dist/pppd/chap-md5.h b/external/bsd/ppp/dist/pppd/chap-md5.h index 30d06588ee51..d50335df2d00 100644 --- a/external/bsd/ppp/dist/pppd/chap-md5.h +++ b/external/bsd/ppp/dist/pppd/chap-md5.h @@ -1,3 +1,5 @@ +/* $NetBSD: chap-md5.h,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * chap-md5.h - New CHAP/MD5 implementation. * diff --git a/external/bsd/ppp/dist/pppd/chap-new.c b/external/bsd/ppp/dist/pppd/chap-new.c index cd005d211f4d..c5c03966579c 100644 --- a/external/bsd/ppp/dist/pppd/chap-new.c +++ b/external/bsd/ppp/dist/pppd/chap-new.c @@ -1,3 +1,5 @@ +/* $NetBSD: chap-new.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * chap-new.c - New CHAP implementation. * @@ -28,7 +30,13 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include +#if 0 #define RCSID "Id: chap-new.c,v 1.9 2007/06/19 02:08:35 carlsonj Exp " +static const char rcsid[] = RCSID; +#else +__RCSID("$NetBSD: chap-new.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); +#endif #include #include diff --git a/external/bsd/ppp/dist/pppd/chap-new.h b/external/bsd/ppp/dist/pppd/chap-new.h index 665e78fb19a9..f2536bbaf0b5 100644 --- a/external/bsd/ppp/dist/pppd/chap-new.h +++ b/external/bsd/ppp/dist/pppd/chap-new.h @@ -1,3 +1,5 @@ +/* $NetBSD: chap-new.h,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * chap-new.c - New CHAP implementation. * diff --git a/external/bsd/ppp/dist/pppd/chap_ms.c b/external/bsd/ppp/dist/pppd/chap_ms.c index c04fa404b799..0dcdbd56275b 100644 --- a/external/bsd/ppp/dist/pppd/chap_ms.c +++ b/external/bsd/ppp/dist/pppd/chap_ms.c @@ -1,3 +1,5 @@ +/* $NetBSD: chap_ms.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * chap_ms.c - Microsoft MS-CHAP compatible implementation. * @@ -74,7 +76,13 @@ * */ +#include +#if 0 #define RCSID "Id: chap_ms.c,v 1.38 2007/12/01 20:10:51 carlsonj Exp " +static const char rcsid[] = RCSID; +#else +__RCSID("$NetBSD: chap_ms.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); +#endif #ifdef CHAPMS @@ -85,16 +93,17 @@ #include #include #include +#include +#include + +#define SHA1_SIGNATURE_SIZE SHA1_DIGEST_LENGTH #include "pppd.h" #include "chap-new.h" #include "chap_ms.h" -#include "md4.h" -#include "sha1.h" #include "pppcrypt.h" #include "magic.h" -static const char rcsid[] = RCSID; static void ascii2unicode __P((char[], int, u_char[])); @@ -545,11 +554,11 @@ ChallengeHash(u_char PeerChallenge[16], u_char *rchallenge, else user = username; - SHA1_Init(&sha1Context); - SHA1_Update(&sha1Context, PeerChallenge, 16); - SHA1_Update(&sha1Context, rchallenge, 16); - SHA1_Update(&sha1Context, (unsigned char *)user, strlen(user)); - SHA1_Final(sha1Hash, &sha1Context); + SHA1Init(&sha1Context); + SHA1Update(&sha1Context, PeerChallenge, 16); + SHA1Update(&sha1Context, rchallenge, 16); + SHA1Update(&sha1Context, (unsigned char *)user, strlen(user)); + SHA1Final(sha1Hash, &sha1Context); BCOPY(sha1Hash, Challenge, 8); } @@ -639,7 +648,7 @@ ChapMS_LANMan(u_char *rchallenge, char *secret, int secret_len, /* LANMan password is case insensitive */ BZERO(UcasePassword, sizeof(UcasePassword)); for (i = 0; i < secret_len; i++) - UcasePassword[i] = (u_char)toupper(secret[i]); + UcasePassword[i] = (u_char)toupper((unsigned char)secret[i]); (void) DesSetkey(UcasePassword + 0); DesEncrypt( StdText, PasswordHash + 0 ); (void) DesSetkey(UcasePassword + 7); @@ -675,19 +684,19 @@ GenerateAuthenticatorResponse(u_char PasswordHashHash[MD4_SIGNATURE_SIZE], u_char Digest[SHA1_SIGNATURE_SIZE]; u_char Challenge[8]; - SHA1_Init(&sha1Context); - SHA1_Update(&sha1Context, PasswordHashHash, MD4_SIGNATURE_SIZE); - SHA1_Update(&sha1Context, NTResponse, 24); - SHA1_Update(&sha1Context, Magic1, sizeof(Magic1)); - SHA1_Final(Digest, &sha1Context); + SHA1Init(&sha1Context); + SHA1Update(&sha1Context, PasswordHashHash, MD4_SIGNATURE_SIZE); + SHA1Update(&sha1Context, NTResponse, 24); + SHA1Update(&sha1Context, Magic1, sizeof(Magic1)); + SHA1Final(Digest, &sha1Context); ChallengeHash(PeerChallenge, rchallenge, username, Challenge); - SHA1_Init(&sha1Context); - SHA1_Update(&sha1Context, Digest, sizeof(Digest)); - SHA1_Update(&sha1Context, Challenge, sizeof(Challenge)); - SHA1_Update(&sha1Context, Magic2, sizeof(Magic2)); - SHA1_Final(Digest, &sha1Context); + SHA1Init(&sha1Context); + SHA1Update(&sha1Context, Digest, sizeof(Digest)); + SHA1Update(&sha1Context, Challenge, sizeof(Challenge)); + SHA1Update(&sha1Context, Magic2, sizeof(Magic2)); + SHA1Final(Digest, &sha1Context); /* Convert to ASCII hex string. */ for (i = 0; i < MAX((MS_AUTH_RESPONSE_LENGTH / 2), sizeof(Digest)); i++) @@ -728,11 +737,11 @@ mppe_set_keys(u_char *rchallenge, u_char PasswordHashHash[MD4_SIGNATURE_SIZE]) SHA1_CTX sha1Context; u_char Digest[SHA1_SIGNATURE_SIZE]; /* >= MPPE_MAX_KEY_LEN */ - SHA1_Init(&sha1Context); - SHA1_Update(&sha1Context, PasswordHashHash, MD4_SIGNATURE_SIZE); - SHA1_Update(&sha1Context, PasswordHashHash, MD4_SIGNATURE_SIZE); - SHA1_Update(&sha1Context, rchallenge, 8); - SHA1_Final(Digest, &sha1Context); + SHA1Init(&sha1Context); + SHA1Update(&sha1Context, PasswordHashHash, MD4_SIGNATURE_SIZE); + SHA1Update(&sha1Context, PasswordHashHash, MD4_SIGNATURE_SIZE); + SHA1Update(&sha1Context, rchallenge, 8); + SHA1Final(Digest, &sha1Context); /* Same key in both directions. */ BCOPY(Digest, mppe_send_key, sizeof(mppe_send_key)); @@ -815,11 +824,11 @@ mppe_set_keys2(u_char PasswordHashHash[MD4_SIGNATURE_SIZE], 0x6b, 0x65, 0x79, 0x2e }; u_char *s; - SHA1_Init(&sha1Context); - SHA1_Update(&sha1Context, PasswordHashHash, MD4_SIGNATURE_SIZE); - SHA1_Update(&sha1Context, NTResponse, 24); - SHA1_Update(&sha1Context, Magic1, sizeof(Magic1)); - SHA1_Final(MasterKey, &sha1Context); + SHA1Init(&sha1Context); + SHA1Update(&sha1Context, PasswordHashHash, MD4_SIGNATURE_SIZE); + SHA1Update(&sha1Context, NTResponse, 24); + SHA1Update(&sha1Context, Magic1, sizeof(Magic1)); + SHA1Final(MasterKey, &sha1Context); /* * generate send key @@ -828,12 +837,12 @@ mppe_set_keys2(u_char PasswordHashHash[MD4_SIGNATURE_SIZE], s = Magic3; else s = Magic2; - SHA1_Init(&sha1Context); - SHA1_Update(&sha1Context, MasterKey, 16); - SHA1_Update(&sha1Context, SHApad1, sizeof(SHApad1)); - SHA1_Update(&sha1Context, s, 84); - SHA1_Update(&sha1Context, SHApad2, sizeof(SHApad2)); - SHA1_Final(Digest, &sha1Context); + SHA1Init(&sha1Context); + SHA1Update(&sha1Context, MasterKey, 16); + SHA1Update(&sha1Context, SHApad1, sizeof(SHApad1)); + SHA1Update(&sha1Context, s, 84); + SHA1Update(&sha1Context, SHApad2, sizeof(SHApad2)); + SHA1Final(Digest, &sha1Context); BCOPY(Digest, mppe_send_key, sizeof(mppe_send_key)); @@ -844,12 +853,12 @@ mppe_set_keys2(u_char PasswordHashHash[MD4_SIGNATURE_SIZE], s = Magic2; else s = Magic3; - SHA1_Init(&sha1Context); - SHA1_Update(&sha1Context, MasterKey, 16); - SHA1_Update(&sha1Context, SHApad1, sizeof(SHApad1)); - SHA1_Update(&sha1Context, s, 84); - SHA1_Update(&sha1Context, SHApad2, sizeof(SHApad2)); - SHA1_Final(Digest, &sha1Context); + SHA1Init(&sha1Context); + SHA1Update(&sha1Context, MasterKey, 16); + SHA1Update(&sha1Context, SHApad1, sizeof(SHApad1)); + SHA1Update(&sha1Context, s, 84); + SHA1Update(&sha1Context, SHApad2, sizeof(SHApad2)); + SHA1Final(Digest, &sha1Context); BCOPY(Digest, mppe_recv_key, sizeof(mppe_recv_key)); diff --git a/external/bsd/ppp/dist/pppd/chap_ms.h b/external/bsd/ppp/dist/pppd/chap_ms.h index 4ebfaeb870ae..515b2dbe504f 100644 --- a/external/bsd/ppp/dist/pppd/chap_ms.h +++ b/external/bsd/ppp/dist/pppd/chap_ms.h @@ -1,3 +1,5 @@ +/* $NetBSD: chap_ms.h,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * chap_ms.h - Challenge Handshake Authentication Protocol definitions. * diff --git a/external/bsd/ppp/dist/pppd/demand.c b/external/bsd/ppp/dist/pppd/demand.c index 897e56cea159..e57e1620fad0 100644 --- a/external/bsd/ppp/dist/pppd/demand.c +++ b/external/bsd/ppp/dist/pppd/demand.c @@ -1,3 +1,5 @@ +/* $NetBSD: demand.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * demand.c - Support routines for demand-dialling. * @@ -28,7 +30,13 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include +#if 0 #define RCSID "Id: demand.c,v 1.20 2005/08/25 12:14:18 paulus Exp " +static const char rcsid[] = RCSID; +#else +__RCSID("$NetBSD: demand.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); +#endif #include #include @@ -44,7 +52,7 @@ #include #include #ifdef PPP_FILTER -#include +#include #endif #include "pppd.h" @@ -52,7 +60,6 @@ #include "ipcp.h" #include "lcp.h" -static const char rcsid[] = RCSID; char *frame; int framelen; @@ -100,7 +107,8 @@ demand_conf() fatal("Couldn't set up demand-dialled PPP interface: %m"); #ifdef PPP_FILTER - set_filters(&pass_filter, &active_filter); + set_filters(&pass_filter_in, &pass_filter_out, + &active_filter_in, &active_filter_out); #endif /* @@ -330,6 +338,9 @@ demand_rexmit(proto) * that is, whether it is worth bringing up the link for. */ static int +/*###340 [cc] error: static declaration of 'active_packet' follows non-static declaration%%%*/ +/*###340 [cc] error: function declaration isn't a prototype%%%*/ +/*###340 [cc] error: 'active_packet' defined but not used%%%*/ active_packet(p, len) unsigned char *p; int len; @@ -342,10 +353,10 @@ active_packet(p, len) proto = PPP_PROTOCOL(p); #ifdef PPP_FILTER p[0] = 1; /* outbound packet indicator */ - if ((pass_filter.bf_len != 0 - && bpf_filter(pass_filter.bf_insns, p, len, len) == 0) - || (active_filter.bf_len != 0 - && bpf_filter(active_filter.bf_insns, p, len, len) == 0)) { + if ((pass_filter_out.bf_len != 0 + && bpf_filter(pass_filter_out.bf_insns, p, len, len) == 0) + || (active_filter_out.bf_len != 0 + && bpf_filter(active_filter_out.bf_insns, p, len, len) == 0)) { p[0] = 0xff; return 0; } diff --git a/external/bsd/ppp/dist/pppd/eap.c b/external/bsd/ppp/dist/pppd/eap.c index 725e5c086953..428d70f6fac0 100644 --- a/external/bsd/ppp/dist/pppd/eap.c +++ b/external/bsd/ppp/dist/pppd/eap.c @@ -1,3 +1,4 @@ +/* $NetBSD: eap.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ /* * eap.c - Extensible Authentication Protocol for PPP (RFC 2284) * @@ -43,7 +44,13 @@ * Based on draft-ietf-pppext-eap-srp-03.txt. */ +#include +#if 0 #define RCSID "Id: eap.c,v 1.4 2004/11/09 22:39:25 paulus Exp " +static const char rcsid[] = RCSID; +#else +__RCSID("$NetBSD: eap.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); +#endif /* * TODO: @@ -59,10 +66,10 @@ #include #include #include +#include #include "pppd.h" #include "pathnames.h" -#include "md5.h" #include "eap.h" #ifdef USE_SRP @@ -76,7 +83,6 @@ #define SHA_DIGESTSIZE 20 #endif -static const char rcsid[] = RCSID; eap_state eap_states[NUM_PPP]; /* EAP state; one for each unit */ #ifdef USE_SRP @@ -142,6 +148,7 @@ struct protent eap_protent = { /* * A well-known 2048 bit modulus. */ +#ifdef USE_SRP static const u_char wkmodulus[] = { 0xAC, 0x6B, 0xDB, 0x41, 0x32, 0x4A, 0x9A, 0x9B, 0xF1, 0x66, 0xDE, 0x5E, 0x13, 0x89, 0x58, 0x2F, @@ -176,9 +183,25 @@ static const u_char wkmodulus[] = { 0x9B, 0x65, 0xE3, 0x72, 0xFC, 0xD6, 0x8E, 0xF2, 0x0F, 0xA7, 0x11, 0x1F, 0x9E, 0x4A, 0xFF, 0x73 }; +#endif /* Local forward declarations. */ static void eap_server_timeout __P((void *arg)); +static const char *eap_state_name __P((enum eap_state_code)); +static void eap_client_timeout __P((void *arg)); +static void eap_send_failure __P((eap_state *)); +static void eap_send_success __P((eap_state *)); +static void eap_figure_next_state __P((eap_state *, int)); +static void eap_send_request __P((eap_state *)); +static void eap_rechallenge __P((void *)); +static void srp_lwrechallenge __P((void *)); +static void eap_send_response __P((eap_state *, u_char, u_char, const u_char *, int)); +static void eap_chap_response __P((eap_state *, u_char, const u_char *, const char *, int)); +static void eap_send_nak __P((eap_state *,u_char,u_char)); +static void eap_request __P((eap_state *, u_char *, int, int)); +static void eap_response __P((eap_state *, u_char *, int, int)); +static void eap_success __P((eap_state *, u_char *, int, int)); +static void eap_failure __P((eap_state *, u_char *, int, int)); /* * Convert EAP state code to printable string for debug. @@ -1039,12 +1062,8 @@ int unit; * Format and send a regular EAP Response message. */ static void -eap_send_response(esp, id, typenum, str, lenstr) -eap_state *esp; -u_char id; -u_char typenum; -u_char *str; -int lenstr; +eap_send_response(eap_state *esp, u_char id, u_char typenum, + const u_char *str, int lenstr) { u_char *outp; int msglen; @@ -1070,12 +1089,8 @@ int lenstr; * Format and send an MD5-Challenge EAP Response message. */ static void -eap_chap_response(esp, id, hash, name, namelen) -eap_state *esp; -u_char id; -u_char *hash; -char *name; -int namelen; +eap_chap_response(eap_state *esp, u_char id, const u_char *hash, + const char *name, int namelen) { u_char *outp; int msglen; @@ -1167,10 +1182,7 @@ u_char *str; #endif /* USE_SRP */ static void -eap_send_nak(esp, id, type) -eap_state *esp; -u_char id; -u_char type; +eap_send_nak(eap_state *esp, u_char id, u_char type) { u_char *outp; int msglen; @@ -1445,13 +1457,13 @@ int len; eap_send_nak(esp, id, EAPT_SRP); break; } - MD5_Init(&mdContext); + MD5Init(&mdContext); typenum = id; - MD5_Update(&mdContext, &typenum, 1); - MD5_Update(&mdContext, (u_char *)secret, secret_len); + MD5Update(&mdContext, &typenum, 1); + MD5Update(&mdContext, secret, secret_len); BZERO(secret, sizeof (secret)); - MD5_Update(&mdContext, inp, vallen); - MD5_Final(hash, &mdContext); + MD5Update(&mdContext, inp, vallen); + MD5Final(hash, &mdContext); eap_chap_response(esp, id, hash, esp->es_client.ea_name, esp->es_client.ea_namelen); break; @@ -1871,12 +1883,12 @@ int len; eap_send_failure(esp); break; } - MD5_Init(&mdContext); - MD5_Update(&mdContext, &esp->es_server.ea_id, 1); - MD5_Update(&mdContext, (u_char *)secret, secret_len); + MD5Init(&mdContext); + MD5Update(&mdContext, &esp->es_server.ea_id, 1); + MD5Update(&mdContext, secret, secret_len); BZERO(secret, sizeof (secret)); - MD5_Update(&mdContext, esp->es_challenge, esp->es_challen); - MD5_Final(hash, &mdContext); + MD5Update(&mdContext, esp->es_challenge, esp->es_challen); + MD5Final(hash, &mdContext); if (BCMP(hash, inp, MD5_SIGNATURE_SIZE) != 0) { eap_send_failure(esp); break; diff --git a/external/bsd/ppp/dist/pppd/eap.h b/external/bsd/ppp/dist/pppd/eap.h index bf7cbbb39b25..b75d097ecaca 100644 --- a/external/bsd/ppp/dist/pppd/eap.h +++ b/external/bsd/ppp/dist/pppd/eap.h @@ -1,3 +1,5 @@ +/* $NetBSD: eap.h,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * eap.h - Extensible Authentication Protocol for PPP (RFC 2284) * diff --git a/external/bsd/ppp/dist/pppd/ecp.c b/external/bsd/ppp/dist/pppd/ecp.c index 35a62fd82bf5..c97091d6d5e4 100644 --- a/external/bsd/ppp/dist/pppd/ecp.c +++ b/external/bsd/ppp/dist/pppd/ecp.c @@ -1,3 +1,5 @@ +/* $NetBSD: ecp.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * ecp.c - PPP Encryption Control Protocol. * @@ -57,9 +59,13 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include +#if 0 #define RCSID "Id: ecp.c,v 1.4 2004/11/04 10:02:26 paulus Exp " - static const char rcsid[] = RCSID; +#else +__RCSID("$NetBSD: ecp.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); +#endif #include diff --git a/external/bsd/ppp/dist/pppd/ecp.h b/external/bsd/ppp/dist/pppd/ecp.h index 31b2515eeb1f..b797a77bdf73 100644 --- a/external/bsd/ppp/dist/pppd/ecp.h +++ b/external/bsd/ppp/dist/pppd/ecp.h @@ -1,3 +1,5 @@ +/* $NetBSD: ecp.h,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * ecp.h - Definitions for PPP Encryption Control Protocol. * diff --git a/external/bsd/ppp/dist/pppd/eui64.c b/external/bsd/ppp/dist/pppd/eui64.c index 1db25bf773a7..8cb613483371 100644 --- a/external/bsd/ppp/dist/pppd/eui64.c +++ b/external/bsd/ppp/dist/pppd/eui64.c @@ -1,3 +1,5 @@ +/* $NetBSD: eui64.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * eui64.c - EUI64 routines for IPv6CP. * @@ -35,11 +37,16 @@ * Id: eui64.c,v 1.6 2002/12/04 23:03:32 paulus Exp */ +#include +#if 0 #define RCSID "Id: eui64.c,v 1.6 2002/12/04 23:03:32 paulus Exp " +static const char rcsid[] = RCSID; +#else +__RCSID("$NetBSD: eui64.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); +#endif #include "pppd.h" -static const char rcsid[] = RCSID; /* * eui64_ntoa - Make an ascii representation of an interface identifier diff --git a/external/bsd/ppp/dist/pppd/eui64.h b/external/bsd/ppp/dist/pppd/eui64.h index 772d430ceb0a..1467fc3642d4 100644 --- a/external/bsd/ppp/dist/pppd/eui64.h +++ b/external/bsd/ppp/dist/pppd/eui64.h @@ -1,3 +1,5 @@ +/* $NetBSD: eui64.h,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * eui64.h - EUI64 routines for IPv6CP. * diff --git a/external/bsd/ppp/dist/pppd/fsm.c b/external/bsd/ppp/dist/pppd/fsm.c index bb0ff4c788be..212c29ab6a8c 100644 --- a/external/bsd/ppp/dist/pppd/fsm.c +++ b/external/bsd/ppp/dist/pppd/fsm.c @@ -1,3 +1,5 @@ +/* $NetBSD: fsm.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * fsm.c - {Link, IP} Control Protocol Finite State Machine. * @@ -40,7 +42,13 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define RCSID "Id: fsm.c,v 1.23 2004/11/13 02:28:15 paulus Exp " +#include +#if 0 +#define RCSID "Id: fsm.c,v 1.23 2004/11/13 02:28:15 paulus Exp " +static const char rcsid[] = RCSID; +#else +__RCSID("$NetBSD: fsm.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); +#endif /* * TODO: @@ -55,7 +63,6 @@ #include "pppd.h" #include "fsm.h" -static const char rcsid[] = RCSID; static void fsm_timeout __P((void *)); static void fsm_rconfreq __P((fsm *, int, u_char *, int)); @@ -65,6 +72,7 @@ static void fsm_rtermreq __P((fsm *, int, u_char *, int)); static void fsm_rtermack __P((fsm *)); static void fsm_rcoderej __P((fsm *, u_char *, int)); static void fsm_sconfreq __P((fsm *, int)); +static void terminate_layer __P((fsm *, int)); #define PROTO_NAME(f) ((f)->callbacks->proto_name) @@ -306,7 +314,7 @@ fsm_timeout(arg) case ACKRCVD: case ACKSENT: if (f->retransmits <= 0) { - warn("%s: timeout sending Config-Requests\n", PROTO_NAME(f)); + warn("%s: timeout sending Config-Requests", PROTO_NAME(f)); f->state = STOPPED; if( (f->flags & OPT_PASSIVE) == 0 && f->callbacks->finished ) (*f->callbacks->finished)(f); diff --git a/external/bsd/ppp/dist/pppd/fsm.h b/external/bsd/ppp/dist/pppd/fsm.h index bad2431596af..1ae0d3fb7169 100644 --- a/external/bsd/ppp/dist/pppd/fsm.h +++ b/external/bsd/ppp/dist/pppd/fsm.h @@ -1,3 +1,5 @@ +/* $NetBSD: fsm.h,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * fsm.h - {Link, IP} Control Protocol Finite State Machine definitions. * diff --git a/external/bsd/ppp/dist/pppd/ipcp.c b/external/bsd/ppp/dist/pppd/ipcp.c index 8deb804689bb..8245dcb77361 100644 --- a/external/bsd/ppp/dist/pppd/ipcp.c +++ b/external/bsd/ppp/dist/pppd/ipcp.c @@ -1,3 +1,5 @@ +/* $NetBSD: ipcp.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * ipcp.c - PPP IP Control Protocol. * @@ -40,7 +42,13 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include +#if 0 #define RCSID "Id: ipcp.c,v 1.73 2008/05/26 08:33:22 paulus Exp " +static const char rcsid[] = RCSID; +#else +__RCSID("$NetBSD: ipcp.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); +#endif /* * TODO: @@ -61,7 +69,6 @@ #include "ipcp.h" #include "pathnames.h" -static const char rcsid[] = RCSID; /* global vars */ ipcp_options ipcp_wantoptions[NUM_PPP]; /* Options that we want to request */ diff --git a/external/bsd/ppp/dist/pppd/ipcp.h b/external/bsd/ppp/dist/pppd/ipcp.h index 5d07279af6ec..1743da729d95 100644 --- a/external/bsd/ppp/dist/pppd/ipcp.h +++ b/external/bsd/ppp/dist/pppd/ipcp.h @@ -1,3 +1,5 @@ +/* $NetBSD: ipcp.h,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * ipcp.h - IP Control Protocol definitions. * diff --git a/external/bsd/ppp/dist/pppd/ipv6cp.c b/external/bsd/ppp/dist/pppd/ipv6cp.c index 70337b60cc20..152b11b1e5a8 100644 --- a/external/bsd/ppp/dist/pppd/ipv6cp.c +++ b/external/bsd/ppp/dist/pppd/ipv6cp.c @@ -1,3 +1,5 @@ +/* $NetBSD: ipv6cp.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * ipv6cp.c - PPP IPV6 Control Protocol. * @@ -138,7 +140,13 @@ * Id: ipv6cp.c,v 1.21 2005/08/25 23:59:34 paulus Exp */ +#include +#if 0 #define RCSID "Id: ipv6cp.c,v 1.21 2005/08/25 23:59:34 paulus Exp " +static const char rcsid[] = RCSID; +#else +__RCSID("$NetBSD: ipv6cp.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); +#endif /* * TODO: @@ -168,7 +176,7 @@ #include "magic.h" #include "pathnames.h" -static const char rcsid[] = RCSID; +#define s6_addr32 __u6_addr.__u6_addr32 /* Non-standard */ /* global vars */ ipv6cp_options ipv6cp_wantoptions[NUM_PPP]; /* Options that we want to request */ @@ -412,7 +420,7 @@ llv6_ntoa(ifaceid) { static char b[64]; - sprintf(b, "fe80::%s", eui64_ntoa(ifaceid)); + snprintf(b, sizeof(b), "fe80::%s", eui64_ntoa(ifaceid)); return b; } @@ -1424,9 +1432,10 @@ ipv6cp_script(script) char strspeed[32], strlocal[32], strremote[32]; char *argv[8]; - sprintf(strspeed, "%d", baud_rate); - strcpy(strlocal, llv6_ntoa(ipv6cp_gotoptions[0].ourid)); - strcpy(strremote, llv6_ntoa(ipv6cp_hisoptions[0].hisid)); + snprintf(strspeed, sizeof(strspeed), "%d", baud_rate); + strlcpy(strlocal, llv6_ntoa(ipv6cp_gotoptions[0].ourid), sizeof(strlocal)); + strlcpy(strremote, llv6_ntoa(ipv6cp_hisoptions[0].hisid), + sizeof(strremote)); argv[0] = script; argv[1] = ifname; diff --git a/external/bsd/ppp/dist/pppd/ipv6cp.h b/external/bsd/ppp/dist/pppd/ipv6cp.h index a4a1a5ca1deb..068a16d42bb0 100644 --- a/external/bsd/ppp/dist/pppd/ipv6cp.h +++ b/external/bsd/ppp/dist/pppd/ipv6cp.h @@ -1,3 +1,5 @@ +/* $NetBSD: ipv6cp.h,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * ipv6cp.h - PPP IPV6 Control Protocol. * diff --git a/external/bsd/ppp/dist/pppd/ipxcp.c b/external/bsd/ppp/dist/pppd/ipxcp.c index cb40bc6e7799..2c3ef14a7f3b 100644 --- a/external/bsd/ppp/dist/pppd/ipxcp.c +++ b/external/bsd/ppp/dist/pppd/ipxcp.c @@ -1,3 +1,5 @@ +/* $NetBSD: ipxcp.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * ipxcp.c - PPP IPX Control Protocol. * @@ -40,9 +42,15 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include +#if 0 +#define RCSID "Id: ipxcp.c,v 1.24 2005/08/25 23:59:34 paulus Exp " +static const char rcsid[] = RCSID; +#else +__RCSID("$NetBSD: ipxcp.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); +#endif #ifdef IPX_CHANGE -#define RCSID "Id: ipxcp.c,v 1.24 2005/08/25 23:59:34 paulus Exp " /* * TODO: @@ -62,7 +70,6 @@ #include "pathnames.h" #include "magic.h" -static const char rcsid[] = RCSID; /* global vars */ ipxcp_options ipxcp_wantoptions[NUM_PPP]; /* Options that we want to request */ diff --git a/external/bsd/ppp/dist/pppd/ipxcp.h b/external/bsd/ppp/dist/pppd/ipxcp.h index 0e22afc4cf8b..a5cc3efaa7a5 100644 --- a/external/bsd/ppp/dist/pppd/ipxcp.h +++ b/external/bsd/ppp/dist/pppd/ipxcp.h @@ -1,3 +1,5 @@ +/* $NetBSD: ipxcp.h,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * ipxcp.h - IPX Control Protocol definitions. * diff --git a/external/bsd/ppp/dist/pppd/lcp.c b/external/bsd/ppp/dist/pppd/lcp.c index 3792bfd6e967..4ced18003455 100644 --- a/external/bsd/ppp/dist/pppd/lcp.c +++ b/external/bsd/ppp/dist/pppd/lcp.c @@ -1,3 +1,5 @@ +/* $NetBSD: lcp.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * lcp.c - PPP Link Control Protocol. * @@ -40,7 +42,13 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include +#if 0 #define RCSID "Id: lcp.c,v 1.76 2006/05/22 00:04:07 paulus Exp " +static const char rcsid[] = RCSID; +#else +__RCSID("$NetBSD: lcp.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); +#endif /* * TODO: @@ -56,7 +64,6 @@ #include "chap-new.h" #include "magic.h" -static const char rcsid[] = RCSID; /* * When the link comes up we want to be able to wait for a short while, diff --git a/external/bsd/ppp/dist/pppd/lcp.h b/external/bsd/ppp/dist/pppd/lcp.h index f20de7e59f72..35531a29920f 100644 --- a/external/bsd/ppp/dist/pppd/lcp.h +++ b/external/bsd/ppp/dist/pppd/lcp.h @@ -1,3 +1,5 @@ +/* $NetBSD: lcp.h,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * lcp.h - Link Control Protocol definitions. * diff --git a/external/bsd/ppp/dist/pppd/magic.c b/external/bsd/ppp/dist/pppd/magic.c index 0b473e2ef3ba..43b1c470663b 100644 --- a/external/bsd/ppp/dist/pppd/magic.c +++ b/external/bsd/ppp/dist/pppd/magic.c @@ -1,3 +1,5 @@ +/* $NetBSD: magic.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * magic.c - PPP Magic Number routines. * @@ -40,7 +42,13 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include +#if 0 #define RCSID "Id: magic.c,v 1.11 2003/06/11 23:56:26 paulus Exp " +static const char rcsid[] = RCSID; +#else +__RCSID("$NetBSD: magic.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); +#endif #include #include @@ -51,7 +59,6 @@ #include "pppd.h" #include "magic.h" -static const char rcsid[] = RCSID; extern long mrand48 __P((void)); extern void srand48 __P((long)); diff --git a/external/bsd/ppp/dist/pppd/magic.h b/external/bsd/ppp/dist/pppd/magic.h index 4e3db34923fb..1b552efe243a 100644 --- a/external/bsd/ppp/dist/pppd/magic.h +++ b/external/bsd/ppp/dist/pppd/magic.h @@ -1,3 +1,5 @@ +/* $NetBSD: magic.h,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * magic.h - PPP Magic Number definitions. * diff --git a/external/bsd/ppp/dist/pppd/main.c b/external/bsd/ppp/dist/pppd/main.c index 83906935aa2b..0b3e4e47ba39 100644 --- a/external/bsd/ppp/dist/pppd/main.c +++ b/external/bsd/ppp/dist/pppd/main.c @@ -1,3 +1,5 @@ +/* $NetBSD: main.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * main.c - Point-to-Point Protocol main module * @@ -66,7 +68,13 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include +#if 0 #define RCSID "Id: main.c,v 1.156 2008/06/23 11:47:18 paulus Exp " +static const char rcsid[] = RCSID; +#else +__RCSID("$NetBSD: main.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); +#endif #include #include @@ -121,7 +129,6 @@ #include "atcp.h" #endif -static const char rcsid[] = RCSID; /* interface vars */ char ifname[32]; /* Interface name */ @@ -1616,9 +1623,7 @@ safe_fork(int infd, int outfd, int errfd) } static bool -add_script_env(pos, newstring) - int pos; - char *newstring; +add_script_env(int pos, char *newstring) { if (pos + 1 >= s_env_nalloc) { int new_n = pos + 17; @@ -1636,8 +1641,7 @@ add_script_env(pos, newstring) } static void -remove_script_env(pos) - int pos; +remove_script_env(int pos) { free(script_env[pos] - 1); while ((script_env[pos] = script_env[pos + 1]) != NULL) @@ -1649,7 +1653,7 @@ remove_script_env(pos) * and update the system environment. */ static void -update_system_environment() +update_system_environment(void) { struct userenv *uep; @@ -1732,7 +1736,7 @@ device_script(program, in, out, dont_wait) * script_unsetenv() safely after this routine is run. */ static void -update_script_environment() +update_script_environment(void) { struct userenv *uep; diff --git a/external/bsd/ppp/dist/pppd/mppe.h b/external/bsd/ppp/dist/pppd/mppe.h index 5eb3b37a99d6..8c72cf979f58 100644 --- a/external/bsd/ppp/dist/pppd/mppe.h +++ b/external/bsd/ppp/dist/pppd/mppe.h @@ -1,3 +1,5 @@ +/* $NetBSD: mppe.h,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * mppe.h - Definitions for MPPE * diff --git a/external/bsd/ppp/dist/pppd/multilink.c b/external/bsd/ppp/dist/pppd/multilink.c index 135cab0b42ad..681a0c732807 100644 --- a/external/bsd/ppp/dist/pppd/multilink.c +++ b/external/bsd/ppp/dist/pppd/multilink.c @@ -1,3 +1,5 @@ +/* $NetBSD: multilink.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * multilink.c - support routines for multilink. * @@ -27,6 +29,10 @@ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ + +#include +__RCSID("$NetBSD: multilink.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); + #include #include #include @@ -573,7 +579,7 @@ str_to_epdisc(ep, str) if (*str == 0) break; if (p <= str) - for (p = str; isxdigit(*p); ++p) + for (p = str; isxdigit((unsigned char)*p); ++p) ; i = p - str; if (i == 0) diff --git a/external/bsd/ppp/dist/pppd/options.c b/external/bsd/ppp/dist/pppd/options.c index 7d9a8a00f825..05fa565170f5 100644 --- a/external/bsd/ppp/dist/pppd/options.c +++ b/external/bsd/ppp/dist/pppd/options.c @@ -1,3 +1,5 @@ +/* $NetBSD: options.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * options.c - handles option processing for PPP. * @@ -40,7 +42,13 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include +#if 0 #define RCSID "Id: options.c,v 1.102 2008/06/15 06:53:06 paulus Exp " +static const char rcsid[] = RCSID; +#else +__RCSID("$NetBSD: options.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); +#endif #include #include @@ -79,7 +87,6 @@ char *strdup __P((char *)); #endif -static const char rcsid[] = RCSID; struct option_value { struct option_value *next; @@ -133,8 +140,13 @@ extern option_t auth_options[]; extern struct stat devstat; #ifdef PPP_FILTER -struct bpf_program pass_filter;/* Filter program for packets to pass */ -struct bpf_program active_filter; /* Filter program for link-active pkts */ +/* Filter program for packets to pass */ +struct bpf_program pass_filter_in; +struct bpf_program pass_filter_out; + +/* Filter program for link-active packets */ +struct bpf_program active_filter_in; +struct bpf_program active_filter_out; #endif static option_t *curopt; /* pointer to option being processed */ @@ -162,8 +174,10 @@ static int loadplugin __P((char **)); #endif #ifdef PPP_FILTER -static int setpassfilter __P((char **)); -static int setactivefilter __P((char **)); +static int setpassfilter_in __P((char **)); +static int setpassfilter_out __P((char **)); +static int setactivefilter_in __P((char **)); +static int setactivefilter_out __P((char **)); #endif #ifdef MAXOCTETS @@ -319,11 +333,15 @@ option_t general_options[] = { #endif #ifdef PPP_FILTER - { "pass-filter", o_special, setpassfilter, - "set filter for packets to pass", OPT_PRIO }, + { "pass-filter-in", o_special, setpassfilter_in, + "set filter for packets to pass inwards", OPT_PRIO }, + { "pass-filter-out", o_special, setpassfilter_out, + "set filter for packets to pass outwards", OPT_PRIO }, - { "active-filter", o_special, setactivefilter, - "set filter for active pkts", OPT_PRIO }, + { "active-filter-in", o_special, setactivefilter_in, + "set filter for active pkts inwards", OPT_PRIO }, + { "active-filter-out", o_special, setactivefilter_out, + "set filter for active pkts outwards", OPT_PRIO }, #endif #ifdef MAXOCTETS @@ -346,7 +364,7 @@ option_t general_options[] = { #define IMPLEMENTATION "" #endif -static char *usage_string = "\ +static const char *usage_string = "\ pppd version %s\n\ Usage: %s [ options ], where options are:\n\ Communicate over the named device\n\ @@ -357,6 +375,7 @@ Usage: %s [ options ], where options are:\n\ auth Require authentication from peer\n\ connect

Invoke shell command

to set up the serial line\n\ crtscts Use hardware RTS/CTS flow control\n\ + cdtrcts Use hardware DTR/CTS flow control (if supported)\n\ defaultroute Add default route through interface\n\ file Take options from file \n\ modem Use modem control lines\n\ @@ -590,18 +609,15 @@ err: * match_option - see if this option matches an option_t structure. */ static int -match_option(name, opt, dowild) - char *name; - option_t *opt; - int dowild; +match_option(const char *name, option_t *opt, int dowild) { - int (*match) __P((char *, char **, int)); + int (*match) __P((const char *, char **, int)); if (dowild != (opt->type == o_wild)) return 0; if (!dowild) return strcmp(name, opt->name) == 0; - match = (int (*) __P((char *, char **, int))) opt->addr; + match = (int (*) __P((const char *, char **, int))) opt->addr; return (*match)(name, NULL, 0); } @@ -898,10 +914,7 @@ check_options() * print_option - print out an option and its value */ static void -print_option(opt, mainopt, printer, arg) - option_t *opt, *mainopt; - printer_func printer; - void *arg; +print_option(option_t *opt, option_t *mainopt, printer_func printer, void *arg) { int i, v; char *p; @@ -1000,10 +1013,7 @@ print_option(opt, mainopt, printer, arg) * array of options. */ static void -print_option_list(opt, printer, arg) - option_t *opt; - printer_func printer; - void *arg; +print_option_list(option_t *opt, printer_func printer, void *arg) { while (opt->name != NULL) { if (opt->priority != OPRIO_DEFAULT @@ -1249,12 +1259,12 @@ getword(f, word, newlinep, filename) break; default: - if (isoctal(c)) { + if (isoctal((unsigned char)c)) { /* * \ddd octal sequence */ value = 0; - for (n = 0; n < 3 && isoctal(c); ++n) { + for (n = 0; n < 3 && isoctal((unsigned char)c); ++n) { value = (value << 3) + (c & 07); c = getc(f); } @@ -1268,8 +1278,8 @@ getword(f, word, newlinep, filename) */ value = 0; c = getc(f); - for (n = 0; n < 2 && isxdigit(c); ++n) { - digit = toupper(c) - '0'; + for (n = 0; n < 2 && isxdigit((unsigned char)c); ++n) { + digit = toupper((unsigned char)c) - '0'; if (digit > 10) digit += '0' + 10 - 'A'; value = (value << 4) + digit; @@ -1472,18 +1482,18 @@ callfile(argv) #ifdef PPP_FILTER /* - * setpassfilter - Set the pass filter for packets + * setpassfilter_in - Set the pass filter for incoming packets */ static int -setpassfilter(argv) +setpassfilter_in(argv) char **argv; { pcap_t *pc; int ret = 1; pc = pcap_open_dead(DLT_PPP_PPPD, 65535); - if (pcap_compile(pc, &pass_filter, *argv, 1, netmask) == -1) { - option_error("error in pass-filter expression: %s\n", + if (pcap_compile(pc, &pass_filter_in, *argv, 1, netmask) == -1) { + option_error("error in pass-filter-in expression: %s\n", pcap_geterr(pc)); ret = 0; } @@ -1493,17 +1503,59 @@ setpassfilter(argv) } /* - * setactivefilter - Set the active filter for packets + * setpassfilter_out - Set the pass filter for outgoing packets */ static int -setactivefilter(argv) +setpassfilter_out(argv) char **argv; { pcap_t *pc; int ret = 1; pc = pcap_open_dead(DLT_PPP_PPPD, 65535); - if (pcap_compile(pc, &active_filter, *argv, 1, netmask) == -1) { + if (pcap_compile(pc, &pass_filter_out, *argv, 1, netmask) == -1) { + option_error("error in pass-filter-out expression: %s\n", + pcap_geterr(pc)); + ret = 0; + } + pcap_close(pc); + + return ret; +} + +/* + * setactivefilter_in - Set the active filter for incoming packets + */ +static int +setactivefilter_in(argv) + char **argv; +{ + pcap_t *pc; + int ret = 1; + + pc = pcap_open_dead(DLT_PPP_PPPD, 65535); + if (pcap_compile(pc, &active_filter_in, *argv, 1, netmask) == -1) { + option_error("error in active-filter expression: %s\n", + pcap_geterr(pc)); + ret = 0; + } + pcap_close(pc); + + return ret; +} + +/* + * setactivefilter_out - Set the active filter for outgoing packets + */ +static int +setactivefilter_out(argv) + char **argv; +{ + pcap_t *pc; + int ret = 1; + + pc = pcap_open_dead(DLT_PPP_PPPD, 65535); + if (pcap_compile(pc, &active_filter_out, *argv, 1, netmask) == -1) { option_error("error in active-filter expression: %s\n", pcap_geterr(pc)); ret = 0; diff --git a/external/bsd/ppp/dist/pppd/patchlevel.h b/external/bsd/ppp/dist/pppd/patchlevel.h index b7d6ce335e7c..c6df179248e1 100644 --- a/external/bsd/ppp/dist/pppd/patchlevel.h +++ b/external/bsd/ppp/dist/pppd/patchlevel.h @@ -1,2 +1,4 @@ +/* $NetBSD: patchlevel.h,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + #define VERSION "2.4.5" #define DATE "17 November 2009" diff --git a/external/bsd/ppp/dist/pppd/pathnames.h b/external/bsd/ppp/dist/pppd/pathnames.h index 96afb0c589a8..366b4e217b1c 100644 --- a/external/bsd/ppp/dist/pppd/pathnames.h +++ b/external/bsd/ppp/dist/pppd/pathnames.h @@ -1,3 +1,5 @@ +/* $NetBSD: pathnames.h,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * define path names * @@ -46,20 +48,15 @@ #endif /* IPX_CHANGE */ #ifdef __STDC__ -#define _PATH_PPPDB _ROOT_PATH _PATH_VARRUN "pppd2.tdb" +#define _PATH_PPPDB _ROOT_PATH _PATH_VARRUN "pppd.tdb" #else /* __STDC__ */ #ifdef HAVE_PATHS_H -#define _PATH_PPPDB "/var/run/pppd2.tdb" +#define _PATH_PPPDB "/var/run/pppd.tdb" #else -#define _PATH_PPPDB "/etc/ppp/pppd2.tdb" +#define _PATH_PPPDB "/etc/ppp/pppd.tdb" #endif #endif /* __STDC__ */ #ifdef PLUGIN -#ifdef __STDC__ -#define _PATH_PLUGIN DESTDIR "/lib/pppd/" VERSION -#else /* __STDC__ */ -#define _PATH_PLUGIN "/usr/lib/pppd" -#endif /* __STDC__ */ - +#define _PATH_PLUGIN "/usr/libexec/pppd/" #endif /* PLUGIN */ diff --git a/external/bsd/ppp/dist/pppd/pppcrypt.c b/external/bsd/ppp/dist/pppd/pppcrypt.c index 8b85b13276ab..7686ffcd9426 100644 --- a/external/bsd/ppp/dist/pppd/pppcrypt.c +++ b/external/bsd/ppp/dist/pppd/pppcrypt.c @@ -1,3 +1,5 @@ +/* $NetBSD: pppcrypt.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * pppcrypt.c - PPP/DES linkage for MS-CHAP and EAP SRP-SHA1 * @@ -30,14 +32,17 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include +__RCSID("$NetBSD: pppcrypt.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); + #include +#include +#include #include "pppd.h" #include "pppcrypt.h" static u_char -Get7Bits(input, startBit) -u_char *input; -int startBit; +Get7Bits(u_char *input, int startBit) { unsigned int word; @@ -50,9 +55,10 @@ int startBit; } static void -MakeKey(key, des_key) -u_char *key; /* IN 56 bit DES key missing parity bits */ -u_char *des_key; /* OUT 64 bit DES key with parity bits added */ +MakeKey( +u_char *key, /* IN 56 bit DES key missing parity bits */ +u_char *des_key /* OUT 64 bit DES key with parity bits added */ +) { des_key[0] = Get7Bits(key, 0); des_key[1] = Get7Bits(key, 7); @@ -75,9 +81,7 @@ u_char *des_key; /* OUT 64 bit DES key with parity bits added */ * Note that the low-order "bit" is always ignored by by setkey() */ static void -Expand(in, out) -u_char *in; -u_char *out; +Expand(u_char *in, u_char *out) { int j, c; int i; @@ -93,9 +97,7 @@ u_char *out; /* The inverse of Expand */ static void -Collapse(in, out) -u_char *in; -u_char *out; +Collapse(u_char *in, u_char *out) { int j; int i; diff --git a/external/bsd/ppp/dist/pppd/pppcrypt.h b/external/bsd/ppp/dist/pppd/pppcrypt.h index adcdcbcb68dd..b9ab525cf4f8 100644 --- a/external/bsd/ppp/dist/pppd/pppcrypt.h +++ b/external/bsd/ppp/dist/pppd/pppcrypt.h @@ -1,3 +1,5 @@ +/* $NetBSD: pppcrypt.h,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * pppcrypt.c - PPP/DES linkage for MS-CHAP and EAP SRP-SHA1 * diff --git a/external/bsd/ppp/dist/pppd/pppd.8 b/external/bsd/ppp/dist/pppd/pppd.8 index 66d9c44e1fc1..726ef7199a6a 100644 --- a/external/bsd/ppp/dist/pppd/pppd.8 +++ b/external/bsd/ppp/dist/pppd/pppd.8 @@ -1,3 +1,4 @@ +.\" $NetBSD: pppd.8,v 1.2 2013/11/28 22:33:42 christos Exp $ .\" manual page [] for pppd 2.4 .\" Id: pppd.8,v 1.90 2008/03/26 12:09:40 paulus Exp .\" SH section heading diff --git a/external/bsd/ppp/dist/pppd/pppd.h b/external/bsd/ppp/dist/pppd/pppd.h index 39505813e44a..2fd85728705d 100644 --- a/external/bsd/ppp/dist/pppd/pppd.h +++ b/external/bsd/ppp/dist/pppd/pppd.h @@ -1,3 +1,5 @@ +/* $NetBSD: pppd.h,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * pppd.h - PPP daemon global declarations. * @@ -84,8 +86,7 @@ /* * Option descriptor structure. */ - -typedef unsigned char bool; +#include enum opt_type { o_special_noarg = 0, @@ -341,8 +342,13 @@ extern int maxoctets_timeout; /* Timeout for check of octets limit */ #endif #ifdef PPP_FILTER -extern struct bpf_program pass_filter; /* Filter for pkts to pass */ -extern struct bpf_program active_filter; /* Filter for link-active pkts */ +/* Filter for packets to pass */ +extern struct bpf_program pass_filter_in; +extern struct bpf_program pass_filter_out; + +/* Filter for link-active packets */ +extern struct bpf_program active_filter_in; +extern struct bpf_program active_filter_out; #endif #ifdef MSLANMAN @@ -679,7 +685,8 @@ void logwtmp __P((const char *, const char *, const char *)); int get_host_seed __P((void)); /* Get host-dependent random number seed */ int have_route_to __P((u_int32_t)); /* Check if route to addr exists */ #ifdef PPP_FILTER -int set_filters __P((struct bpf_program *pass, struct bpf_program *active)); +int set_filters __P((struct bpf_program *, struct bpf_program *, + struct bpf_program *, struct bpf_program *)); /* Set filter programs in kernel */ #endif #ifdef IPX_CHANGE diff --git a/external/bsd/ppp/dist/pppd/session.c b/external/bsd/ppp/dist/pppd/session.c index 56385dd63874..1972e16ab889 100644 --- a/external/bsd/ppp/dist/pppd/session.c +++ b/external/bsd/ppp/dist/pppd/session.c @@ -1,3 +1,5 @@ +/* $NetBSD: session.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * session.c - PPP session control. * @@ -68,16 +70,25 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include +__RCSID("$NetBSD: session.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); + + #include #include #include #include -#include #ifdef HAS_SHADOW #include #endif #include +#ifdef SUPPORT_UTMP #include +#endif +#ifdef SUPPORT_UTMPX +#include +#endif +#include #include #include #include "pppd.h" @@ -365,7 +376,13 @@ session_start(flags, user, passwd, ttyName, msg) if (SESS_ACCT & flags) { if (strncmp(ttyName, "/dev/", 5) == 0) ttyName += 5; - logwtmp(ttyName, user, ifname); /* Add wtmp login entry */ +#ifdef SUPPORT_UTMP + logwtmp(ttyName, user, ifname); /* Add wtmp login entry */ +#endif +#ifdef SUPPORT_UTMPX + logwtmpx(ttyName, user, ifname, 0, USER_PROCESS); /* Add wtmpx login entry */ +#endif + logged_in = 1; #if defined(_PATH_LASTLOG) && !defined(USE_PAM) @@ -418,7 +435,12 @@ session_end(const char* ttyName) if (logged_in) { if (strncmp(ttyName, "/dev/", 5) == 0) ttyName += 5; +#ifdef SUPPORT_UTMP logwtmp(ttyName, "", ""); /* Wipe out utmp logout entry */ +#endif +#ifdef SUPPORT_UTMPX + logwtmpx(ttyName, "", "", 0, DEAD_PROCESS); /* Wipe out utmpx logout entry */ +#endif logged_in = 0; } } diff --git a/external/bsd/ppp/dist/pppd/session.h b/external/bsd/ppp/dist/pppd/session.h index bee8c4124eaf..3f0bb1fd3e89 100644 --- a/external/bsd/ppp/dist/pppd/session.h +++ b/external/bsd/ppp/dist/pppd/session.h @@ -1,3 +1,5 @@ +/* $NetBSD: session.h,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * session.c - PPP session control. * diff --git a/external/bsd/ppp/dist/pppd/tty.c b/external/bsd/ppp/dist/pppd/tty.c index ed8482e534c4..763a12fde106 100644 --- a/external/bsd/ppp/dist/pppd/tty.c +++ b/external/bsd/ppp/dist/pppd/tty.c @@ -1,3 +1,5 @@ +/* $NetBSD: tty.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * tty.c - code for handling serial ports in pppd. * @@ -68,7 +70,13 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include +#if 0 #define RCSID "Id: tty.c,v 1.27 2008/07/01 12:27:56 paulus Exp " +static const char rcsid[] = RCSID; +#else +__RCSID("$NetBSD: tty.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); +#endif #include #include diff --git a/external/bsd/ppp/dist/pppd/upap.c b/external/bsd/ppp/dist/pppd/upap.c index 0b293b49e99f..74df693fd3e0 100644 --- a/external/bsd/ppp/dist/pppd/upap.c +++ b/external/bsd/ppp/dist/pppd/upap.c @@ -1,3 +1,5 @@ +/* $NetBSD: upap.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * upap.c - User/Password Authentication Protocol. * @@ -40,7 +42,13 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include +#if 0 #define RCSID "Id: upap.c,v 1.30 2005/07/13 10:41:58 paulus Exp " +static const char rcsid[] = RCSID; +#else +__RCSID("$NetBSD: upap.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); +#endif /* * TODO: @@ -52,7 +60,6 @@ #include "pppd.h" #include "upap.h" -static const char rcsid[] = RCSID; static bool hide_password = 1; diff --git a/external/bsd/ppp/dist/pppd/upap.h b/external/bsd/ppp/dist/pppd/upap.h index 19bed64f9aff..d92d9ca992cc 100644 --- a/external/bsd/ppp/dist/pppd/upap.h +++ b/external/bsd/ppp/dist/pppd/upap.h @@ -1,3 +1,5 @@ +/* $NetBSD: upap.h,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * upap.h - User/Password Authentication Protocol definitions. * diff --git a/external/bsd/ppp/dist/pppd/utils.c b/external/bsd/ppp/dist/pppd/utils.c index d945bb327d1c..10fe7896f8f0 100644 --- a/external/bsd/ppp/dist/pppd/utils.c +++ b/external/bsd/ppp/dist/pppd/utils.c @@ -1,3 +1,5 @@ +/* $NetBSD: utils.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * utils.c - various utility functions used in pppd. * @@ -28,7 +30,13 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include +#if 0 #define RCSID "Id: utils.c,v 1.25 2008/06/03 12:06:37 paulus Exp " +static const char rcsid[] = RCSID; +#else +__RCSID("$NetBSD: utils.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); +#endif #include #include @@ -59,7 +67,6 @@ #include "fsm.h" #include "lcp.h" -static const char rcsid[] = RCSID; #if defined(SUNOS4) extern char *strerror(); @@ -75,45 +82,6 @@ struct buffer_info { int len; }; -/* - * strlcpy - like strcpy/strncpy, doesn't overflow destination buffer, - * always leaves destination null-terminated (for len > 0). - */ -size_t -strlcpy(dest, src, len) - char *dest; - const char *src; - size_t len; -{ - size_t ret = strlen(src); - - if (len != 0) { - if (ret < len) - strcpy(dest, src); - else { - strncpy(dest, src, len - 1); - dest[len-1] = 0; - } - } - return ret; -} - -/* - * strlcat - like strcat/strncat, doesn't overflow destination buffer, - * always leaves destination null-terminated (for len > 0). - */ -size_t -strlcat(dest, src, len) - char *dest; - const char *src; - size_t len; -{ - size_t dlen = strlen(dest); - - return dlen + strlcpy(dest + dlen, src, (len > dlen? len - dlen: 0)); -} - - /* * slprintf - format a message into a buffer. Like sprintf except we * also specify the length of the output buffer, and we handle @@ -289,8 +257,12 @@ vslprintf(buf, buflen, fmt, args) case 't': time(&t); str = ctime(&t); - str += 4; /* chop off the day name */ - str[15] = 0; /* chop off year and newline */ + if ((str = ctime(&t)) == NULL) + strlcpy(str = num, "?", sizeof(num)); + else { + str += 4; /* chop off the day name */ + str[15] = 0; /* chop off year and newline */ + } break; case 'v': /* "visible" string */ case 'q': /* quoted string */ diff --git a/external/bsd/ppp/dist/pppdump/.gitignore b/external/bsd/ppp/dist/pppdump/.gitignore deleted file mode 100644 index f122623caf08..000000000000 --- a/external/bsd/ppp/dist/pppdump/.gitignore +++ /dev/null @@ -1 +0,0 @@ -pppdump diff --git a/external/bsd/ppp/dist/pppdump/bsd-comp.c b/external/bsd/ppp/dist/pppdump/bsd-comp.c index edc297f48cf0..30aa32c2284c 100644 --- a/external/bsd/ppp/dist/pppdump/bsd-comp.c +++ b/external/bsd/ppp/dist/pppdump/bsd-comp.c @@ -1,3 +1,5 @@ +/* $NetBSD: bsd-comp.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* Because this code is derived from the 4.3BSD compress source: * * @@ -37,8 +39,11 @@ * SUCH DAMAGE. */ +#include +__RCSID("$NetBSD: bsd-comp.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); + /* - * Id: bsd-comp.c,v 1.4 2004/01/17 05:47:55 carlsonj Exp + * Id: bsd-comp.c,v 1.4 2004/01/17 05:47:55 carlsonj Exp */ #include @@ -46,6 +51,7 @@ #include #include #include +#include "pppdump.h" #include "ppp_defs.h" #include "ppp-comp.h" @@ -128,9 +134,8 @@ static void *bsd_decomp_alloc __P((u_char *options, int opt_len)); static void bsd_free __P((void *state)); static int bsd_decomp_init __P((void *state, u_char *options, int opt_len, int unit, int hdrlen, int mru, int debug)); -static void bsd_incomp __P((void *state, u_char *dmsg, int len)); -static int bsd_decompress __P((void *state, u_char *cmp, int inlen, - u_char *dmp, int *outlen)); +static void bsd_incomp __P((void *state, PACKETPTR in)); +static int bsd_decompress __P((void *state, PACKETPTR in, PACKETPTR *out)); static void bsd_reset __P((void *state)); static void bsd_comp_stats __P((void *state, struct compstat *stats)); @@ -139,6 +144,12 @@ static void bsd_comp_stats __P((void *state, struct compstat *stats)); */ struct compressor ppp_bsd_compress = { CI_BSD_COMPRESS, /* compress_proto */ + NULL, /* comp_alloc */ + NULL, /* comp_free */ + NULL, /* comp_init */ + NULL, /* comp_reset */ + NULL, /* comp_compress */ + NULL, /* comp_stat */ bsd_decomp_alloc, /* decomp_alloc */ bsd_free, /* decomp_free */ bsd_decomp_init, /* decomp_init */ @@ -170,6 +181,12 @@ struct compressor ppp_bsd_compress = { #define RATIO_SCALE (1<>RATIO_SCALE_LOG) +static void bsd_clear __P((struct bsd_db *)); +static int bsd_check __P((struct bsd_db *)); +static void *bsd_alloc __P((u_char *, int, int)); +static int bsd_init __P((struct bsd_db *, u_char *, int, int, int, int, + int, int)); + /* * clear the dictionary */ @@ -424,10 +441,9 @@ bsd_decomp_init(state, options, opt_len, unit, hdrlen, mru, debug) * incompressible data by pretending to compress the incoming data. */ static void -bsd_incomp(state, dmsg, mlen) +bsd_incomp(state, in) void *state; - u_char *dmsg; - int mlen; + PACKETPTR in; { struct bsd_db *db = (struct bsd_db *) state; u_int hshift = db->hshift; @@ -442,11 +458,11 @@ bsd_incomp(state, dmsg, mlen) u_char *rptr; u_int ent; - rptr = dmsg; + rptr = in->buf; ent = rptr[0]; /* get the protocol */ if (ent == 0) { ++rptr; - --mlen; + in->len--; ent = rptr[0]; } if ((ent & 1) == 0 || ent < 0x21 || ent > 0xf9) @@ -455,7 +471,7 @@ bsd_incomp(state, dmsg, mlen) db->seqno++; ilen = 1; /* count the protocol as 1 byte */ ++rptr; - slen = dmsg + mlen - rptr; + slen = in->buf + in->len - rptr; ilen += slen; for (; slen > 0; --slen) { c = *rptr++; @@ -544,10 +560,10 @@ bsd_incomp(state, dmsg, mlen) * compression, even though they are detected by inspecting the input. */ static int -bsd_decompress(state, cmsg, inlen, dmp, outlenp) +bsd_decompress(state, in, out) void *state; - u_char *cmsg, *dmp; - int inlen, *outlenp; + PACKETPTR in; + PACKETPTR *out; { struct bsd_db *db = (struct bsd_db *) state; u_int max_ent = db->max_ent; @@ -562,13 +578,13 @@ bsd_decompress(state, cmsg, inlen, dmp, outlenp) int ilen; int codelen, extra; - rptr = cmsg; + rptr = in->buf; if (*rptr == 0) ++rptr; ++rptr; /* skip protocol (assumed 0xfd) */ seq = (rptr[0] << 8) + rptr[1]; rptr += BSD_OVHD; - ilen = len = cmsg + inlen - rptr; + ilen = len = in->buf + in->len - rptr; /* * Check the sequence number and give up if it is not what we expect. @@ -580,7 +596,7 @@ bsd_decompress(state, cmsg, inlen, dmp, outlenp) return DECOMP_ERROR; } - wptr = dmp + db->hdrlen; + wptr = (*out)->buf + db->hdrlen; oldcode = CLEAR; explen = 0; @@ -729,7 +745,7 @@ bsd_decompress(state, cmsg, inlen, dmp, outlenp) } oldcode = incode; } - *outlenp = wptr - (dmp + db->hdrlen); + (*out)->len = wptr - ((*out)->buf + db->hdrlen); /* * Keep the checkpoint right so that incompressible packets diff --git a/external/bsd/ppp/dist/pppdump/deflate.c b/external/bsd/ppp/dist/pppdump/deflate.c index ca1c10e51275..9ea2652b6b8a 100644 --- a/external/bsd/ppp/dist/pppdump/deflate.c +++ b/external/bsd/ppp/dist/pppdump/deflate.c @@ -1,3 +1,5 @@ +/* $NetBSD: deflate.c,v 1.2 2013/11/28 22:33:42 christos Exp $ */ + /* * ppp_deflate.c - interface the zlib procedures for Deflate compression * and decompression (as used by gzip) to the PPP code. @@ -33,17 +35,20 @@ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * Id: deflate.c,v 1.5 2004/01/17 05:47:55 carlsonj Exp + * Id: deflate.c,v 1.5 2004/01/17 05:47:55 carlsonj Exp */ +#include +__RCSID("$NetBSD: deflate.c,v 1.2 2013/11/28 22:33:42 christos Exp $"); #include #include #include #include #include -#include "ppp_defs.h" -#include "ppp-comp.h" -#include "zlib.h" +#include "pppdump.h" +#include +#include +#include #if DO_DEFLATE @@ -71,9 +76,8 @@ static void *z_decomp_alloc __P((u_char *options, int opt_len)); static void z_decomp_free __P((void *state)); static int z_decomp_init __P((void *state, u_char *options, int opt_len, int unit, int hdrlen, int mru, int debug)); -static void z_incomp __P((void *state, u_char *dmsg, int len)); -static int z_decompress __P((void *state, u_char *cmp, int inlen, - u_char *dmp, int *outlenp)); +static void z_incomp __P((void *state, PACKETPTR mi)); +static int z_decompress __P((void *state, PACKETPTR mi, PACKETPTR *mo)); static void z_decomp_reset __P((void *state)); static void z_comp_stats __P((void *state, struct compstat *stats)); @@ -82,6 +86,12 @@ static void z_comp_stats __P((void *state, struct compstat *stats)); */ struct compressor ppp_deflate = { CI_DEFLATE, /* compress_proto */ + NULL, /* comp_alloc */ + NULL, /* comp_free */ + NULL, /* comp_init */ + NULL, /* comp_reset */ + NULL, /* comp_compress */ + NULL, /* comp_stat */ z_decomp_alloc, /* decomp_alloc */ z_decomp_free, /* decomp_free */ z_decomp_init, /* decomp_init */ @@ -230,17 +240,17 @@ z_decomp_reset(arg) * compression, even though they are detected by inspecting the input. */ static int -z_decompress(arg, mi, inlen, mo, outlenp) +z_decompress(arg, mi, mo) void *arg; - u_char *mi, *mo; - int inlen, *outlenp; + PACKETPTR mi; + PACKETPTR *mo; { struct deflate_state *state = (struct deflate_state *) arg; u_char *rptr, *wptr; int rlen, olen; int seq, r; - rptr = mi; + rptr = mi->buf; if (*rptr == 0) ++rptr; ++rptr; @@ -261,9 +271,9 @@ z_decompress(arg, mi, inlen, mo, outlenp) /* * Set up to call inflate. */ - wptr = mo; + wptr = (*mo)->buf; state->strm.next_in = rptr; - state->strm.avail_in = mi + inlen - rptr; + state->strm.avail_in = mi->buf + mi->len - rptr; rlen = state->strm.avail_in + PPP_HDRLEN + DEFLATE_OVHD; state->strm.next_out = wptr; state->strm.avail_out = state->mru + 2; @@ -278,7 +288,7 @@ z_decompress(arg, mi, inlen, mo, outlenp) return DECOMP_FATALERROR; } olen = state->mru + 2 - state->strm.avail_out; - *outlenp = olen; + (*mo)->len = olen; if ((wptr[0] & 1) != 0) ++olen; /* for suppressed protocol high byte */ @@ -302,10 +312,9 @@ z_decompress(arg, mi, inlen, mo, outlenp) * Incompressible data has arrived - add it to the history. */ static void -z_incomp(arg, mi, mlen) +z_incomp(arg, mi) void *arg; - u_char *mi; - int mlen; + PACKETPTR mi; { struct deflate_state *state = (struct deflate_state *) arg; u_char *rptr; @@ -314,7 +323,7 @@ z_incomp(arg, mi, mlen) /* * Check that the protocol is one we handle. */ - rptr = mi; + rptr = mi->buf; proto = rptr[0]; if ((proto & 1) == 0) proto = (proto << 8) + rptr[1]; @@ -325,7 +334,7 @@ z_incomp(arg, mi, mlen) if (rptr[0] == 0) ++rptr; - rlen = mi + mlen - rptr; + rlen = mi->buf + mi->len - rptr; state->strm.next_in = rptr; state->strm.avail_in = rlen; r = inflateIncomp(&state->strm); diff --git a/external/bsd/ppp/dist/pppdump/pppdump.c b/external/bsd/ppp/dist/pppdump/pppdump.c index 87c2e8f1ac69..1855e0ce8f74 100644 --- a/external/bsd/ppp/dist/pppdump/pppdump.c +++ b/external/bsd/ppp/dist/pppdump/pppdump.c @@ -38,6 +38,7 @@ #include #include #include +#include "pppdump.h" #include "ppp_defs.h" #include "ppp-comp.h" @@ -51,18 +52,14 @@ time_t start_time; int start_time_tenths; int tot_sent, tot_rcvd; -extern int optind; -extern char *optarg; - -void dumplog(); -void dumpppp(); -void show_time(); -void handle_ccp(); +void dumplog(FILE *); +void dumpppp(FILE *); +void show_time(FILE *, int); +struct pkt; +void handle_ccp(struct pkt *, u_char *, int); int -main(ac, av) - int ac; - char **av; +main(int ac, char **av) { int i; char *p; @@ -113,8 +110,7 @@ main(ac, av) } void -dumplog(f) - FILE *f; +dumplog(FILE *f) { int c, n, k, col; int nb, c2; @@ -253,8 +249,7 @@ struct pkt { unsigned char dbuf[8192]; void -dumpppp(f) - FILE *f; +dumpppp(FILE *f) { int c, n, k; int nb, nl, dn, proto, rv; @@ -320,7 +315,7 @@ dumpppp(f) ++r; ++r; if (endp - r > mru) - printf(" ERROR: length (%d) > MRU (%d)\n", + printf(" ERROR: length (%td) > MRU (%d)\n", endp - r, mru); if (decompress && fcs == PPP_GOODFCS) { /* See if this is a CCP or compressed packet */ @@ -340,8 +335,15 @@ dumpppp(f) && (pkt->flags & CCP_DECOMP_RUN) && pkt->state && (pkt->flags & CCP_ERR) == 0) { - rv = pkt->comp->decompress(pkt->state, r, - endp - r, d, &dn); + struct packet in, out, *outp; + in.buf = r; + in.len = endp - r; + out.buf = d; + outp = &out; + rv = pkt->comp->decompress(pkt->state, &in, + &outp); + dn = outp->len; + d = outp->buf; switch (rv) { case DECOMP_OK: p = dbuf; @@ -364,7 +366,10 @@ dumpppp(f) } } else if (pkt->state && (pkt->flags & CCP_DECOMP_RUN)) { - pkt->comp->incomp(pkt->state, r, endp - r); + struct packet in; + in.buf = r; + in.len = endp - r; + pkt->comp->incomp(pkt->state, &in); } } do { @@ -439,10 +444,7 @@ struct compressor *compressors[] = { }; void -handle_ccp(cp, dp, len) - struct pkt *cp; - u_char *dp; - int len; +handle_ccp(struct pkt *cp, u_char *dp, int len) { int clen; struct compressor **comp; @@ -496,9 +498,7 @@ handle_ccp(cp, dp, len) } void -show_time(f, c) - FILE *f; - int c; +show_time(FILE *f, int c) { time_t t; int n; diff --git a/external/bsd/ppp/dist/pppstats/.gitignore b/external/bsd/ppp/dist/pppstats/.gitignore deleted file mode 100644 index 25fd29e34216..000000000000 --- a/external/bsd/ppp/dist/pppstats/.gitignore +++ /dev/null @@ -1 +0,0 @@ -pppstats diff --git a/external/bsd/ppp/dist/pppstats/pppstats.c b/external/bsd/ppp/dist/pppstats/pppstats.c index bba5579f3088..9fcbd7b0a9c3 100644 --- a/external/bsd/ppp/dist/pppstats/pppstats.c +++ b/external/bsd/ppp/dist/pppstats/pppstats.c @@ -1,3 +1,5 @@ +/* $NetBSD: pppstats.c,v 1.2 2013/11/28 22:33:43 christos Exp $ */ + /* * print PPP statistics: * pppstats [-a|-d] [-v|-r|-z] [-c count] [-w wait] [interface] @@ -35,9 +37,14 @@ #define const #endif +#include +#if 0 #ifndef lint static const char rcsid[] = "Id: pppstats.c,v 1.29 2002/10/27 12:56:26 fcusack Exp "; #endif +#else +__RCSID("$NetBSD: pppstats.c,v 1.2 2013/11/28 22:33:43 christos Exp $"); +#endif #include #include @@ -93,6 +100,7 @@ int s; /* socket or /dev/ppp file descriptor */ int signalled; /* set if alarm goes off "early" */ char *progname; char *interface; +char *fmt; #if defined(SUNOS4) || defined(ULTRIX) || defined(NeXT) extern int optind; @@ -106,6 +114,9 @@ extern char *optarg; #if !defined(PPP_DRV_NAME) #define PPP_DRV_NAME "ppp" #endif /* !defined(PPP_DRV_NAME) */ +#if !defined(SL_DRV_NAME) +#define SL_DRV_NAME "sl" +#endif /* !defined(SL_DRV_NAME) */ static void usage __P((void)); static void catchalarm __P((int)); @@ -295,9 +306,11 @@ intpr() struct ppp_stats cur, old; struct ppp_comp_stats ccs, ocs; + memset(&ccs, 0, sizeof(ccs)); memset(&old, 0, sizeof(old)); memset(&ocs, 0, sizeof(ocs)); + interface = PPP_DRV_NAME "0"; while (1) { get_ppp_stats(&cur); if (zflag || rflag) @@ -458,6 +471,13 @@ main(argc, argv) else ++progname; + if (strncmp(progname, SL_DRV_NAME, sizeof(SL_DRV_NAME) - 1) == 0) { + interface = SL_DRV_NAME "0"; + fmt = SL_DRV_NAME "%d"; + } else { + interface = PPP_DRV_NAME "0"; + fmt = PPP_DRV_NAME "%d"; + } while ((c = getopt(argc, argv, "advrzc:w:")) != -1) { switch (c) { case 'a': @@ -506,7 +526,7 @@ main(argc, argv) if (argc > 0) interface = argv[0]; - if (sscanf(interface, PPP_DRV_NAME "%d", &unit) != 1) { + if (sscanf(interface, fmt, &unit) != 1) { fprintf(stderr, "%s: invalid interface '%s' specified\n", progname, interface); } diff --git a/external/bsd/ppp/ppp2netbsd b/external/bsd/ppp/ppp2netbsd new file mode 100755 index 000000000000..b0d9ae3b090d --- /dev/null +++ b/external/bsd/ppp/ppp2netbsd @@ -0,0 +1,70 @@ +#!/bin/sh +# +# NetBSD: ppp2netbsd,v 1.4 2008/04/30 13:10:47 martin Exp +# +# Copyright (c) 2005 The NetBSD Foundation. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +# Execute this at the top of the ppp distribution +# then import it. +# +# cvs import src/external/bsd/ppp/dist MACKERRAS PPP2_4_X + +# Stuff we don't need +UNUSED_DIRS="common contrib etc.ppp include linux modules solaris scripts" +UNUSED_DIRS="${UNUSED_DIRS} .git" +UNUSED_FILES="Changes-2.3 README.linux README.pppoe README.sol2 configure" +UNUSED_FILES="${UNUSED_FILES} pppd/md[45].* pppd/sha1.* pppd/srp-entry.*" +UNUSED_FILES="${UNUSED_FILES} pppd/sys-linux.c pppd/sys-solaris.c" +UNUSED_FILES="${UNUSED_FILES} pppdump/zlib.* pppdump/ppp-comp.h .gitignore" +UNUSED_FILES="${UNUSED_FILES} pppdump/.gitignore pppdump/bsd-comp.c" + +# Stuff we don't want +GPL_DIRS="pppd/plugins/pppoatm pppd/plugins/radius pppd/plugins/rp-pppoe" +GPL_FILES="pppd/tdb.* pppd/spinlock.* pppd/plugins/passprompt.c + pppd/plugins/winbind.c" + +if [ -z "$1" ] +then + echo "Usage: $0

" 1>&2 + exit 1 +fi +cd $1 +echo -n "Removing unwanted stuf... " +for obj in ${UNUSED_DIRS} ${GPL_DIRS} ${UNUSED_FILES} ${GPL_FILES}; do + rm -Rf ${obj} + echo -n "${obj} " +done +echo; echo + +# Remove Makefiles +echo -n "Removing Makefiles... " +find . -type f -name 'Makefile*' | while read m; do + rm -f ${m} + echo -n "${m} " +done +echo; echo + +cleantags . diff --git a/external/bsd/ppp/usr.sbin/Makefile b/external/bsd/ppp/usr.sbin/Makefile new file mode 100644 index 000000000000..8a244d3fcc1c --- /dev/null +++ b/external/bsd/ppp/usr.sbin/Makefile @@ -0,0 +1,5 @@ +# $NetBSD: Makefile,v 1.1 2013/11/28 22:33:43 christos Exp $ + +SUBDIR= chat pppd pppdump pppstats + +.include diff --git a/external/bsd/ppp/usr.sbin/Makefile.inc b/external/bsd/ppp/usr.sbin/Makefile.inc new file mode 100644 index 000000000000..8964694a555e --- /dev/null +++ b/external/bsd/ppp/usr.sbin/Makefile.inc @@ -0,0 +1,13 @@ +# $NetBSD: Makefile.inc,v 1.1 2013/11/28 22:33:43 christos Exp $ + +WARNS?= 1 # XXX -Wshadow -Wcast-qual -Wsign-compare + +USE_FORT?=yes # network client/server + +.include +DIST=${NETBSDSRCDIR}/external/bsd/ppp/dist +BINDIR=/usr/sbin + +.if defined(HAVE_GCC) || defined(HAVE_LLVM) +COPTS+= -fno-strict-aliasing +.endif diff --git a/external/bsd/ppp/usr.sbin/chat/Makefile b/external/bsd/ppp/usr.sbin/chat/Makefile new file mode 100644 index 000000000000..0defabe158e6 --- /dev/null +++ b/external/bsd/ppp/usr.sbin/chat/Makefile @@ -0,0 +1,10 @@ +# $NetBSD: Makefile,v 1.1 2013/11/28 22:33:43 christos Exp $ + +.include "../Makefile.inc" + +.PATH: ${DIST}/chat + +PROG= chat +MAN= chat.8 + +.include diff --git a/external/bsd/ppp/usr.sbin/plugins/minconn/Makefile b/external/bsd/ppp/usr.sbin/plugins/minconn/Makefile new file mode 100644 index 000000000000..4335d4a4847f --- /dev/null +++ b/external/bsd/ppp/usr.sbin/plugins/minconn/Makefile @@ -0,0 +1,16 @@ +# $NetBSD: Makefile,v 1.1 2013/11/28 22:33:43 christos Exp $ + +NOLINT= # defined + +.include + +.PATH: ${NETBSDSRCDIR}/dist/pppd/pppd/plugins + +LIB=minconn +SRCS=minconn.c +CPPFLAGS+=-I${NETBSDSRCDIR}/dist/pppd/pppd + +LIBPREFIX= +SHLIB_FULLVERSION= + +.include diff --git a/external/bsd/ppp/usr.sbin/plugins/passwordfd/Makefile b/external/bsd/ppp/usr.sbin/plugins/passwordfd/Makefile new file mode 100644 index 000000000000..581883025ad2 --- /dev/null +++ b/external/bsd/ppp/usr.sbin/plugins/passwordfd/Makefile @@ -0,0 +1,16 @@ +# $NetBSD: Makefile,v 1.1 2013/11/28 22:33:43 christos Exp $ + +NOLINT= # defined + +.include + +.PATH: ${NETBSDSRCDIR}/dist/pppd/pppd/plugins + +LIB=passwordfd +SRCS=passwordfd.c +CPPFLAGS+=-I${NETBSDSRCDIR}/dist/pppd/pppd + +LIBPREFIX= +SHLIB_FULLVERSION= + +.include diff --git a/external/bsd/ppp/usr.sbin/plugins/status/Makefile b/external/bsd/ppp/usr.sbin/plugins/status/Makefile new file mode 100644 index 000000000000..a3456d3f2e69 --- /dev/null +++ b/external/bsd/ppp/usr.sbin/plugins/status/Makefile @@ -0,0 +1,14 @@ +# $NetBSD: Makefile,v 1.1 2013/11/28 22:33:43 christos Exp $ + +NOLINT= # defined + +.include + +LIB=status +SRCS=status.c +CPPFLAGS+=-I${NETBSDSRCDIR}/dist/pppd/pppd + +LIBPREFIX= +SHLIB_FULLVERSION= + +.include diff --git a/external/bsd/ppp/usr.sbin/plugins/status/status.c b/external/bsd/ppp/usr.sbin/plugins/status/status.c new file mode 100644 index 000000000000..3bcae14ccc22 --- /dev/null +++ b/external/bsd/ppp/usr.sbin/plugins/status/status.c @@ -0,0 +1,146 @@ +/* NetBSD: status.c,v 1.3 2008/05/04 13:30:54 martin Exp */ + +/* + * status.c - pppd plugin to implement an `lcpstatus' option. + * This is intended as more of an example than perfected feature, + * but this code has been in use on my local network for a year and + * is quite useful as is (with a bit of external help, at any rate). + * + * Written January 2003 by John F. Woods, jfw@funhouse.com + */ + +/* + * Copyright (c) 2004 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by John F. Woods, jfw@funhouse.com. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include +#include +#include +#include "pppd.h" + +/* this version string will be checked against pppd's version string when + * this plugin is loaded. +*/ +char pppd_version[] = VERSION; + +/* + * Usage: to use this status plug as-is, add the lines: +plugin status +lcpstatus /var/run/ppp0.status + * to your PPP options file (or add the appropriate options to your + * pppd command line), where /var/run/ppp0.status can vary to taste. + * This plugin will then proceed to create the lcp status file and + * write one of four strings to the file based on the most recent LCP + * event: "up", "down", "?", or "!", representing LCP up, LCP down, + * LCP echo not received, and received-our-own-LCP-echo (probably + * indicating a loopback or a disconnected modem echoing back characters). + * On my system, I have a separate program which reads that file every + * second and sends a UDP broadcast packet on my ethernet with the contents + * of the file; each of the other computers on my ethernet (all Macs) have + * a tiny little program which listens for that UDP broadcast packet and + * updates a menubar status indicator; the end result is that when PPP + * shuts down, users on my LAN immediately know without having to go look + * at the modem. (Or without demanding that *I* go look at the modem...) + * + * If you want to modify this plugin, other ways you could use and display + * the data generated by the transitions would include: + * + directly broadcasting the results from inside the pppd task (rather + * than having a separate process do it) + * + store the ppp state in an SNMP database so it could be displayed with + * a standard form of client rather than a goofy little Mac OS X menubar + * widget. + */ + +static char *statusfilename = 0; +static char *laststatus = 0; +static char UP[] = "up"; +static char DOWN[] = "down"; +static char MISS[] = "?"; +static char MINE[] = "!"; + +static option_t status_options[] = { + { "lcpstatus", o_string, &statusfilename, + "Name of file to which LCP status string will be written" }, + { NULL } +}; + +/* status should be one of the canned constants above. */ +static void writestatus(char *status) +{ + FILE *statusfile; + if (status == laststatus) return; /* we knew that already */ + statusfile = fopen(statusfilename, "w"); + if (!statusfile) { + warn("can't write %s to log LCP status", statusfilename); + free(statusfilename); + statusfilename = 0; + return; + } + fprintf(statusfile, "%s\n", status); + fclose(statusfile); + laststatus = status; +} + +static void status_lcp_up(void) +{ + if (!statusfilename) return; /* not enabled */ + writestatus(UP); +} + +static void status_lcp_down(void) +{ + if (!statusfilename) return; /* not enabled */ + writestatus(DOWN); +} + +static void status_lcp_echo(int pending) +{ + if (!statusfilename) return; /* not enabled */ + if (pending == 0) + writestatus(UP); + else if (laststatus != MINE) + writestatus(MISS); +} + +static void status_lcp_echoreply(int mine) +{ + if (!statusfilename) return; /* not enabled */ + if (mine == 0) + writestatus(UP); + else + writestatus(MINE); +} + +void plugin_init(void) +{ + info("Initialize PPP status plugin."); + add_options(status_options); + lcp_up_hook = status_lcp_up; + lcp_down_hook = status_lcp_down; + lcp_echo_hook = status_lcp_echo; + lcp_echoreply_hook = status_lcp_echoreply; +} diff --git a/external/bsd/ppp/usr.sbin/pppd/Makefile b/external/bsd/ppp/usr.sbin/pppd/Makefile new file mode 100644 index 000000000000..4bf60f6714a0 --- /dev/null +++ b/external/bsd/ppp/usr.sbin/pppd/Makefile @@ -0,0 +1,42 @@ +# $NetBSD: Makefile,v 1.1 2013/11/28 22:33:43 christos Exp $ + +.include "../Makefile.inc" + +PROG= pppd +SRCS= auth.c cbcp.c ccp.c chap-md5.c chap-new.c chap_ms.c demand.c eap.c \ + ecp.c fsm.c ipcp.c ipxcp.c lcp.c magic.c main.c multilink.c \ + options.c pppcrypt.c session.c sys-bsd.c tdb.c tty.c upap.c utils.c + +PPPDDIR= ${DIST}/pppd + +.PATH: ${PPPDDIR} +MAN= pppd.8 +BINMODE=4555 +BINOWN= root + +CPPFLAGS+= -I${.CURDIR} -DHAVE_PATHS_H -DSUPPORT_UTMP -DSUPPORT_UTMPX -DPLUGIN +CPPFLAGS+= -I${PPPDDIR} -DPPP_FILTER +CPPFLAGS+= -DCBCP_SUPPORT -DUSE_CRYPT -DCHAPMS -DMSLANMAN -DMPPE +CPPFLAGS+= -DHAVE_MULTILINK -DUSE_TDB + +.if (!defined(SMALLPROG) || defined(SMALLPROG_INET6)) && (${USE_INET6} != "no") +CPPFLAGS+= -DINET6 +SRCS+= eui64.c ipv6cp.c +.endif + +.if (!defined(SMALLPROG)) && (${USE_PAM} != "no") +CPPFLAGS+= -DUSE_PAM +LDADD+=-lpam ${PAM_STATIC_LDADD} +DPADD+=${LIBPAM} ${PAM_STATIC_DPADD} +.endif + +LDADD+= -lpcap -lcrypt -lutil -Wl,--export-dynamic +DPADD+= ${LIBPCAP} ${LIBCRYPT} ${LIBUTIL} + +.for f in chap-md5 chap_ms eap +COPTS.${f}.c+= -Wno-pointer-sign +.endfor + +CWARNFLAGS.clang+= -Wno-tautological-compare + +.include diff --git a/external/bsd/ppp/usr.sbin/pppd/sys-bsd.c b/external/bsd/ppp/usr.sbin/pppd/sys-bsd.c new file mode 100644 index 000000000000..748695c0c4a8 --- /dev/null +++ b/external/bsd/ppp/usr.sbin/pppd/sys-bsd.c @@ -0,0 +1,2071 @@ +/* NetBSD: sys-bsd.c,v 1.68 2013/06/24 20:43:48 christos Exp */ + +/* + * sys-bsd.c - System-dependent procedures for setting up + * PPP interfaces on bsd-4.4-ish systems (including 386BSD, NetBSD, etc.) + * + * Copyright (c) 1984-2000 Carnegie Mellon University. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The name "Carnegie Mellon University" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For permission or any legal + * details, please contact + * Office of Technology Transfer + * Carnegie Mellon University + * 5000 Forbes Avenue + * Pittsburgh, PA 15213-3890 + * (412) 268-4387, fax: (412) 268-7395 + * tech-transfer@andrew.cmu.edu + * + * 4. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by Computing Services + * at Carnegie Mellon University (http://www.cmu.edu/computing/)." + * + * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE + * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Copyright (c) 1989-2002 Paul Mackerras. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The name(s) of the authors of this software must not be used to + * endorse or promote products derived from this software without + * prior written permission. + * + * 4. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by Paul Mackerras + * ". + * + * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#ifndef lint +#if 0 +#define RCSID "Id: sys-bsd.c,v 1.47 2000/04/13 12:04:23 paulus Exp " +#else +__RCSID("NetBSD: sys-bsd.c,v 1.68 2013/06/24 20:43:48 christos Exp "); +#endif +#endif + +/* + * TODO: + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if defined(NetBSD1_2) || defined(__NetBSD_Version__) +#include +#endif +#ifdef PPP_FILTER +#include +#endif + +#include +#include +#include +#include +#include +#include +#ifdef __KAME__ +#include +#include +#endif +#include + +#ifndef IN6_LLADDR_FROM_EUI64 +#ifdef __KAME__ +#define IN6_LLADDR_FROM_EUI64(sin6, eui64) do { \ + sin6.sin6_family = AF_INET6; \ + sin6.sin6_len = sizeof(struct sockaddr_in6); \ + sin6.sin6_addr.s6_addr[0] = 0xfe; \ + sin6.sin6_addr.s6_addr[1] = 0x80; \ + eui64_copy(eui64, sin6.sin6_addr.s6_addr[8]); \ +} while (/*CONSTCOND*/0) +#define IN6_IFINDEX(sin6, ifindex) \ + /* KAME ifindex hack */ \ + *(u_int16_t *)&sin6.sin6_addr.s6_addr[2] = htons(ifindex) +#else +#define IN6_LLADDR_FROM_EUI64(sin6, eui64) do { \ + memset(&sin6.s6_addr, 0, sizeof(struct in6_addr)); \ + sin6.s6_addr16[0] = htons(0xfe80); \ + eui64_copy(eui64, sin6.s6_addr32[2]); \ +} while (/*CONSTCOND*/0) +#endif +#endif + +#if RTM_VERSION >= 3 +#include +#if defined(NetBSD) && (NetBSD >= 199703) +#include +#else /* NetBSD 1.2D or later */ +#ifdef __FreeBSD__ +#include +#else +#include +#endif +#endif +#endif + +#include "pppd.h" +#include "fsm.h" +#include "ipcp.h" + +#ifdef RCSID +static const char rcsid[] = RCSID; +#endif + +static int initdisc = -1; /* Initial TTY discipline for ppp_fd */ +static int initfdflags = -1; /* Initial file descriptor flags for ppp_fd */ +static int ppp_fd = -1; /* fd which is set to PPP discipline */ +static int rtm_seq; + +static int restore_term; /* 1 => we've munged the terminal */ +static struct termios inittermios; /* Initial TTY termios */ +static struct winsize wsinfo; /* Initial window size info */ + +static int loop_slave = -1; +static int loop_master = -1; +static int doing_cleanup = 0; +static char loop_name[20]; + +static unsigned char inbuf[512]; /* buffer for chars read from loopback */ + +static int sock_fd; /* socket for doing interface ioctls */ +#ifdef INET6 +static int sock6_fd = -1; /* socket for doing ipv6 interface ioctls */ +#endif /* INET6 */ +static int ttyfd = -1; /* the file descriptor of the tty */ + +static fd_set in_fds; /* set of fds that wait_input waits for */ +static int max_in_fd; /* highest fd set in in_fds */ + +static int if_is_up; /* the interface is currently up */ +static u_int32_t ifaddrs[2]; /* local and remote addresses we set */ +static u_int32_t default_route_gateway; /* gateway addr for default route */ +static u_int32_t proxy_arp_addr; /* remote addr for proxy arp */ + +/* Prototypes for procedures local to this file. */ +static int get_flags(int); +static void set_flags(int, int); +static int dodefaultroute(u_int32_t, int); +static int get_ether_addr(u_int32_t, struct sockaddr_dl *); +static void restore_loop(void); /* Transfer ppp unit back to loopback */ + + +static void +set_queue_size(const char *fmt, int fd) { +#ifdef TIOCSQSIZE + int oqsize, qsize = 32768; + + /* Only for ptys */ + if (ioctl(fd, TIOCGQSIZE, &oqsize) == -1) + return; + + if (oqsize >= qsize) + return; + + if (ioctl(fd, TIOCSQSIZE, &qsize) == -1) + warn("%s: Cannot set tty queue size for %d from %d to %d", fmt, fd, + oqsize, qsize); + else + notice("%s: Changed queue size of %d from %d to %d", fmt, fd, oqsize, + qsize); +#endif +} + +/******************************************************************** + * + * Functions to read and set the flags value in the device driver + */ + +static int +get_flags(int fd) +{ + int flags; + + if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &flags) == -1) + fatal("%s: ioctl(PPPIOCGFLAGS): %m", __func__); + + SYSDEBUG((LOG_DEBUG, "get flags = %x\n", flags)); + return flags; +} + +/********************************************************************/ + +static void +set_flags(int fd, int flags) +{ + SYSDEBUG((LOG_DEBUG, "set flags = %x\n", flags)); + + if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &flags) == -1) + fatal("%s: ioctl(PPPIOCSFLAGS, %x): %m", __func__, flags, errno); +} + +/* + * sys_init - System-dependent initialization. + */ +void +sys_init(void) +{ + /* Get an internet socket for doing socket ioctl's on. */ + if ((sock_fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) + fatal("%s: Couldn't create IP socket: %m", __func__); + +#ifdef INET6 + if ((sock6_fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { + /* check it at runtime */ + sock6_fd = -1; + } +#endif + + FD_ZERO(&in_fds); + max_in_fd = 0; +} + +/* + * sys_cleanup - restore any system state we modified before exiting: + * mark the interface down, delete default route and/or proxy arp entry. + * This should call die() because it's called from die(). + */ +void +sys_cleanup(void) +{ + struct ifreq ifr; + + doing_cleanup = 1; + if (if_is_up) { + strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + if (ioctl(sock_fd, SIOCGIFFLAGS, &ifr) >= 0 + && ((ifr.ifr_flags & IFF_UP) != 0)) { + ifr.ifr_flags &= ~IFF_UP; + ioctl(sock_fd, SIOCSIFFLAGS, &ifr); + } + } + if (ifaddrs[0] != 0) + cifaddr(0, ifaddrs[0], ifaddrs[1]); + if (default_route_gateway) + cifdefaultroute(0, 0, default_route_gateway); + if (proxy_arp_addr) + cifproxyarp(0, proxy_arp_addr); + doing_cleanup = 0; +} + +/* + * sys_close - Clean up in a child process before execing. + */ +void +sys_close() +{ + if (sock_fd >= 0) + close(sock_fd); +#ifdef INET6 + if (sock6_fd >= 0) + close(sock6_fd); +#endif + if (loop_slave >= 0) + close(loop_slave); + if (loop_master >= 0) + close(loop_master); +} + +/* + * sys_check_options - check the options that the user specified + */ +int +sys_check_options(void) +{ +#ifndef CDTRCTS + if (crtscts == 2) { + warn("%s: DTR/CTS flow control is not supported on this system", + __func__); + return 0; + } +#endif + return 1; +} + +/* + * ppp_available - check whether the system has any ppp interfaces + * (in fact we check whether we can do an ioctl on ppp0). + */ +int +ppp_available(void) +{ + struct if_clonereq ifcr; + char *cp, *buf; + int idx, s; + extern char *no_ppp_msg; + + (void)memset(&ifcr, 0, sizeof(ifcr)); + + if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) + fatal("%s: socket: %m", __func__); + + if (ioctl(s, SIOCIFGCLONERS, &ifcr) == -1) + fatal("%s: ioctl(get cloners): %m", __func__); + + buf = malloc(ifcr.ifcr_total * IFNAMSIZ); + if (buf == NULL) + fatal("%s: Unable to allocate cloner name buffer: %m", __func__); + + ifcr.ifcr_count = ifcr.ifcr_total; + ifcr.ifcr_buffer = buf; + + if (ioctl(s, SIOCIFGCLONERS, &ifcr) == -1) + fatal("%s: ioctl(get cloners): %m", __func__); + (void)close(s); + + /* + * In case some disappeared in the mean time, clamp it down. + */ + if (ifcr.ifcr_count > ifcr.ifcr_total) + ifcr.ifcr_count = ifcr.ifcr_total; + + for (cp = buf, idx = 0; idx < ifcr.ifcr_count; idx++, cp += IFNAMSIZ) { + if (strcmp(cp, "ppp") == 0) + break; + } + free(buf); + +#ifdef __NetBSD__ + no_ppp_msg = "\ +This system lacks kernel support for PPP. To include PPP support\n\ +in the kernel, please read the ppp(4) manual page.\n"; +#else + no_ppp_msg = "\ +This system lacks kernel support for PPP. To include PPP support\n\ +in the kernel, please follow the steps detailed in the README.bsd\n\ +file in the ppp-2.2 distribution.\n"; +#endif + return idx != ifcr.ifcr_count; +} + +/* + * tty_establish_ppp - Turn the serial port into a ppp interface. + */ +int +tty_establish_ppp(int fd) +{ + int pppdisc = PPPDISC; + int x; + ttyfd = fd; + + if (demand) { + /* + * Demand mode - prime the old ppp device to relinquish the unit. + */ + if (ioctl(ppp_fd, PPPIOCXFERUNIT, 0) < 0) + fatal("%s: ioctl(transfer ppp unit): %m", __func__); + } + + set_queue_size(__func__, fd); + /* + * Save the old line discipline of fd, and set it to PPP. + */ + if (ioctl(fd, TIOCGETD, &initdisc) < 0) + fatal("%s: ioctl(TIOCGETD): %m", __func__); + if (ioctl(fd, TIOCSETD, &pppdisc) < 0) + fatal("%s: ioctl(TIOCSETD): %m", __func__); + + if (ioctl(fd, PPPIOCGUNIT, &x) < 0) + fatal("%s: ioctl(PPPIOCGUNIT): %m", __func__); + if (!demand) { + /* + * Find out which interface we were given. + */ + ifunit = x; + } else { + /* + * Check that we got the same unit again. + */ + if (x != ifunit) + fatal("%s: transfer_ppp failed: wanted unit %d, got %d", + __func__, ifunit, x); + x = TTYDISC; + if (ioctl(loop_slave, TIOCSETD, &x) == -1) + fatal("%s: ioctl(TIOCGETD): %m", __func__); + } + + ppp_fd = fd; + + /* + * Enable debug in the driver if requested. + */ + if (kdebugflag) { + x = get_flags(fd); + x |= (kdebugflag & 0xFF) * SC_DEBUG; + set_flags(fd, x); + } + + /* + * Set device for non-blocking reads. + */ + if ((initfdflags = fcntl(fd, F_GETFL)) == -1 + || fcntl(fd, F_SETFL, initfdflags | O_NONBLOCK) == -1) { + warn("%s: Couldn't set device to non-blocking mode: %m", __func__); + } + + return fd; +} + +/* + * restore_loop - reattach the ppp unit to the loopback. + */ +static void +restore_loop(void) +{ + int x; + + set_queue_size(__func__, loop_slave); + /* + * Transfer the ppp interface back to the loopback. + */ + if (ioctl(ppp_fd, PPPIOCXFERUNIT, 0) < 0) + fatal("%s: ioctl(transfer ppp unit): %m", __func__); + x = PPPDISC; + if (ioctl(loop_slave, TIOCSETD, &x) < 0) + fatal("%s: ioctl(TIOCSETD): %m", __func__); + + /* + * Check that we got the same unit again. + */ + if (ioctl(loop_slave, PPPIOCGUNIT, &x) < 0) + fatal("%s: ioctl(PPPIOCGUNIT): %m", __func__); + if (x != ifunit) + fatal("%s: transfer_ppp failed: wanted unit %d, got %d", __func__, + ifunit, x); + ppp_fd = loop_slave; +} + + +/* + * Determine if the PPP connection should still be present. + */ +extern int hungup; + +/* + * tty_disestablish_ppp - Restore the serial port to normal operation. + * and reconnect the ppp unit to the loopback if in demand mode. + * This shouldn't call die() because it's called from die(). + */ +void +tty_disestablish_ppp(fd) + int fd; +{ + if (!doing_cleanup && demand) + restore_loop(); + + if (!hungup || demand) { + + /* Flush the tty output buffer so that the TIOCSETD doesn't hang. */ + if (tcflush(fd, TCIOFLUSH) < 0) + if (!doing_cleanup) + warn("%s: tcflush failed: %m", __func__); + + /* Restore old line discipline. */ + if (initdisc >= 0 && ioctl(fd, TIOCSETD, &initdisc) < 0) + if (!doing_cleanup) + error("%s: ioctl(TIOCSETD): %m", __func__); + initdisc = -1; + + /* Reset non-blocking mode on fd. */ + if (initfdflags != -1 && fcntl(fd, F_SETFL, initfdflags) < 0) + if (!doing_cleanup) + warn("%s: Couldn't restore device fd flags: %m", __func__); + } + initfdflags = -1; + + if (fd == ppp_fd) + ppp_fd = -1; +} + +/* + * cfg_bundle - configure the existing bundle. + * Used in demand mode. + */ +void +cfg_bundle(int mrru, int mtru, int rssn, int tssn) +{ + abort(); +#ifdef notyet + int flags; + struct ifreq ifr; + + if (!new_style_driver) + return; + + /* set the mrru, mtu and flags */ + if (ioctl(ppp_dev_fd, PPPIOCSMRRU, &mrru) < 0) + error("%s: Couldn't set MRRU: %m", __func__); + flags = get_flags(ppp_dev_fd); + flags &= ~(SC_MP_SHORTSEQ | SC_MP_XSHORTSEQ); + flags |= (rssn? SC_MP_SHORTSEQ: 0) | (tssn? SC_MP_XSHORTSEQ: 0) + | (mrru? SC_MULTILINK: 0); + + set_flags(ppp_dev_fd, flags); + + /* connect up the channel */ + if (ioctl(ppp_fd, PPPIOCCONNECT, &ifunit) < 0) + fatal("%s: Couldn't attach to PPP unit %d: %m", __func__, ifunit); + add_fd(ppp_dev_fd); +#endif +} + +/* + * make_new_bundle - create a new PPP unit (i.e. a bundle) + * and connect our channel to it. This should only get called + * if `multilink' was set at the time establish_ppp was called. + * In demand mode this uses our existing bundle instead of making + * a new one. + */ +void +make_new_bundle(int mrru, int mtru, int rssn, int tssn) +{ + abort(); +#ifdef notyet + if (!new_style_driver) + return; + + /* make us a ppp unit */ + if (make_ppp_unit() < 0) + die(1); + + /* set the mrru, mtu and flags */ + cfg_bundle(mrru, mtru, rssn, tssn); +#endif +} + +/* + * bundle_attach - attach our link to a given PPP unit. + * We assume the unit is controlled by another pppd. + */ +int +bundle_attach(int ifnum) +{ + abort(); +#ifdef notyet + if (!new_style_driver) + return -1; + + if (ioctl(ppp_dev_fd, PPPIOCATTACH, &ifnum) < 0) { + if (errno == ENXIO) + return 0; /* doesn't still exist */ + fatal("%s: Couldn't attach to interface unit %d: %m", __func__, ifnum); + } + if (ioctl(ppp_fd, PPPIOCCONNECT, &ifnum) < 0) + fatal("%s: Couldn't connect to interface unit %d: %m", __func__, ifnum); + set_flags(ppp_dev_fd, get_flags(ppp_dev_fd) | SC_MULTILINK); + + ifunit = ifnum; +#endif + return 1; +} + +/* + * destroy_bundle - tell the driver to destroy our bundle. + */ +void destroy_bundle(void) +{ +#if notyet + if (ppp_dev_fd >= 0) { + close(ppp_dev_fd); + remove_fd(ppp_dev_fd); + ppp_dev_fd = -1; + } +#endif +} + +/* + * Check whether the link seems not to be 8-bit clean. + */ +void +clean_check(void) +{ + int x; + char *s; + + if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) == 0) { + s = NULL; + switch (~x & (SC_RCV_B7_0|SC_RCV_B7_1|SC_RCV_EVNP|SC_RCV_ODDP)) { + case SC_RCV_B7_0: + s = "bit 7 set to 1"; + break; + case SC_RCV_B7_1: + s = "bit 7 set to 0"; + break; + case SC_RCV_EVNP: + s = "odd parity"; + break; + case SC_RCV_ODDP: + s = "even parity"; + break; + } + if (s != NULL) { + struct ppp_rawin win; + char buf[4 * sizeof(win.buf) + 1]; + int i; + warn("%s: Serial link is not 8-bit clean:", __func__); + warn("%s: All received characters had %s", __func__, s); + if (ioctl(ppp_fd, PPPIOCGRAWIN, &win) == -1) { + warn("%s: ioctl(PPPIOCGRAWIN): %s", __func__, strerror(errno)); + return; + } + for (i = 0; i < sizeof(win.buf); i++) + win.buf[i] = win.buf[i] & 0x7f; + strvisx(buf, (char *)win.buf, win.count, VIS_CSTYLE); + warn("%s: Last %d characters were: %s", __func__, (int)win.count, + buf); + } + } +} + + +/* + * set_up_tty: Set up the serial port on `fd' for 8 bits, no parity, + * at the requested speed, etc. If `local' is true, set CLOCAL + * regardless of whether the modem option was specified. + * + * For *BSD, we assume that speed_t values numerically equal bits/second. + */ +void +set_up_tty(int fd, int local) +{ + struct termios tios; + + if (tcgetattr(fd, &tios) < 0) + fatal("%s: tcgetattr: %m", __func__); + + if (!restore_term) { + inittermios = tios; + ioctl(fd, TIOCGWINSZ, &wsinfo); + } + + set_queue_size(__func__, fd); + + tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB | CLOCAL); + if (crtscts > 0 && !local) { + if (crtscts == 2) { +#ifdef CDTRCTS + tios.c_cflag |= CDTRCTS; +#endif + } else + tios.c_cflag |= CRTSCTS; + } else if (crtscts < 0) { + tios.c_cflag &= ~CRTSCTS; +#ifdef CDTRCTS + tios.c_cflag &= ~CDTRCTS; +#endif + } + + tios.c_cflag |= CS8 | CREAD | HUPCL; + if (local || !modem) + tios.c_cflag |= CLOCAL; + tios.c_iflag = IGNBRK | IGNPAR; + tios.c_oflag = 0; + tios.c_lflag = 0; + tios.c_cc[VMIN] = 1; + tios.c_cc[VTIME] = 0; + + if (crtscts == -2) { + tios.c_iflag |= IXON | IXOFF; + tios.c_cc[VSTOP] = 0x13; /* DC3 = XOFF = ^S */ + tios.c_cc[VSTART] = 0x11; /* DC1 = XON = ^Q */ + } + + if (inspeed) { + cfsetospeed(&tios, inspeed); + cfsetispeed(&tios, inspeed); + } else { + inspeed = cfgetospeed(&tios); + /* + * We can't proceed if the serial port speed is 0, + * since that implies that the serial port is disabled. + */ + if (inspeed == 0) + fatal("%s: Baud rate for %s is 0; need explicit baud rate", + __func__, devnam); + } + baud_rate = inspeed; + + if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) + fatal("%s: tcsetattr: %m", __func__); + + restore_term = 1; +} + +/* + * restore_tty - restore the terminal to the saved settings. + */ +void +restore_tty(int fd) +{ + if (restore_term) { + if (!default_device) { + /* + * Turn off echoing, because otherwise we can get into + * a loop with the tty and the modem echoing to each other. + * We presume we are the sole user of this tty device, so + * when we close it, it will revert to its defaults anyway. + */ + inittermios.c_lflag &= ~(ECHO | ECHONL); + } + if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0) + if (errno != ENXIO) + warn("%s: tcsetattr: %m", __func__); + ioctl(fd, TIOCSWINSZ, &wsinfo); + restore_term = 0; + } +} + +/* + * setdtr - control the DTR line on the serial port. + * This is called from die(), so it shouldn't call die(). + */ +void +setdtr(int fd, int on) +{ + int modembits = TIOCM_DTR; + + ioctl(fd, (on? TIOCMBIS: TIOCMBIC), &modembits); +} + +#ifdef INET6 +/* + * sif6addr - Config the interface with an IPv6 link-local address + */ +int +sif6addr(int unit, eui64_t our_eui64, eui64_t his_eui64) +{ +#ifdef __KAME__ + int ifindex; + struct in6_aliasreq addreq6; + + if (sock6_fd < 0) { + fatal("%s: No IPv6 socket available", __func__); + /*NOTREACHED*/ + } + + /* actually, this part is not kame local - RFC2553 conformant */ + ifindex = if_nametoindex(ifname); + if (ifindex == 0) { + error("%s: sifaddr6: no interface %s", __func__, ifname); + return 0; + } + + memset(&addreq6, 0, sizeof(addreq6)); + strlcpy(addreq6.ifra_name, ifname, sizeof(addreq6.ifra_name)); + + /* my addr */ + IN6_LLADDR_FROM_EUI64(addreq6.ifra_addr, our_eui64); + IN6_IFINDEX(addreq6.ifra_addr, ifindex); + +#ifdef notdef + /* his addr */ + IN6_LLADDR_FROM_EUI64(addreq6.ifra_dstaddr, his_eui64); + IN6_IFINDEX(addreq6.ifra_dstaddr, ifindex); +#endif + + /* prefix mask: 72bit */ + addreq6.ifra_prefixmask.sin6_family = AF_INET6; + addreq6.ifra_prefixmask.sin6_len = sizeof(struct sockaddr_in6); + memset(&addreq6.ifra_prefixmask.sin6_addr, 0xff, + sizeof(addreq6.ifra_prefixmask.sin6_addr) - sizeof(our_eui64)); + memset((char *)&addreq6.ifra_prefixmask.sin6_addr + + sizeof(addreq6.ifra_prefixmask.sin6_addr) - sizeof(our_eui64), 0x00, + sizeof(our_eui64)); + + /* address lifetime (infty) */ + addreq6.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME; + addreq6.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME; + + if (ioctl(sock6_fd, SIOCAIFADDR_IN6, &addreq6) < 0) { + error("%s: sif6addr: ioctl(SIOCAIFADDR_IN6): %m", __func__); + return 0; + } + + return 1; +#else + struct in6_ifreq ifr6; + struct ifreq ifr; + struct in6_rtmsg rt6; + + if (sock6_fd < 0) { + fatal("%s: No IPv6 socket available", __func__); + /*NOTREACHED*/ + } + + memset(&ifr, 0, sizeof (ifr)); + strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + if (ioctl(sock6_fd, SIOCGIFINDEX, (caddr_t) &ifr) < 0) { + error("%s: sif6addr: ioctl(SIOCGIFINDEX): %m", __func__); + return 0; + } + + /* Local interface */ + memset(&ifr6, 0, sizeof(ifr6)); + IN6_LLADDR_FROM_EUI64(ifr6.ifr6_addr, our_eui64); + ifr6.ifr6_ifindex = ifindex; + ifr6.ifr6_prefixlen = 10; + + if (ioctl(sock6_fd, SIOCSIFADDR, &ifr6) < 0) { + error("%s: sif6addr: ioctl(SIOCSIFADDR): %m", __func__); + return 0; + } + + /* Route to remote host */ + memset(&rt6, 0, sizeof(rt6)); + IN6_LLADDR_FROM_EUI64(rt6.rtmsg_dst, his_eui64); + rt6.rtmsg_flags = RTF_UP; + rt6.rtmsg_dst_len = 10; + rt6.rtmsg_ifindex = ifr.ifr_ifindex; + rt6.rtmsg_metric = 1; + + if (ioctl(sock6_fd, SIOCADDRT, &rt6) < 0) { + error("%s: sif6addr: ioctl(SIOCADDRT): %m", __func__); + return 0; + } + + return 1; +#endif +} + + +/* + * cif6addr - Remove IPv6 address from interface + */ +int +cif6addr(int unit, eui64_t our_eui64, eui64_t his_eui64) +{ +#ifdef __KAME__ + int ifindex; + struct in6_ifreq delreq6; + + if (sock6_fd < 0) { + fatal("%s: No IPv6 socket available", __func__); + /*NOTREACHED*/ + } + + /* actually, this part is not kame local - RFC2553 conformant */ + ifindex = if_nametoindex(ifname); + if (ifindex == 0) { + error("%s: cifaddr6: no interface %s", __func__, ifname); + return 0; + } + + memset(&delreq6, 0, sizeof(delreq6)); + strlcpy(delreq6.ifr_name, ifname, sizeof(delreq6.ifr_name)); + + /* my addr */ + IN6_LLADDR_FROM_EUI64(delreq6.ifr_ifru.ifru_addr, our_eui64); + IN6_IFINDEX(delreq6.ifr_ifru.ifru_addr, ifindex); + + if (ioctl(sock6_fd, SIOCDIFADDR_IN6, &delreq6) < 0) { + error("%s: cif6addr: ioctl(SIOCDIFADDR_IN6): %m", __func__); + return 0; + } + + return 1; +#else + struct ifreq ifr; + struct in6_ifreq ifr6; + + if (sock6_fd < 0) { + fatal("%s: No IPv6 socket available", __func__); + /*NOTREACHED*/ + } + + memset(&ifr, 0, sizeof(ifr)); + strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + if (ioctl(sock6_fd, SIOCGIFINDEX, (caddr_t) &ifr) < 0) { + error("%s: cif6addr: ioctl(SIOCGIFINDEX): %m", __func__); + return 0; + } + + memset(&ifr6, 0, sizeof(ifr6)); + IN6_LLADDR_FROM_EUI64(ifr6.ifr6_addr, our_eui64); + ifr6.ifr6_ifindex = ifr.ifr_ifindex; + ifr6.ifr6_prefixlen = 10; + + if (ioctl(sock6_fd, SIOCDIFADDR, &ifr6) < 0) { + if (errno != EADDRNOTAVAIL) { + if (! ok_error (errno)) + error("%s: cif6addr: ioctl(SIOCDIFADDR): %m", __func__); + } + else { + warn("%s: cif6addr: ioctl(SIOCDIFADDR): No such address", __func__); + } + return (0); + } + return 1; +#endif +} +#endif /* INET6 */ + +/* + * get_pty - get a pty master/slave pair and chown the slave side + * to the uid given. Assumes slave_name points to >= 12 bytes of space. + */ +int +get_pty(int *master_fdp, int *slave_fdp, char *slave_name, int uid) +{ + struct termios tios; + + if (openpty(master_fdp, slave_fdp, slave_name, NULL, NULL) < 0) + return 0; + + set_queue_size(__func__, *master_fdp); + set_queue_size(__func__, *slave_fdp); + fchown(*slave_fdp, uid, -1); + fchmod(*slave_fdp, S_IRUSR | S_IWUSR); + if (tcgetattr(*slave_fdp, &tios) == 0) { + tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB); + tios.c_cflag |= CS8 | CREAD | CLOCAL; + tios.c_iflag = IGNPAR; + tios.c_oflag = 0; + tios.c_lflag = 0; + if (tcsetattr(*slave_fdp, TCSAFLUSH, &tios) < 0) + warn("%s: couldn't set attributes on pty: %m", __func__); + } else + warn("%s: couldn't get attributes on pty: %m", __func__); + + return 1; +} + + +/* + * open_ppp_loopback - open the device we use for getting + * packets in demand mode, and connect it to a ppp interface. + * Here we use a pty. + */ +int +open_ppp_loopback(void) +{ + int flags; + struct termios tios; + int pppdisc = PPPDISC; + + if (openpty(&loop_master, &loop_slave, loop_name, NULL, NULL) < 0) + fatal("%s: No free pty for loopback", __func__); + SYSDEBUG(("using %s for loopback", loop_name)); + + if (tcgetattr(loop_slave, &tios) == 0) { + tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB); + tios.c_cflag |= CS8 | CREAD | CLOCAL; + tios.c_iflag = IGNPAR; + tios.c_oflag = 0; + tios.c_lflag = 0; + if (tcsetattr(loop_slave, TCSAFLUSH, &tios) < 0) + warn("%s: couldn't set attributes on loopback: %m", __func__); + } + + flags = fcntl(loop_master, F_GETFL); + if (flags == -1 || fcntl(loop_master, F_SETFL, flags | O_NONBLOCK) == -1) + warn("%s: couldn't set master loopback to nonblock: %m", __func__); + + flags = fcntl(loop_slave, F_GETFL); + if (flags == -1 || fcntl(loop_slave, F_SETFL, flags | O_NONBLOCK) == -1) + warn("%s: couldn't set slave loopback to nonblock: %m", __func__); + + ppp_fd = loop_slave; + if (ioctl(ppp_fd, TIOCSETD, &pppdisc) < 0) + fatal("%s: ioctl(TIOCSETD): %m", __func__); + + /* + * Find out which interface we were given. + */ + if (ioctl(ppp_fd, PPPIOCGUNIT, &ifunit) < 0) + fatal("%s: ioctl(PPPIOCGUNIT): %m", __func__); + + /* + * Enable debug in the driver if requested. + */ + if (kdebugflag) { + flags = get_flags(ppp_fd); + flags |= (kdebugflag & 0xFF) * SC_DEBUG; + set_flags(ppp_fd, flags); + } + + return loop_master; +} + + +/* + * output - Output PPP packet. + */ +void +output(int unit, u_char *p, int len) +{ + if (debug) + dbglog("sent %P", p, len); + + if (write(ttyfd, p, len) < 0) { + if (errno != EIO) + error("%s: write: %m", __func__); + } +} + + +/* + * wait_input - wait until there is data available, + * for the length of time specified by *timo (indefinite + * if timo is NULL). + */ +void +wait_input(struct timeval *timo) +{ + fd_set ready; + int n; + + ready = in_fds; + n = select(max_in_fd + 1, &ready, NULL, &ready, timo); + if (n < 0 && errno != EINTR) + fatal("%s: select: %m", __func__); +} + + +/* + * add_fd - add an fd to the set that wait_input waits for. + */ +void add_fd(int fd) +{ + if (fd >= FD_SETSIZE) + fatal("%s: descriptor too big", __func__); + FD_SET(fd, &in_fds); + if (fd > max_in_fd) + max_in_fd = fd; +} + +/* + * remove_fd - remove an fd from the set that wait_input waits for. + */ +void remove_fd(int fd) +{ + FD_CLR(fd, &in_fds); +} + +#if 0 +/* + * wait_loop_output - wait until there is data available on the + * loopback, for the length of time specified by *timo (indefinite + * if timo is NULL). + */ +void +wait_loop_output(struct timeval *timo) +{ + fd_set ready; + int n; + + FD_ZERO(&ready); + if (loop_master >= FD_SETSIZE) + fatal("%s: descriptor too big", __func__); + FD_SET(loop_master, &ready); + n = select(loop_master + 1, &ready, NULL, &ready, timo); + if (n < 0 && errno != EINTR) + fatal("%s: select: %m", __func__); +} + + +/* + * wait_time - wait for a given length of time or until a + * signal is received. + */ +void +wait_time(struct timeval *timo) +{ + int n; + + n = select(0, NULL, NULL, NULL, timo); + if (n < 0 && errno != EINTR) + fatal("%s: select: %m", __func__); +} +#endif + + +/* + * read_packet - get a PPP packet from the serial device. + */ +int +read_packet(u_char *buf) +{ + int len; + + if ((len = read(ttyfd, buf, PPP_MTU + PPP_HDRLEN)) < 0) { + if (errno == EWOULDBLOCK || errno == EINTR) + return -1; + fatal("%s: read: %m", __func__); + } + return len; +} + + +/* + * get_loop_output - read characters from the loopback, form them + * into frames, and detect when we want to bring the real link up. + * Return value is 1 if we need to bring up the link, 0 otherwise. + */ +int +get_loop_output(void) +{ + int rv = 0; + int n; + + while ((n = read(loop_master, inbuf, sizeof(inbuf))) >= 0) { + if (loop_chars(inbuf, n)) + rv = 1; + } + + if (n == 0) + fatal("%s: eof on loopback", __func__); + if (n == -1 && errno != EWOULDBLOCK) + fatal("%s: read from loopback: %m", __func__); + + return rv; +} + + +/* + * netif_set_mtu - set the MTU on the PPP network interface. + */ +void +netif_set_mtu(int unit, int mtu) +{ + struct ifreq ifr; + + SYSDEBUG((LOG_DEBUG, "netif_set_mtu: mtu = %d\n", mtu)); + + memset(&ifr, '\0', sizeof (ifr)); + strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); + ifr.ifr_mtu = mtu; + + if (ifunit >= 0 && ioctl(sock_fd, SIOCSIFMTU, (caddr_t) &ifr) < 0) + fatal("%s: ioctl(SIOCSIFMTU): %m", __func__); +} + +/* + * netif_get_mtu - get the MTU on the PPP network interface. + */ +int +netif_get_mtu(int unit) +{ + struct ifreq ifr; + + memset (&ifr, '\0', sizeof (ifr)); + strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); + + if (ifunit >= 0 && ioctl(sock_fd, SIOCGIFMTU, (caddr_t) &ifr) < 0) { + error("%s: ioctl(SIOCGIFMTU): %m", __func__); + return 0; + } + return ifr.ifr_mtu; +} + +/* + * tty_send_config - configure the transmit characteristics of + * the ppp interface. + */ +void +tty_send_config(int mtu, u_int32_t asyncmap, int pcomp, int accomp) +{ + u_int x; +#if 0 + /* Linux code does not do anything with the mtu here */ + ifnet_set_mtu(-1, mtu); +#endif + + if (ioctl(ppp_fd, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0) + fatal("%s: ioctl(PPPIOCSASYNCMAP): %m", __func__); + + x = get_flags(ppp_fd); + x = pcomp? x | SC_COMP_PROT: x &~ SC_COMP_PROT; + x = accomp? x | SC_COMP_AC: x &~ SC_COMP_AC; + x = sync_serial ? x | SC_SYNC : x & ~SC_SYNC; + set_flags(ppp_fd, x); +} + + +/* + * ppp_set_xaccm - set the extended transmit ACCM for the interface. + */ +void +tty_set_xaccm(ext_accm accm) +{ + if (ioctl(ppp_fd, PPPIOCSXASYNCMAP, accm) < 0 && errno != ENOTTY) + warn("%s: ioctl(set extended ACCM): %m", __func__); +} + + +/* + * ppp_recv_config - configure the receive-side characteristics of + * the ppp interface. + */ +void +tty_recv_config(int mru, u_int32_t asyncmap, int pcomp, int accomp) +{ + int x; + + if (ioctl(ppp_fd, PPPIOCSMRU, (caddr_t) &mru) < 0) + fatal("%s: ioctl(PPPIOCSMRU): %m", __func__); + if (ioctl(ppp_fd, PPPIOCSRASYNCMAP, (caddr_t) &asyncmap) < 0) + fatal("%s: ioctl(PPPIOCSRASYNCMAP): %m", __func__); + x = get_flags(ppp_fd); + x = !accomp? x | SC_REJ_COMP_AC: x &~ SC_REJ_COMP_AC; + set_flags(ppp_fd, x); +} + +/* + * ccp_test - ask kernel whether a given compression method + * is acceptable for use. Returns 1 if the method and parameters + * are OK, 0 if the method is known but the parameters are not OK + * (e.g. code size should be reduced), or -1 if the method is unknown. + */ +int +ccp_test(int unit, u_char *opt_ptr, int opt_len, int for_transmit) +{ + struct ppp_option_data data; + + data.ptr = opt_ptr; + data.length = opt_len; + data.transmit = for_transmit; + if (ioctl(ttyfd, PPPIOCSCOMPRESS, (caddr_t) &data) >= 0) + return 1; + return (errno == ENOBUFS)? 0: -1; +} + +/* + * ccp_flags_set - inform kernel about the current state of CCP. + */ +void +ccp_flags_set(int unit, int isopen, int isup) +{ + int x; + + x = get_flags(ppp_fd); + x = isopen? x | SC_CCP_OPEN: x &~ SC_CCP_OPEN; + x = isup? x | SC_CCP_UP: x &~ SC_CCP_UP; + set_flags(ppp_fd, x); +} + +/* + * ccp_fatal_error - returns 1 if decompression was disabled as a + * result of an error detected after decompression of a packet, + * 0 otherwise. This is necessary because of patent nonsense. + */ +int +ccp_fatal_error(int unit) +{ + int x; + + x = get_flags(ppp_fd); + return x & SC_DC_FERROR; +} + +/* + * get_idle_time - return how long the link has been idle. + */ +int +get_idle_time(int u, struct ppp_idle *ip) +{ + return ioctl(ppp_fd, PPPIOCGIDLE, ip) >= 0; +} + +/* + * get_ppp_stats - return statistics for the link. + */ +int +get_ppp_stats(int u, struct pppd_stats *stats) +{ + struct ifpppstatsreq req; + + memset (&req, 0, sizeof (req)); + strlcpy(req.ifr_name, ifname, sizeof(req.ifr_name)); + if (ioctl(sock_fd, SIOCGPPPSTATS, &req) < 0) { + error("%s: Couldn't get PPP statistics: %m", __func__); + return 0; + } + stats->bytes_in = req.stats.p.ppp_ibytes; + stats->bytes_out = req.stats.p.ppp_obytes; + stats->pkts_in = req.stats.p.ppp_ipackets; + stats->pkts_out = req.stats.p.ppp_opackets; + return 1; +} + + +#ifdef PPP_FILTER +/* + * set_filters - transfer the pass and active filters to the kernel. + */ +int +set_filters(struct bpf_program *pass_in, struct bpf_program *pass_out, + struct bpf_program *active_in, struct bpf_program *active_out) +{ + int ret = 1; + + if (pass_in->bf_len > 0) { + if (ioctl(ppp_fd, PPPIOCSIPASS, pass_in) < 0) { + error("%s: Couldn't set pass-filter-in in kernel: %m", __func__); + ret = 0; + } + } + + if (pass_out->bf_len > 0) { + if (ioctl(ppp_fd, PPPIOCSOPASS, pass_out) < 0) { + error("%s: Couldn't set pass-filter-out in kernel: %m", __func__); + ret = 0; + } + } + + if (active_in->bf_len > 0) { + if (ioctl(ppp_fd, PPPIOCSIACTIVE, active_in) < 0) { + error("%s: Couldn't set active-filter-in in kernel: %m", __func__); + ret = 0; + } + } + + if (active_out->bf_len > 0) { + if (ioctl(ppp_fd, PPPIOCSOACTIVE, active_out) < 0) { + error("%s: Couldn't set active-filter-out in kernel: %m", __func__); + ret = 0; + } + } + + return ret; +} +#endif + +/* + * sifvjcomp - config tcp header compression + */ +int +sifvjcomp(int u, int vjcomp, int cidcomp, int maxcid) +{ + u_int x; + + x = get_flags(ppp_fd); + x = vjcomp ? x | SC_COMP_TCP: x &~ SC_COMP_TCP; + x = cidcomp? x & ~SC_NO_TCP_CCID: x | SC_NO_TCP_CCID; + set_flags(ppp_fd, x); + if (vjcomp && ioctl(ppp_fd, PPPIOCSMAXCID, (caddr_t) &maxcid) < 0) { + error("%s: ioctl(PPPIOCSMAXCID): %m", __func__); + return 0; + } + return 1; +} + +/* + * sifup - Config the interface up and enable IP packets to pass. + */ +int +sifup(int u) +{ + struct ifreq ifr; + + strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); + if (ioctl(sock_fd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) { + error("%s: ioctl (SIOCGIFFLAGS): %m", __func__); + return 0; + } + ifr.ifr_flags |= IFF_UP; + if (ioctl(sock_fd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) { + error("%s: ioctl(SIOCSIFFLAGS): %m", __func__); + return 0; + } + if_is_up = 1; + return 1; +} + +/* + * sifnpmode - Set the mode for handling packets for a given NP. + */ +int +sifnpmode(int u, int proto, enum NPmode mode) +{ + struct npioctl npi; + + npi.protocol = proto; + npi.mode = mode; + if (ioctl(ppp_fd, PPPIOCSNPMODE, &npi) < 0) { + error("%s: ioctl(set NP %d mode to %d): %m", __func__, proto, mode); + return 0; + } + return 1; +} + +/* + * sifdown - Config the interface down and disable IP. + */ +int +sifdown(int u) +{ + struct ifreq ifr; + int rv; + struct npioctl npi; + + rv = 1; + npi.protocol = PPP_IP; + npi.mode = NPMODE_ERROR; + ioctl(ppp_fd, PPPIOCSNPMODE, (caddr_t) &npi); + /* ignore errors, because ppp_fd might have been closed by now. */ + + strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); + if (ioctl(sock_fd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) { + error("%s: ioctl (SIOCGIFFLAGS): %m", __func__); + rv = 0; + } else { + ifr.ifr_flags &= ~IFF_UP; + if (ioctl(sock_fd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) { + error("%s: ioctl(SIOCSIFFLAGS): %m", __func__); + rv = 0; + } else + if_is_up = 0; + } + return rv; +} + +/* + * SET_SA_FAMILY - set the sa_family field of a struct sockaddr, + * if it exists. + */ +#define SET_SA_FAMILY(addr, family) \ + BZERO((char *) &(addr), sizeof(addr)); \ + addr.sa_family = (family); \ + addr.sa_len = sizeof(addr); + +/* + * sifaddr - Config the interface IP addresses and netmask. + */ +int +sifaddr(int u, u_int32_t o, u_int32_t h, u_int32_t m) +{ + struct ifaliasreq ifra; + struct ifreq ifr; + + strlcpy(ifra.ifra_name, ifname, sizeof(ifra.ifra_name)); + SET_SA_FAMILY(ifra.ifra_addr, AF_INET); + ((struct sockaddr_in *) &ifra.ifra_addr)->sin_addr.s_addr = o; + SET_SA_FAMILY(ifra.ifra_broadaddr, AF_INET); + ((struct sockaddr_in *) &ifra.ifra_broadaddr)->sin_addr.s_addr = h; + if (m != 0) { + SET_SA_FAMILY(ifra.ifra_mask, AF_INET); + ((struct sockaddr_in *) &ifra.ifra_mask)->sin_addr.s_addr = m; + } else + BZERO(&ifra.ifra_mask, sizeof(ifra.ifra_mask)); + BZERO(&ifr, sizeof(ifr)); + strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + if (ioctl(sock_fd, SIOCDIFADDR, (caddr_t) &ifr) < 0) { + if (errno != EADDRNOTAVAIL) + warn("%s: Couldn't remove interface address: %m", __func__); + } + if (ioctl(sock_fd, SIOCAIFADDR, (caddr_t) &ifra) < 0) { + if (errno != EEXIST) { + error("%s: Couldn't set interface address: %m", __func__); + return 0; + } + warn("%s: Couldn't set interface address: Address %I already exists", + __func__, o); + } + ifaddrs[0] = o; + ifaddrs[1] = h; + return 1; +} + +/* + * cifaddr - Clear the interface IP addresses, and delete routes + * through the interface if possible. + */ +int +cifaddr(int u, u_int32_t o, u_int32_t h) +{ + struct ifaliasreq ifra; + + ifaddrs[0] = 0; + strlcpy(ifra.ifra_name, ifname, sizeof(ifra.ifra_name)); + SET_SA_FAMILY(ifra.ifra_addr, AF_INET); + ((struct sockaddr_in *) &ifra.ifra_addr)->sin_addr.s_addr = o; + SET_SA_FAMILY(ifra.ifra_broadaddr, AF_INET); + ((struct sockaddr_in *) &ifra.ifra_broadaddr)->sin_addr.s_addr = h; + BZERO(&ifra.ifra_mask, sizeof(ifra.ifra_mask)); + if (ioctl(sock_fd, SIOCDIFADDR, (caddr_t) &ifra) < 0) { + if (!doing_cleanup && errno != EADDRNOTAVAIL) + warn("%s: Couldn't delete interface address: %m", __func__); + return 0; + } + return 1; +} + +/* + * sifdefaultroute - assign a default route through the address given. + */ +int +sifdefaultroute(int u, u_int32_t l, u_int32_t g) +{ + return dodefaultroute(g, 's'); +} + +/* + * cifdefaultroute - delete a default route through the address given. + */ +int +cifdefaultroute(int u, u_int32_t l, u_int32_t g) +{ + return dodefaultroute(g, 'c'); +} + +/* + * dodefaultroute - talk to a routing socket to add/delete a default route. + */ +static int +dodefaultroute(u_int32_t g, int cmd) +{ + int routes; + struct { + struct rt_msghdr hdr; + struct sockaddr_in dst; + struct sockaddr_in gway; + struct sockaddr_in netmask; + struct sockaddr_dl ifp; + } rtmsg; + + if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) { + if (!doing_cleanup) + error("%s: Couldn't %s default route: socket: %m", __func__, + cmd == 's' ? "add" : "delete"); + return 0; + } + + memset(&rtmsg, 0, sizeof(rtmsg)); + + rtmsg.hdr.rtm_type = cmd == 's' ? RTM_ADD : RTM_DELETE; + rtmsg.hdr.rtm_flags = RTF_UP | RTF_GATEWAY | RTF_STATIC; + rtmsg.hdr.rtm_version = RTM_VERSION; + rtmsg.hdr.rtm_seq = ++rtm_seq; + rtmsg.hdr.rtm_addrs = + RTA_DST | RTA_GATEWAY | RTA_NETMASK | RTA_IFP; + + rtmsg.dst.sin_len = sizeof(rtmsg.dst); + rtmsg.dst.sin_family = AF_INET; + rtmsg.dst.sin_addr.s_addr = 0; + + rtmsg.gway.sin_len = sizeof(rtmsg.gway); + rtmsg.gway.sin_family = AF_INET; + rtmsg.gway.sin_addr.s_addr = g; + + rtmsg.netmask.sin_len = sizeof(rtmsg.netmask); + rtmsg.netmask.sin_family = AF_INET; + rtmsg.netmask.sin_addr.s_addr = 0; + + rtmsg.ifp.sdl_family = AF_LINK; + rtmsg.ifp.sdl_len = sizeof(rtmsg.ifp); + link_addr(ifname, &rtmsg.ifp); + + rtmsg.hdr.rtm_msglen = sizeof(rtmsg); + + if (write(routes, &rtmsg, sizeof(rtmsg)) < 0) { + if (!doing_cleanup) + error("%s: Couldn't %s default route: %m", __func__, + cmd == 's' ? "add" : "delete"); + close(routes); + return 0; + } + + close(routes); + default_route_gateway = (cmd == 's') ? g : 0; + return 1; +} + +#if RTM_VERSION >= 3 + +/* + * sifproxyarp - Make a proxy ARP entry for the peer. + */ +static struct { + struct rt_msghdr hdr; + struct sockaddr_inarp dst; + struct sockaddr_dl hwa; + char extra[128]; +} arpmsg; + +static int arpmsg_valid; + +int +sifproxyarp(int unit, u_int32_t hisaddr) +{ + int routes; + + /* + * Get the hardware address of an interface on the same subnet + * as our local address. + */ + memset(&arpmsg, 0, sizeof(arpmsg)); + if (!get_ether_addr(hisaddr, &arpmsg.hwa)) { + error("%s: Cannot determine ethernet address for proxy ARP", __func__); + return 0; + } + + if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) { + error("%s: Couldn't add proxy arp entry: socket: %m", __func__); + return 0; + } + + arpmsg.hdr.rtm_type = RTM_ADD; + arpmsg.hdr.rtm_flags = RTF_ANNOUNCE | RTF_HOST | RTF_STATIC; + arpmsg.hdr.rtm_version = RTM_VERSION; + arpmsg.hdr.rtm_seq = ++rtm_seq; + arpmsg.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY; + arpmsg.hdr.rtm_inits = RTV_EXPIRE; + arpmsg.dst.sin_len = sizeof(struct sockaddr_inarp); + arpmsg.dst.sin_family = AF_INET; + arpmsg.dst.sin_addr.s_addr = hisaddr; + arpmsg.dst.sin_other = SIN_PROXY; + + arpmsg.hdr.rtm_msglen = (char *) &arpmsg.hwa - (char *) &arpmsg + + RT_ROUNDUP(arpmsg.hwa.sdl_len); + if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) { + error("%s: Couldn't add proxy arp entry: %m", __func__); + close(routes); + return 0; + } + + close(routes); + arpmsg_valid = 1; + proxy_arp_addr = hisaddr; + return 1; +} + +/* + * cifproxyarp - Delete the proxy ARP entry for the peer. + */ +int +cifproxyarp(int unit, u_int32_t hisaddr) +{ + int routes; + + if (!arpmsg_valid) + return 0; + arpmsg_valid = 0; + + arpmsg.hdr.rtm_type = RTM_DELETE; + arpmsg.hdr.rtm_seq = ++rtm_seq; + + if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) { + if (!doing_cleanup) + error("%s: Couldn't delete proxy arp entry: socket: %m", __func__); + return 0; + } + + if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) { + if (!doing_cleanup) + error("%s: Couldn't delete proxy arp entry: %m", __func__); + close(routes); + return 0; + } + + close(routes); + proxy_arp_addr = 0; + return 1; +} + +#else /* RTM_VERSION */ + +/* + * sifproxyarp - Make a proxy ARP entry for the peer. + */ +int +sifproxyarp(int unit, u_int32_t hisaddr) +{ + struct arpreq arpreq; + struct { + struct sockaddr_dl sdl; + char space[128]; + } dls; + + BZERO(&arpreq, sizeof(arpreq)); + + /* + * Get the hardware address of an interface on the same subnet + * as our local address. + */ + if (!get_ether_addr(hisaddr, &dls.sdl)) { + error("%s: Cannot determine ethernet address for proxy ARP", __func__); + return 0; + } + + arpreq.arp_ha.sa_len = sizeof(struct sockaddr); + arpreq.arp_ha.sa_family = AF_UNSPEC; + BCOPY(LLADDR(&dls.sdl), arpreq.arp_ha.sa_data, dls.sdl.sdl_alen); + SET_SA_FAMILY(arpreq.arp_pa, AF_INET); + ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr; + arpreq.arp_flags = ATF_PERM | ATF_PUBL; + if (ioctl(sock_fd, SIOCSARP, (caddr_t)&arpreq) < 0) { + error("%s: Couldn't add proxy arp entry: %m", __func__); + return 0; + } + + proxy_arp_addr = hisaddr; + return 1; +} + +/* + * cifproxyarp - Delete the proxy ARP entry for the peer. + */ +int +cifproxyarp(int unit, u_int32_t hisaddr) +{ + struct arpreq arpreq; + + BZERO(&arpreq, sizeof(arpreq)); + SET_SA_FAMILY(arpreq.arp_pa, AF_INET); + ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr; + if (ioctl(sock_fd, SIOCDARP, (caddr_t)&arpreq) < 0) { + warn("%s: Couldn't delete proxy arp entry: %m", __func__); + return 0; + } + proxy_arp_addr = 0; + return 1; +} +#endif /* RTM_VERSION */ + + +/* + * get_ether_addr - get the hardware address of an interface on the + * the same subnet as ipaddr. + */ +static int +get_ether_addr(u_int32_t ipaddr, struct sockaddr_dl *hwaddr) +{ + u_int32_t ina, mask; + struct sockaddr_dl *dla; + struct ifaddrs *ifap, *ifa, *ifp; + + /* + * Scan through looking for an interface with an Internet + * address on the same subnet as `ipaddr'. + */ + if (getifaddrs(&ifap) != 0) { + error("%s: getifaddrs: %m", __func__); + return 0; + } + + for (ifa = ifap; ifa; ifa = ifa->ifa_next) { + if (ifa->ifa_addr->sa_family != AF_INET) + continue; + ina = ((struct sockaddr_in *) ifa->ifa_addr)->sin_addr.s_addr; + /* + * Check that the interface is up, and not point-to-point + * or loopback. + */ + if ((ifa->ifa_flags & + (IFF_UP|IFF_BROADCAST|IFF_POINTOPOINT|IFF_LOOPBACK|IFF_NOARP)) + != (IFF_UP|IFF_BROADCAST)) + continue; + /* + * Get its netmask and check that it's on the right subnet. + */ + mask = ((struct sockaddr_in *) ifa->ifa_netmask)->sin_addr.s_addr; + if ((ipaddr & mask) != (ina & mask)) + continue; + break; + } + + if (!ifa) { + freeifaddrs(ifap); + return 0; + } + info("found interface %s for proxy arp", ifa->ifa_name); + + ifp = ifa; + + /* + * Now scan through again looking for a link-level address + * for this interface. + */ + for (ifa = ifap; ifa; ifa = ifa->ifa_next) { + if (strcmp(ifp->ifa_name, ifa->ifa_name) != 0) + continue; + if (ifa->ifa_addr->sa_family != AF_LINK) + continue; + /* + * Found the link-level address - copy it out + */ + dla = (struct sockaddr_dl *) ifa->ifa_addr; + BCOPY(dla, hwaddr, dla->sdl_len); + freeifaddrs(ifap); + return 1; + } + + freeifaddrs(ifap); + return 0; +} + +/* + * get_if_hwaddr - get the hardware address for the specified + * network interface device. + */ +int +get_if_hwaddr(u_char *addr, char *name) +{ + +#define IFREQ_SAFE (sizeof(struct ifreq) + sizeof(struct sockaddr_dl)) + /* XXX sockaddr_dl is larger than the sockaddr in struct ifreq! */ + union { /* XXX */ + struct ifreq _ifreq; /* XXX */ + char _X[IFREQ_SAFE]; /* XXX */ + } _ifreq_dontsmashstack; /* XXX */ +#define ifreq_xxx _ifreq_dontsmashstack._ifreq /* XXX */ + + struct sockaddr_dl *sdl = (struct sockaddr_dl *) &ifreq_xxx.ifr_addr; + int fd; + + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) + return 0; + (void)memset(sdl, 0, sizeof(*sdl)); + sdl->sdl_family = AF_LINK; + (void)strlcpy(ifreq_xxx.ifr_name, name, sizeof(ifreq_xxx.ifr_name)); + if (ioctl(fd, SIOCGIFADDR, &ifreq_xxx) == -1) { + (void)close(fd); + return 0; + } + (void)close(fd); + (void)memcpy(addr, LLADDR(sdl), sdl->sdl_alen); + return sdl->sdl_nlen; +} + +/* + * get_first_ethernet - return the name of the first ethernet-style + * interface on this system. + */ +char * +get_first_ethernet(void) +{ + static char ifname[IFNAMSIZ]; + struct ifaddrs *ifap, *ifa; + + /* + * Scan through the system's network interfaces. + */ + if (getifaddrs(&ifap) != 0) { + warn("%s: getifaddrs: %m", __func__); + return NULL; + } + for (ifa = ifap; ifa; ifa = ifa->ifa_next) { + /* + * Check the interface's internet address. + */ + if (ifa->ifa_addr->sa_family != AF_INET) + continue; + /* + * Check that the interface is up, and not point-to-point or loopback. + */ + if ((ifa->ifa_flags & (IFF_UP|IFF_POINTOPOINT|IFF_LOOPBACK)) + != IFF_UP) { + strlcpy(ifname, ifa->ifa_name, sizeof(ifname)); + freeifaddrs(ifap); + return ifname; + } + } + freeifaddrs(ifap); + return NULL; +} + +/* + * Return user specified netmask, modified by any mask we might determine + * for address `addr' (in network byte order). + * Here we scan through the system's list of interfaces, looking for + * any non-point-to-point interfaces which might appear to be on the same + * network as `addr'. If we find any, we OR in their netmask to the + * user-specified netmask. + */ +u_int32_t +GetMask(u_int32_t addr) +{ + u_int32_t mask, nmask, ina; + struct ifaddrs *ifap, *ifa; + + addr = ntohl(addr); + if (IN_CLASSA(addr)) /* determine network mask for address class */ + nmask = IN_CLASSA_NET; + else if (IN_CLASSB(addr)) + nmask = IN_CLASSB_NET; + else + nmask = IN_CLASSC_NET; + /* class D nets are disallowed by bad_ip_adrs */ + mask = netmask | htonl(nmask); + + /* + * Scan through the system's network interfaces. + */ + if (getifaddrs(&ifap) != 0) { + warn("%s: getifaddrs: %m", __func__); + return 0; + } + + for (ifa = ifap; ifa; ifa = ifa->ifa_next) { + /* + * Check the interface's internet address. + */ + if (ifa->ifa_addr->sa_family != AF_INET) + continue; + ina = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr; + if ((ntohl(ina) & nmask) != (addr & nmask)) + continue; + /* + * Check that the interface is up, and not point-to-point or loopback. + */ + if ((ifa->ifa_flags & (IFF_UP|IFF_POINTOPOINT|IFF_LOOPBACK)) != IFF_UP) + continue; + /* + * Get its netmask and OR it into our mask. + */ + mask |= ((struct sockaddr_in *)ifa->ifa_netmask)->sin_addr.s_addr; + } + + freeifaddrs(ifap); + return mask; +} + +/* + * have_route_to - determine if the system has any route to + * a given IP address. + * For demand mode to work properly, we have to ignore routes + * through our own interface. + */ +int have_route_to(u_int32_t addr) +{ + return -1; +} + +/* + * Use the hostid as part of the random number seed. + */ +int +get_host_seed(void) +{ + return gethostid(); +} + +#if 0 +/* + * lock - create a lock file for the named lock device + */ +#define LOCK_PREFIX "/var/spool/lock/LCK.." + +static char *lock_file; /* name of lock file created */ + +int +lock(char *dev) +{ + char hdb_lock_buffer[12]; + int fd, pid, n; + char *p; + size_t l; + + if ((p = strrchr(dev, '/')) != NULL) + dev = p + 1; + l = strlen(LOCK_PREFIX) + strlen(dev) + 1; + lock_file = malloc(l); + if (lock_file == NULL) + novm("lock file name"); + slprintf(lock_file, l, "%s%s", LOCK_PREFIX, dev); + + while ((fd = open(lock_file, O_EXCL | O_CREAT | O_RDWR, 0644)) < 0) { + if (errno == EEXIST + && (fd = open(lock_file, O_RDONLY, 0)) >= 0) { + /* Read the lock file to find out who has the device locked */ + n = read(fd, hdb_lock_buffer, 11); + if (n <= 0) { + error("%s: Can't read pid from lock file %s", __func__, + lock_file); + close(fd); + } else { + hdb_lock_buffer[n] = 0; + pid = atoi(hdb_lock_buffer); + if (kill(pid, 0) == -1 && errno == ESRCH) { + /* pid no longer exists - remove the lock file */ + if (unlink(lock_file) == 0) { + close(fd); + notice("%s: Removed stale lock on %s (pid %d)", + __func__, dev, pid); + continue; + } else + warn("%s: Couldn't remove stale lock on %s", __func__, + dev); + } else + notice("%s: Device %s is locked by pid %d", __func__, + dev, pid); + } + close(fd); + } else + error("%s: Can't create lock file %s: %m", __func__, lock_file); + free(lock_file); + lock_file = NULL; + return -1; + } + + slprintf(hdb_lock_buffer, sizeof(hdb_lock_buffer), "%10d\n", getpid()); + write(fd, hdb_lock_buffer, 11); + + close(fd); + return 0; +} + +/* + * unlock - remove our lockfile + */ +void +unlock(void) +{ + if (lock_file) { + unlink(lock_file); + free(lock_file); + lock_file = NULL; + } +} +#endif diff --git a/external/bsd/ppp/usr.sbin/pppd/tdb.c b/external/bsd/ppp/usr.sbin/pppd/tdb.c new file mode 100644 index 000000000000..afb24b996607 --- /dev/null +++ b/external/bsd/ppp/usr.sbin/pppd/tdb.c @@ -0,0 +1,1293 @@ +/* NetBSD: tdb.c,v 1.7 2013/10/19 17:16:38 christos Exp */ + +/* + * Database functions + * Copyright (C) Andrew Tridgell 1999 + * + * 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 provided that this software or + * any derived work is only used as part of the PPP daemon (pppd) + * and related utilities. + * The name of the author 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. + * + * Note: this software is also available under the Gnu Public License + * version 2 or later. + */ + +#include +#ifndef lint +__RCSID("NetBSD: tdb.c,v 1.7 2013/10/19 17:16:38 christos Exp "); +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include "tdb.h" + +#define TDB_VERSION (0x26011967 + 1) +#define TDB_MAGIC (0x26011999U) +#define TDB_FREE_MAGIC (~TDB_MAGIC) +#define TDB_ALIGN 4 +#define MIN_REC_SIZE (2*sizeof(struct list_struct) + TDB_ALIGN) +#define DEFAULT_HASH_SIZE 128 +#define TDB_PAGE_SIZE 0x2000 +#define TDB_LEN_MULTIPLIER 10 +#define FREELIST_TOP (sizeof(struct tdb_header)) + +#define LOCK_SET 1 +#define LOCK_CLEAR 0 + +/* lock offsets */ +#define GLOBAL_LOCK 0 +#define ACTIVE_LOCK 4 +#define LIST_LOCK_BASE 1024 + +#define BUCKET(hash) ((hash) % tdb->header.hash_size) + +#ifndef MAP_FILE +#define MAP_FILE 0 +#endif + +/* the body of the database is made of one list_struct for the free space + plus a separate data list for each hash value */ +struct list_struct { + tdb_len rec_len; /* total byte length of record */ + tdb_off next; /* offset of the next record in the list */ + tdb_len key_len; /* byte length of key */ + tdb_len data_len; /* byte length of data */ + unsigned full_hash; /* the full 32 bit hash of the key */ + unsigned magic; /* try to catch errors */ + /* + the following union is implied + union { + char record[rec_len]; + struct { + char key[key_len]; + char data[data_len]; + } + } + */ +}; + +/* a null data record - useful for error returns */ +static TDB_DATA null_data; + +static int tdb_update __P((TDB_CONTEXT *, TDB_DATA, TDB_DATA)); +#ifdef notyet +static int tdb_lockchain __P((TDB_CONTEXT *, TDB_DATA)); +static int tdb_unlockchain __P((TDB_CONTEXT *, TDB_DATA)); +#endif + +/* a byte range locking function - return 0 on success + this functions locks/unlocks 1 byte at the specified offset */ +static int tdb_brlock(TDB_CONTEXT *tdb, tdb_off offset, + int set, int rw_type, int lck_type) +{ +#if NOLOCK + return 0; +#else + struct flock fl; + + if (tdb->fd == -1) return 0; /* for in memory tdb */ + + if (tdb->read_only) return -1; + + fl.l_type = set==LOCK_SET?rw_type:F_UNLCK; + fl.l_whence = SEEK_SET; + fl.l_start = offset; + fl.l_len = 1; + fl.l_pid = 0; + + if (fcntl(tdb->fd, lck_type, &fl) != 0) { +#if TDB_DEBUG + if (lck_type == F_SETLKW) { + printf("lock %d failed at %d (%s)\n", + set, offset, strerror(errno)); + } +#endif + tdb->ecode = TDB_ERR_LOCK; + return -1; + } + return 0; +#endif +} + +/* lock a list in the database. list -1 is the alloc list */ +static int tdb_lock(TDB_CONTEXT *tdb, int list) +{ + if (list < -1 || list >= (int)tdb->header.hash_size) { +#if TDB_DEBUG + printf("bad list %d\n", list); +#endif + return -1; + } + if (tdb->locked[list+1] == 0) { + if (tdb_brlock(tdb, LIST_LOCK_BASE + 4*list, LOCK_SET, + F_WRLCK, F_SETLKW) != 0) { + return -1; + } + } + tdb->locked[list+1]++; + return 0; +} + +/* unlock the database. */ +static int tdb_unlock(TDB_CONTEXT *tdb, int list) +{ + if (list < -1 || list >= (int)tdb->header.hash_size) { +#if TDB_DEBUG + printf("bad unlock list %d\n", list); +#endif + return -1; + } + + if (tdb->locked[list+1] == 0) { +#if TDB_DEBUG + printf("not locked %d\n", list); +#endif + tdb->ecode = TDB_ERR_LOCK; + return -1; + } + if (tdb->locked[list+1] == 1) { + if (tdb_brlock(tdb, LIST_LOCK_BASE + 4*list, LOCK_CLEAR, + F_WRLCK, F_SETLKW) != 0) { + return -1; + } + } + tdb->locked[list+1]--; + return 0; +} + +/* the hash algorithm - turn a key into an integer + This is based on the hash agorithm from gdbm */ +static unsigned tdb_hash(TDB_DATA *key) +{ + unsigned value; /* Used to compute the hash value. */ + unsigned i; /* Used to cycle through random values. */ + + /* Set the initial value from the key size. */ + value = 0x238F13AF * key->dsize; + for (i=0; i < key->dsize; i++) { + value = (value + (key->dptr[i] << (i*5 % 24))); + } + + value = (1103515243 * value + 12345); + + return value; +} + +/* find the top of the hash chain for an open database */ +static tdb_off tdb_hash_top(TDB_CONTEXT *tdb, unsigned hash) +{ + tdb_off ret; + hash = BUCKET(hash); + ret = FREELIST_TOP + (hash+1)*sizeof(tdb_off); + return ret; +} + + +/* check for an out of bounds access - if it is out of bounds then + see if the database has been expanded by someone else and expand + if necessary */ +static int tdb_oob(TDB_CONTEXT *tdb, tdb_off offset) +{ + struct stat st; + if ((offset <= tdb->map_size) || (tdb->fd == -1)) return 0; + + fstat(tdb->fd, &st); + if (st.st_size <= (ssize_t)offset) { + tdb->ecode = TDB_ERR_IO; + return -1; + } + +#if HAVE_MMAP + if (tdb->map_ptr) { + munmap(tdb->map_ptr, tdb->map_size); + tdb->map_ptr = NULL; + } +#endif + + tdb->map_size = st.st_size; +#if HAVE_MMAP + tdb->map_ptr = (void *)mmap(NULL, tdb->map_size, + tdb->read_only?PROT_READ:PROT_READ|PROT_WRITE, + MAP_SHARED | MAP_FILE, tdb->fd, 0); +#endif + return 0; +} + + +/* write a lump of data at a specified offset */ +static int tdb_write(TDB_CONTEXT *tdb, tdb_off offset, const char *buf, tdb_len len) +{ + if (tdb_oob(tdb, offset + len) != 0) { + /* oops - trying to write beyond the end of the database! */ + return -1; + } + + if (tdb->map_ptr) { + memcpy(offset + (char *)tdb->map_ptr, buf, len); + } else { + if (lseek(tdb->fd, offset, SEEK_SET) != offset || + write(tdb->fd, buf, len) != (ssize_t)len) { + tdb->ecode = TDB_ERR_IO; + return -1; + } + } + return 0; +} + +/* read a lump of data at a specified offset */ +static int tdb_read(TDB_CONTEXT *tdb, tdb_off offset, char *buf, tdb_len len) +{ + if (tdb_oob(tdb, offset + len) != 0) { + /* oops - trying to read beyond the end of the database! */ + return -1; + } + + if (tdb->map_ptr) { + memcpy(buf, offset + (char *)tdb->map_ptr, len); + } else { + if (lseek(tdb->fd, offset, SEEK_SET) != offset || + read(tdb->fd, buf, len) != (ssize_t)len) { + tdb->ecode = TDB_ERR_IO; + return -1; + } + } + return 0; +} + + +/* read a lump of data, allocating the space for it */ +static char *tdb_alloc_read(TDB_CONTEXT *tdb, tdb_off offset, tdb_len len) +{ + char *buf; + + buf = (char *)malloc(len); + + if (!buf) { + tdb->ecode = TDB_ERR_OOM; + return NULL; + } + + if (tdb_read(tdb, offset, buf, len) == -1) { + free(buf); + return NULL; + } + + return buf; +} + +/* convenience routine for writing a record */ +static int rec_write(TDB_CONTEXT *tdb, tdb_off offset, struct list_struct *rec) +{ + return tdb_write(tdb, offset, (char *)rec, sizeof(*rec)); +} + +/* convenience routine for writing a tdb_off */ +static int ofs_write(TDB_CONTEXT *tdb, tdb_off offset, tdb_off *d) +{ + return tdb_write(tdb, offset, (char *)d, sizeof(*d)); +} + +/* read a tdb_off from the store */ +static int ofs_read(TDB_CONTEXT *tdb, tdb_off offset, tdb_off *d) +{ + return tdb_read(tdb, offset, (char *)d, sizeof(*d)); +} + +/* read a record and check for simple errors */ +static int rec_read(TDB_CONTEXT *tdb, tdb_off offset, struct list_struct *rec) +{ + if (tdb_read(tdb, offset, (char *)rec, sizeof(*rec)) == -1) return -1; + if (rec->magic != TDB_MAGIC) { +#if TDB_DEBUG + printf("bad magic 0x%08x at offset %d\n", + rec->magic, offset); +#endif + tdb->ecode = TDB_ERR_CORRUPT; + return -1; + } + if (tdb_oob(tdb, rec->next) != 0) { + return -1; + } + return 0; +} + +/* expand the database at least length bytes by expanding the + underlying file and doing the mmap again if necessary */ +static int tdb_expand(TDB_CONTEXT *tdb, tdb_off length) +{ + struct list_struct rec; + tdb_off offset, ptr; + char b = 0; + + tdb_lock(tdb,-1); + + /* make sure we know about any previous expansions by another + process */ + tdb_oob(tdb,tdb->map_size + 1); + + /* always make room for at least 10 more records */ + length *= TDB_LEN_MULTIPLIER; + + /* and round the database up to a multiple of TDB_PAGE_SIZE */ + length = ((tdb->map_size + length + TDB_PAGE_SIZE) & ~(TDB_PAGE_SIZE - 1)) - tdb->map_size; + + /* expand the file itself */ + if (tdb->fd != -1) { + lseek(tdb->fd, tdb->map_size + length - 1, SEEK_SET); + if (write(tdb->fd, &b, 1) != 1) goto fail; + } + + /* form a new freelist record */ + offset = FREELIST_TOP; + rec.rec_len = length - sizeof(rec); + rec.magic = TDB_FREE_MAGIC; + if (ofs_read(tdb, offset, &rec.next) == -1) { + goto fail; + } + +#if HAVE_MMAP + if (tdb->fd != -1 && tdb->map_ptr) { + munmap(tdb->map_ptr, tdb->map_size); + tdb->map_ptr = NULL; + } +#endif + + tdb->map_size += length; + + if (tdb->fd == -1) { + void *n; + n = realloc(tdb->map_ptr, tdb->map_size); + if (!n) + goto fail; + tdb->map_ptr = n; + } + + /* write it out */ + if (rec_write(tdb, tdb->map_size - length, &rec) == -1) { + goto fail; + } + + /* link it into the free list */ + ptr = tdb->map_size - length; + if (ofs_write(tdb, offset, &ptr) == -1) goto fail; + +#if HAVE_MMAP + if (tdb->fd != -1) { + tdb->map_ptr = (void *)mmap(NULL, tdb->map_size, + PROT_READ|PROT_WRITE, + MAP_SHARED | MAP_FILE, tdb->fd, 0); + } +#endif + + tdb_unlock(tdb, -1); + return 0; + + fail: + tdb_unlock(tdb,-1); + return -1; +} + +/* allocate some space from the free list. The offset returned points + to a unconnected list_struct within the database with room for at + least length bytes of total data + + 0 is returned if the space could not be allocated + */ +static tdb_off tdb_allocate(TDB_CONTEXT *tdb, tdb_len length) +{ + tdb_off offset, rec_ptr, last_ptr; + struct list_struct rec, lastrec, newrec; + + tdb_lock(tdb, -1); + + again: + last_ptr = 0; + offset = FREELIST_TOP; + + /* read in the freelist top */ + if (ofs_read(tdb, offset, &rec_ptr) == -1) { + goto fail; + } + + /* keep looking until we find a freelist record that is big + enough */ + while (rec_ptr) { + if (tdb_read(tdb, rec_ptr, (char *)&rec, sizeof(rec)) == -1) { + goto fail; + } + + if (rec.magic != TDB_FREE_MAGIC) { +#if TDB_DEBUG + printf("bad magic 0x%08x in free list\n", rec.magic); +#endif + goto fail; + } + + if (rec.rec_len >= length) { + /* found it - now possibly split it up */ + if (rec.rec_len > length + MIN_REC_SIZE) { + length = (length + TDB_ALIGN) & ~(TDB_ALIGN-1); + + newrec.rec_len = rec.rec_len - (sizeof(rec) + length); + newrec.next = rec.next; + newrec.magic = TDB_FREE_MAGIC; + + rec.rec_len = length; + rec.next = rec_ptr + sizeof(rec) + rec.rec_len; + + if (rec_write(tdb, rec.next, &newrec) == -1) { + goto fail; + } + + if (rec_write(tdb, rec_ptr, &rec) == -1) { + goto fail; + } + } + + /* remove it from the list */ + if (last_ptr == 0) { + offset = FREELIST_TOP; + + if (ofs_write(tdb, offset, &rec.next) == -1) { + goto fail; + } + } else { + lastrec.next = rec.next; + if (rec_write(tdb, last_ptr, &lastrec) == -1) { + goto fail; + } + } + + /* all done - return the new record offset */ + tdb_unlock(tdb, -1); + return rec_ptr; + } + + /* move to the next record */ + lastrec = rec; + last_ptr = rec_ptr; + rec_ptr = rec.next; + } + + /* we didn't find enough space. See if we can expand the + database and if we can then try again */ + if (tdb_expand(tdb, length + sizeof(rec)) == 0) goto again; + + fail: +#if TDB_DEBUG + printf("tdb_allocate failed for size %u\n", length); +#endif + tdb_unlock(tdb, -1); + return 0; +} + +/* initialise a new database with a specified hash size */ +static int tdb_new_database(TDB_CONTEXT *tdb, int hash_size) +{ + struct tdb_header header; + int i, size = 0; + tdb_off buf[16]; + + /* create the header */ + memset(&header, 0, sizeof(header)); + memcpy(header.magic_food, TDB_MAGIC_FOOD, strlen(TDB_MAGIC_FOOD)+1); + header.version = TDB_VERSION; + header.hash_size = hash_size; + lseek(tdb->fd, 0, SEEK_SET); + ftruncate(tdb->fd, 0); + + if (tdb->fd != -1 && write(tdb->fd, &header, sizeof(header)) != + sizeof(header)) { + tdb->ecode = TDB_ERR_IO; + return -1; + } else size += sizeof(header); + + /* the freelist and hash pointers */ + memset(buf, 0, sizeof(buf)); + + for (i=0;(hash_size+1)-i >= 16; i += 16) { + if (tdb->fd != -1 && write(tdb->fd, buf, sizeof(buf)) != + sizeof(buf)) { + tdb->ecode = TDB_ERR_IO; + return -1; + } else size += sizeof(buf); + } + + for (;ifd != -1 && write(tdb->fd, buf, sizeof(tdb_off)) != + sizeof(tdb_off)) { + tdb->ecode = TDB_ERR_IO; + return -1; + } else size += sizeof(tdb_off); + } + + if (tdb->fd == -1) { + tdb->map_ptr = calloc(size, 1); + tdb->map_size = size; + if (tdb->map_ptr == NULL) { + tdb->ecode = TDB_ERR_IO; + return -1; + } + memcpy(&tdb->header, &header, sizeof(header)); + } + +#if TDB_DEBUG + printf("initialised database of hash_size %u\n", + hash_size); +#endif + return 0; +} + +/* Returns 0 on fail. On success, return offset of record, and fills + in rec */ +static tdb_off tdb_find(TDB_CONTEXT *tdb, TDB_DATA key, unsigned int hash, + struct list_struct *rec) +{ + tdb_off offset, rec_ptr; + + /* find the top of the hash chain */ + offset = tdb_hash_top(tdb, hash); + + /* read in the hash top */ + if (ofs_read(tdb, offset, &rec_ptr) == -1) + return 0; + + /* keep looking until we find the right record */ + while (rec_ptr) { + if (rec_read(tdb, rec_ptr, rec) == -1) + return 0; + + if (hash == rec->full_hash && key.dsize == rec->key_len) { + char *k; + /* a very likely hit - read the key */ + k = tdb_alloc_read(tdb, rec_ptr + sizeof(*rec), + rec->key_len); + + if (!k) + return 0; + + if (memcmp(key.dptr, k, key.dsize) == 0) { + free(k); + return rec_ptr; + } + free(k); + } + + /* move to the next record */ + rec_ptr = rec->next; + } + return 0; +} + +/* + return an error string for the last tdb error +*/ +char *tdb_errorstr(TDB_CONTEXT *tdb) +{ + int i; + static struct { + enum TDB_ERROR ecode; + char *estring; + } emap[] = { + {TDB_SUCCESS, "Success"}, + {TDB_ERR_CORRUPT, "Corrupt database"}, + {TDB_ERR_IO, "IO Error"}, + {TDB_ERR_LOCK, "Locking error"}, + {TDB_ERR_OOM, "Out of memory"}, + {TDB_ERR_EXISTS, "Record exists"}, + {-1, NULL}}; + if (tdb != NULL) { + for (i=0;emap[i].estring;i++) { + if (tdb->ecode == emap[i].ecode) return emap[i].estring; + } + } else { + return "Invalid tdb context"; + } + return "Invalid error code"; +} + + +/* update an entry in place - this only works if the new data size + is <= the old data size and the key exists. + on failure return -1 +*/ +static int tdb_update(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf) +{ + unsigned hash; + struct list_struct rec; + tdb_off rec_ptr; + int ret = -1; + + if (tdb == NULL) { +#ifdef TDB_DEBUG + printf("tdb_update() called with null context\n"); +#endif + return -1; + } + + /* find which hash bucket it is in */ + hash = tdb_hash(&key); + + tdb_lock(tdb, BUCKET(hash)); + rec_ptr = tdb_find(tdb, key, hash, &rec); + + if (!rec_ptr) + goto out; + + /* must be long enough */ + if (rec.rec_len < key.dsize + dbuf.dsize) + goto out; + + if (tdb_write(tdb, rec_ptr + sizeof(rec) + rec.key_len, + dbuf.dptr, dbuf.dsize) == -1) + goto out; + + if (dbuf.dsize != rec.data_len) { + /* update size */ + rec.data_len = dbuf.dsize; + ret = rec_write(tdb, rec_ptr, &rec); + } else + ret = 0; + + out: + tdb_unlock(tdb, BUCKET(hash)); + return ret; +} + +/* find an entry in the database given a key */ +TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key) +{ + unsigned hash; + tdb_off rec_ptr; + struct list_struct rec; + TDB_DATA ret = null_data; + + if (tdb == NULL) { +#ifdef TDB_DEBUG + printf("tdb_fetch() called with null context\n"); +#endif + return null_data; + } + + /* find which hash bucket it is in */ + hash = tdb_hash(&key); + + tdb_lock(tdb, BUCKET(hash)); + rec_ptr = tdb_find(tdb, key, hash, &rec); + + if (rec_ptr) { + ret.dptr = tdb_alloc_read(tdb, + rec_ptr + sizeof(rec) + rec.key_len, + rec.data_len); + ret.dsize = rec.data_len; + } + + tdb_unlock(tdb, BUCKET(hash)); + return ret; +} + +/* check if an entry in the database exists + + note that 1 is returned if the key is found and 0 is returned if not found + this doesn't match the conventions in the rest of this module, but is + compatible with gdbm +*/ +int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key) +{ + unsigned hash; + tdb_off rec_ptr; + struct list_struct rec; + + if (tdb == NULL) { +#ifdef TDB_DEBUG + printf("tdb_exists() called with null context\n"); +#endif + return 0; + } + + /* find which hash bucket it is in */ + hash = tdb_hash(&key); + + tdb_lock(tdb, BUCKET(hash)); + rec_ptr = tdb_find(tdb, key, hash, &rec); + tdb_unlock(tdb, BUCKET(hash)); + + return rec_ptr != 0; +} + +/* traverse the entire database - calling fn(tdb, key, data) on each element. + return -1 on error or the record count traversed + if fn is NULL then it is not called + a non-zero return value from fn() indicates that the traversal should stop + */ +int tdb_traverse(TDB_CONTEXT *tdb, int (*fn)(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void* state), void* state) +{ + int count = 0; + unsigned h; + tdb_off offset, rec_ptr; + struct list_struct rec; + char *data; + TDB_DATA key, dbuf; + + if (tdb == NULL) { +#ifdef TDB_DEBUG + printf("tdb_traverse() called with null context\n"); +#endif + return -1; + } + + /* loop over all hash chains */ + for (h = 0; h < tdb->header.hash_size; h++) { + tdb_lock(tdb, BUCKET(h)); + + /* read in the hash top */ + offset = tdb_hash_top(tdb, h); + if (ofs_read(tdb, offset, &rec_ptr) == -1) { + goto fail; + } + + /* traverse all records for this hash */ + while (rec_ptr) { + if (rec_read(tdb, rec_ptr, &rec) == -1) { + goto fail; + } + + /* now read the full record */ + data = tdb_alloc_read(tdb, rec_ptr + sizeof(rec), + rec.key_len + rec.data_len); + if (!data) { + goto fail; + } + + key.dptr = data; + key.dsize = rec.key_len; + dbuf.dptr = data + rec.key_len; + dbuf.dsize = rec.data_len; + count++; + + if (fn && fn(tdb, key, dbuf, state) != 0) { + /* they want us to stop traversing */ + free(data); + tdb_unlock(tdb, BUCKET(h)); + return count; + } + + /* a miss - drat */ + free(data); + + /* move to the next record */ + rec_ptr = rec.next; + } + tdb_unlock(tdb, BUCKET(h)); + } + + /* return the number traversed */ + return count; + + fail: + tdb_unlock(tdb, BUCKET(h)); + return -1; +} + + +/* find the first entry in the database and return its key */ +TDB_DATA tdb_firstkey(TDB_CONTEXT *tdb) +{ + tdb_off offset, rec_ptr; + struct list_struct rec; + unsigned hash; + TDB_DATA ret; + + if (tdb == NULL) { +#ifdef TDB_DEBUG + printf("tdb_firstkey() called with null context\n"); +#endif + return null_data; + } + + /* look for a non-empty hash chain */ + for (hash = 0, rec_ptr = 0; + hash < tdb->header.hash_size; + hash++) { + /* find the top of the hash chain */ + offset = tdb_hash_top(tdb, hash); + + tdb_lock(tdb, BUCKET(hash)); + + /* read in the hash top */ + if (ofs_read(tdb, offset, &rec_ptr) == -1) { + goto fail; + } + + if (rec_ptr) break; + + tdb_unlock(tdb, BUCKET(hash)); + } + + if (rec_ptr == 0) return null_data; + + /* we've found a non-empty chain, now read the record */ + if (rec_read(tdb, rec_ptr, &rec) == -1) { + goto fail; + } + + /* allocate and read the key space */ + ret.dptr = tdb_alloc_read(tdb, rec_ptr + sizeof(rec), rec.key_len); + ret.dsize = rec.key_len; + tdb_unlock(tdb, BUCKET(hash)); + return ret; + + fail: + tdb_unlock(tdb, BUCKET(hash)); + return null_data; +} + +/* find the next entry in the database, returning its key */ +TDB_DATA tdb_nextkey(TDB_CONTEXT *tdb, TDB_DATA key) +{ + unsigned hash, hbucket; + tdb_off rec_ptr, offset; + struct list_struct rec; + TDB_DATA ret; + + if (tdb == NULL) { +#ifdef TDB_DEBUG + printf("tdb_nextkey() called with null context\n"); +#endif + return null_data; + } + + /* find which hash bucket it is in */ + hash = tdb_hash(&key); + hbucket = BUCKET(hash); + + tdb_lock(tdb, hbucket); + rec_ptr = tdb_find(tdb, key, hash, &rec); + if (rec_ptr) { + /* we want the next record after this one */ + rec_ptr = rec.next; + } + + /* not found or last in hash: look for next non-empty hash chain */ + while (rec_ptr == 0) { + tdb_unlock(tdb, hbucket); + + if (++hbucket >= tdb->header.hash_size - 1) + return null_data; + + offset = tdb_hash_top(tdb, hbucket); + tdb_lock(tdb, hbucket); + /* read in the hash top */ + if (ofs_read(tdb, offset, &rec_ptr) == -1) { + tdb_unlock(tdb, hbucket); + return null_data; + } + } + + /* Read the record. */ + if (rec_read(tdb, rec_ptr, &rec) == -1) { + tdb_unlock(tdb, hbucket); + return null_data; + } + /* allocate and read the key */ + ret.dptr = tdb_alloc_read(tdb, rec_ptr + sizeof(rec), rec.key_len); + ret.dsize = rec.key_len; + tdb_unlock(tdb, hbucket); + + return ret; +} + +/* delete an entry in the database given a key */ +int tdb_delete(TDB_CONTEXT *tdb, TDB_DATA key) +{ + unsigned hash; + tdb_off offset, rec_ptr, last_ptr; + struct list_struct rec, lastrec; + char *data = NULL; + + if (tdb == NULL) { +#ifdef TDB_DEBUG + printf("tdb_delete() called with null context\n"); +#endif + return -1; + } + + /* find which hash bucket it is in */ + hash = tdb_hash(&key); + + tdb_lock(tdb, BUCKET(hash)); + + /* find the top of the hash chain */ + offset = tdb_hash_top(tdb, hash); + + /* read in the hash top */ + if (ofs_read(tdb, offset, &rec_ptr) == -1) { + goto fail; + } + + last_ptr = 0; + + /* keep looking until we find the right record */ + while (rec_ptr) { + if (rec_read(tdb, rec_ptr, &rec) == -1) { + goto fail; + } + + if (hash == rec.full_hash && key.dsize == rec.key_len) { + /* a very likely hit - read the record and full key */ + data = tdb_alloc_read(tdb, rec_ptr + sizeof(rec), + rec.key_len); + if (!data) { + goto fail; + } + + if (memcmp(key.dptr, data, key.dsize) == 0) { + /* a definite match - delete it */ + if (last_ptr == 0) { + offset = tdb_hash_top(tdb, hash); + if (ofs_write(tdb, offset, &rec.next) == -1) { + goto fail; + } + } else { + lastrec.next = rec.next; + if (rec_write(tdb, last_ptr, &lastrec) == -1) { + goto fail; + } + } + tdb_unlock(tdb, BUCKET(hash)); + tdb_lock(tdb, -1); + /* and recover the space */ + offset = FREELIST_TOP; + if (ofs_read(tdb, offset, &rec.next) == -1) { + goto fail2; + } + rec.magic = TDB_FREE_MAGIC; + if (rec_write(tdb, rec_ptr, &rec) == -1) { + goto fail2; + } + if (ofs_write(tdb, offset, &rec_ptr) == -1) { + goto fail2; + } + + /* yipee - all done */ + free(data); + tdb_unlock(tdb, -1); + return 0; + } + + /* a miss - drat */ + free(data); + data = NULL; + } + + /* move to the next record */ + last_ptr = rec_ptr; + lastrec = rec; + rec_ptr = rec.next; + } + + fail: + if (data) free(data); + tdb_unlock(tdb, BUCKET(hash)); + return -1; + + fail2: + if (data) free(data); + tdb_unlock(tdb, -1); + return -1; +} + + +/* store an element in the database, replacing any existing element + with the same key + + return 0 on success, -1 on failure +*/ +int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag) +{ + struct list_struct rec; + unsigned hash; + tdb_off rec_ptr, offset; + char *p = NULL; + + if (tdb == NULL) { +#ifdef TDB_DEBUG + printf("tdb_store() called with null context\n"); +#endif + return -1; + } + + /* find which hash bucket it is in */ + hash = tdb_hash(&key); + + /* check for it existing */ + if (flag == TDB_INSERT && tdb_exists(tdb, key)) { + tdb->ecode = TDB_ERR_EXISTS; + return -1; + } + + /* first try in-place update */ + if (flag != TDB_INSERT && tdb_update(tdb, key, dbuf) == 0) { + return 0; + } + + rec_ptr = tdb_allocate(tdb, key.dsize + dbuf.dsize); + if (rec_ptr == 0) { + return -1; + } + + tdb_lock(tdb, BUCKET(hash)); + + /* delete any existing record - if it doesn't exist we don't care */ + if (flag != TDB_INSERT) { + tdb_delete(tdb, key); + } + + /* read the newly created record */ + if (tdb_read(tdb, rec_ptr, (char *)&rec, sizeof(rec)) == -1) { + goto fail; + } + + if (rec.magic != TDB_FREE_MAGIC) goto fail; + + /* find the top of the hash chain */ + offset = tdb_hash_top(tdb, hash); + + /* read in the hash top diretcly into our next pointer */ + if (ofs_read(tdb, offset, &rec.next) == -1) { + goto fail; + } + + rec.key_len = key.dsize; + rec.data_len = dbuf.dsize; + rec.full_hash = hash; + rec.magic = TDB_MAGIC; + + p = (char *)malloc(sizeof(rec) + key.dsize + dbuf.dsize); + if (!p) { + tdb->ecode = TDB_ERR_OOM; + goto fail; + } + + memcpy(p, &rec, sizeof(rec)); + memcpy(p+sizeof(rec), key.dptr, key.dsize); + memcpy(p+sizeof(rec)+key.dsize, dbuf.dptr, dbuf.dsize); + + if (tdb_write(tdb, rec_ptr, p, sizeof(rec)+key.dsize+dbuf.dsize) == -1) + goto fail; + + free(p); + p = NULL; + + /* and point the top of the hash chain at it */ + if (ofs_write(tdb, offset, &rec_ptr) == -1) goto fail; + + tdb_unlock(tdb, BUCKET(hash)); + return 0; + + fail: +#if TDB_DEBUG + printf("store failed for hash 0x%08x in bucket %u\n", hash, BUCKET(hash)); +#endif + if (p) free(p); + tdb_unlock(tdb, BUCKET(hash)); + return -1; +} + + +/* open the database, creating it if necessary + + The open_flags and mode are passed straight to the open call on the database + file. A flags value of O_WRONLY is invalid + + The hash size is advisory, use zero for a default value. + + return is NULL on error +*/ +TDB_CONTEXT *tdb_open(char *name, int hash_size, int tdb_flags, + int open_flags, mode_t mode) +{ + TDB_CONTEXT tdb, *ret; + struct stat st; + + memset(&tdb, 0, sizeof(tdb)); + + tdb.fd = -1; + tdb.name = NULL; + tdb.map_ptr = NULL; + + if ((open_flags & O_ACCMODE) == O_WRONLY) { + goto fail; + } + + if (hash_size == 0) hash_size = DEFAULT_HASH_SIZE; + + tdb.read_only = ((open_flags & O_ACCMODE) == O_RDONLY); + + if (name != NULL) { + tdb.fd = open(name, open_flags, mode); + if (tdb.fd == -1) { + goto fail; + } + } + + /* ensure there is only one process initialising at once */ + tdb_brlock(&tdb, GLOBAL_LOCK, LOCK_SET, F_WRLCK, F_SETLKW); + + if (tdb_flags & TDB_CLEAR_IF_FIRST) { + /* we need to zero the database if we are the only + one with it open */ + if (tdb_brlock(&tdb, ACTIVE_LOCK, LOCK_SET, F_WRLCK, F_SETLK) == 0) { + ftruncate(tdb.fd, 0); + tdb_brlock(&tdb, ACTIVE_LOCK, LOCK_CLEAR, F_WRLCK, F_SETLK); + } + } + + /* leave this lock in place */ + tdb_brlock(&tdb, ACTIVE_LOCK, LOCK_SET, F_RDLCK, F_SETLKW); + + if (read(tdb.fd, &tdb.header, sizeof(tdb.header)) != sizeof(tdb.header) || + strcmp(tdb.header.magic_food, TDB_MAGIC_FOOD) != 0 || + tdb.header.version != TDB_VERSION) { + /* its not a valid database - possibly initialise it */ + if (!(open_flags & O_CREAT)) { + goto fail; + } + if (tdb_new_database(&tdb, hash_size) == -1) goto fail; + + lseek(tdb.fd, 0, SEEK_SET); + if (tdb.fd != -1 && read(tdb.fd, &tdb.header, + sizeof(tdb.header)) != + sizeof(tdb.header)) + goto fail; + } + + if (tdb.fd != -1) { + fstat(tdb.fd, &st); + + /* map the database and fill in the return structure */ + tdb.name = name ? strdup(name) : NULL; + tdb.map_size = st.st_size; + } + + tdb.locked = (int *)calloc(tdb.header.hash_size+1, + sizeof(tdb.locked[0])); + if (!tdb.locked) { + goto fail; + } + +#if HAVE_MMAP + if (tdb.fd != -1) { + tdb.map_ptr = (void *)mmap(NULL, st.st_size, + tdb.read_only? PROT_READ : PROT_READ|PROT_WRITE, + MAP_SHARED | MAP_FILE, tdb.fd, 0); + } +#endif + + ret = (TDB_CONTEXT *)malloc(sizeof(tdb)); + if (!ret) goto fail; + + *ret = tdb; + +#if TDB_DEBUG + printf("mapped database of hash_size %u map_size=%u\n", + hash_size, tdb.map_size); +#endif + + tdb_brlock(&tdb, GLOBAL_LOCK, LOCK_CLEAR, F_WRLCK, F_SETLKW); + return ret; + + fail: + if (tdb.name) free(tdb.name); + if (tdb.fd != -1) close(tdb.fd); + if (tdb.map_ptr) munmap(tdb.map_ptr, tdb.map_size); + + return NULL; +} + +/* close a database */ +int tdb_close(TDB_CONTEXT *tdb) +{ + if (!tdb) return -1; + + if (tdb->name) free(tdb->name); + if (tdb->fd != -1) close(tdb->fd); + if (tdb->locked) free(tdb->locked); + + if (tdb->map_ptr) { + if (tdb->fd != -1) { + munmap(tdb->map_ptr, tdb->map_size); + } else { + free(tdb->map_ptr); + } + } + + memset(tdb, 0, sizeof(*tdb)); + free(tdb); + + return 0; +} + +/* lock the database. If we already have it locked then don't do anything */ +int tdb_writelock(TDB_CONTEXT *tdb) +{ + if (tdb == NULL) { +#ifdef TDB_DEBUG + printf("tdb_writelock() called with null context\n"); +#endif + return -1; + } + + return tdb_lock(tdb, -1); +} + +/* unlock the database. */ +int tdb_writeunlock(TDB_CONTEXT *tdb) +{ + if (tdb == NULL) { +#ifdef TDB_DEBUG + printf("tdb_writeunlock() called with null context\n"); +#endif + return -1; + } + + return tdb_unlock(tdb, -1); +} + +int tdb_chainlock(TDB_CONTEXT *tdb, TDB_DATA key) +{ + if (tdb == NULL) { +#ifdef TDB_DEBUG + printf("tdb_lockchain() called with null context\n"); +#endif + return -1; + } + + return tdb_lock(tdb, BUCKET(tdb_hash(&key))); +} + + +int tdb_chainunlock(TDB_CONTEXT *tdb, TDB_DATA key) +{ + if (tdb == NULL) { +#ifdef TDB_DEBUG + printf("tdb_unlockchain() called with null context\n"); +#endif + return -1; + } + + return tdb_unlock(tdb, BUCKET(tdb_hash(&key))); +} diff --git a/external/bsd/ppp/usr.sbin/pppd/tdb.h b/external/bsd/ppp/usr.sbin/pppd/tdb.h new file mode 100644 index 000000000000..06884792108b --- /dev/null +++ b/external/bsd/ppp/usr.sbin/pppd/tdb.h @@ -0,0 +1,79 @@ +#define STANDALONE 1 +/* + * Database functions + * Copyright (C) Andrew Tridgell 1999 + * + * 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 provided that this software or + * any derived work is only used as part of the PPP daemon (pppd) + * and related utilities. + * The name of the author 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. + * + * Note: this software is also available under the Gnu Public License + * version 2 or later. + */ + +typedef unsigned tdb_len; +typedef unsigned tdb_off; + +#define TDB_MAGIC_FOOD "TDB file\n" + +/* this is stored at the front of every database */ +struct tdb_header { + char magic_food[32]; /* for /etc/magic */ + unsigned version; /* version of the code */ + unsigned hash_size; /* number of hash entries */ +}; + +typedef struct { + char *dptr; + size_t dsize; +} TDB_DATA; + +/* this is the context structure that is returned from a db open */ +typedef struct { + char *name; /* the name of the database */ + void *map_ptr; /* where it is currently mapped */ + int fd; /* open file descriptor for the database */ + tdb_len map_size; /* how much space has been mapped */ + int read_only; /* opened read-only */ + int *locked; /* set if we have a chain locked */ + int ecode; /* error code for last tdb error */ + struct tdb_header header; /* a cached copy of the header */ +} TDB_CONTEXT; + +/* flags to tdb_store() */ +#define TDB_REPLACE 1 +#define TDB_INSERT 2 + +/* flags for tdb_open() */ +#define TDB_CLEAR_IF_FIRST 1 + +/* error codes */ +enum TDB_ERROR {TDB_SUCCESS=0, TDB_ERR_CORRUPT, TDB_ERR_IO, TDB_ERR_LOCK, + TDB_ERR_OOM, TDB_ERR_EXISTS}; + +#if STANDALONE +TDB_CONTEXT *tdb_open(char *name, int hash_size, int tdb_flags, + int open_flags, mode_t mode); +char *tdb_errorstr(TDB_CONTEXT *tdb); +int tdb_writelock(TDB_CONTEXT *tdb); +int tdb_writeunlock(TDB_CONTEXT *tdb); +TDB_DATA tdb_fetch(TDB_CONTEXT *tdb, TDB_DATA key); +int tdb_delete(TDB_CONTEXT *tdb, TDB_DATA key); +int tdb_store(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, int flag); +int tdb_close(TDB_CONTEXT *tdb); +TDB_DATA tdb_firstkey(TDB_CONTEXT *tdb); +TDB_DATA tdb_nextkey(TDB_CONTEXT *tdb, TDB_DATA key); +int tdb_traverse(TDB_CONTEXT *tdb, + int (*fn)(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state), + void *state); +int tdb_exists(TDB_CONTEXT *tdb, TDB_DATA key); +int tdb_chainlock(TDB_CONTEXT *tdb, TDB_DATA key); +int tdb_chainunlock(TDB_CONTEXT *tdb, TDB_DATA key); +#endif diff --git a/external/bsd/ppp/usr.sbin/pppdump/Makefile b/external/bsd/ppp/usr.sbin/pppdump/Makefile new file mode 100644 index 000000000000..fce18c67bdfd --- /dev/null +++ b/external/bsd/ppp/usr.sbin/pppdump/Makefile @@ -0,0 +1,14 @@ +# $NetBSD: Makefile,v 1.1 2013/11/28 22:33:43 christos Exp $ + +.include "../Makefile.inc" + +.PATH: ${DIST}/pppdump ${NETBSDSRCDIR}/sys/net + +PROG= pppdump +SRCS= pppdump.c deflate.c bsd-comp.c zlib.c +MAN= pppdump.8 + +CPPFLAGS+= -I${NETBSDSRCDIR}/sys/net -I${.CURDIR} +CPPFLAGS+= -DDO_BSD_COMPRESS -DDO_DEFLATE + +.include diff --git a/external/bsd/ppp/usr.sbin/pppdump/pppdump.h b/external/bsd/ppp/usr.sbin/pppdump/pppdump.h new file mode 100644 index 000000000000..25b7fc6de527 --- /dev/null +++ b/external/bsd/ppp/usr.sbin/pppdump/pppdump.h @@ -0,0 +1,37 @@ +/* $NetBSD: pppdump.h,v 1.1 2013/11/28 22:33:43 christos Exp $ */ + +/*- + * Copyright (c) 2002 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +struct packet { + u_char *buf; + int len; +}; + +#define PACKETPTR struct packet * diff --git a/external/bsd/ppp/usr.sbin/pppstats/Makefile b/external/bsd/ppp/usr.sbin/pppstats/Makefile new file mode 100644 index 000000000000..2d362294ed18 --- /dev/null +++ b/external/bsd/ppp/usr.sbin/pppstats/Makefile @@ -0,0 +1,12 @@ +# $NetBSD: Makefile,v 1.1 2013/11/28 22:33:43 christos Exp $ + +.include "../Makefile.inc" + +.PATH: ${DIST}/pppstats + +PROG= pppstats +MAN= pppstats.8 +LINKS= ${BINDIR}/pppstats ${BINDIR}/slstats +MLINKS= pppstats.8 slstats.8 + +.include