From 1038894eb08ab9fe9df118a397394f4877a742ea Mon Sep 17 00:00:00 2001 From: Brian Somers Date: Wed, 19 Jul 2000 02:10:35 +0000 Subject: [PATCH] Support link identification from rfc1570 Two new commands are available; ``ident'' and ``sendident''. --- usr.sbin/ppp/acf.c | 2 +- usr.sbin/ppp/cbcp.c | 2 +- usr.sbin/ppp/ccp.c | 4 ++-- usr.sbin/ppp/chap.c | 2 +- usr.sbin/ppp/command.c | 33 ++++++++++++++++++++++++++++++++- usr.sbin/ppp/datalink.c | 2 +- usr.sbin/ppp/deflate.c | 2 ++ usr.sbin/ppp/fsm.c | 40 ++++++++++++++++++++++++++++++++-------- usr.sbin/ppp/ipcp.c | 2 +- usr.sbin/ppp/lcp.c | 40 +++++++++++++++++++++++++++++++++++++++- usr.sbin/ppp/lcp.h | 5 ++++- usr.sbin/ppp/lqr.c | 2 +- usr.sbin/ppp/pap.c | 2 +- usr.sbin/ppp/ppp.8 | 28 ++++++++++++++++++++++++++++ usr.sbin/ppp/ppp.8.m4 | 28 ++++++++++++++++++++++++++++ usr.sbin/ppp/prompt.c | 2 +- usr.sbin/ppp/proto.c | 2 +- 17 files changed, 176 insertions(+), 22 deletions(-) diff --git a/usr.sbin/ppp/acf.c b/usr.sbin/ppp/acf.c index 9e2b63b18732..4db0b6b264d8 100644 --- a/usr.sbin/ppp/acf.c +++ b/usr.sbin/ppp/acf.c @@ -39,10 +39,10 @@ #include "mbuf.h" #include "acf.h" #include "proto.h" -#include "lcp.h" #include "throughput.h" #include "lqr.h" #include "hdlc.h" +#include "lcp.h" #include "ccp.h" #include "link.h" #include "descriptor.h" diff --git a/usr.sbin/ppp/cbcp.c b/usr.sbin/ppp/cbcp.c index 02505945ad7f..8e9025a2abf8 100644 --- a/usr.sbin/ppp/cbcp.c +++ b/usr.sbin/ppp/cbcp.c @@ -41,9 +41,9 @@ #include "lqr.h" #include "mbuf.h" #include "fsm.h" -#include "lcp.h" #include "throughput.h" #include "hdlc.h" +#include "lcp.h" #include "ccp.h" #include "link.h" #include "async.h" diff --git a/usr.sbin/ppp/ccp.c b/usr.sbin/ppp/ccp.c index 8ea977521eaf..e7df030ecc3d 100644 --- a/usr.sbin/ppp/ccp.c +++ b/usr.sbin/ppp/ccp.c @@ -41,8 +41,6 @@ #include "timer.h" #include "fsm.h" #include "proto.h" -#include "lcp.h" -#include "ccp.h" #include "pred.h" #include "deflate.h" #include "throughput.h" @@ -50,6 +48,8 @@ #include "slcompress.h" #include "lqr.h" #include "hdlc.h" +#include "lcp.h" +#include "ccp.h" #include "ipcp.h" #include "filter.h" #include "descriptor.h" diff --git a/usr.sbin/ppp/chap.c b/usr.sbin/ppp/chap.c index aee866a42752..07e69c130ffd 100644 --- a/usr.sbin/ppp/chap.c +++ b/usr.sbin/ppp/chap.c @@ -49,9 +49,9 @@ #include "timer.h" #include "fsm.h" #include "proto.h" -#include "lcp.h" #include "lqr.h" #include "hdlc.h" +#include "lcp.h" #include "auth.h" #include "async.h" #include "throughput.h" diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c index 2553f42a98d9..35e582e53c75 100644 --- a/usr.sbin/ppp/command.c +++ b/usr.sbin/ppp/command.c @@ -61,12 +61,12 @@ #include "log.h" #include "timer.h" #include "fsm.h" -#include "lcp.h" #include "iplist.h" #include "throughput.h" #include "slcompress.h" #include "lqr.h" #include "hdlc.h" +#include "lcp.h" #include "ipcp.h" #ifndef NONAT #include "nat_cmd.h" @@ -241,6 +241,31 @@ HelpCommand(struct cmdargs const *arg) return 0; } +static int +IdentCommand(struct cmdargs const *arg) +{ + int f, pos; + + *arg->cx->physical->link.lcp.cfg.ident = '\0'; + + for (pos = 0, f = arg->argn; f < arg->argc; f++) + pos += snprintf(arg->cx->physical->link.lcp.cfg.ident + pos, + sizeof arg->cx->physical->link.lcp.cfg.ident - pos, "%s%s", + f == arg->argn ? "" : " ", arg->argv[f]); + + return 0; +} + +static int +SendIdentification(struct cmdargs const *arg) +{ + if (arg->cx->state < DATALINK_LCP) { + log_Printf(LogWARN, "sendident: link has not reached LCP\n"); + return 2; + } + return lcp_SendIdentification(&arg->cx->physical->link.lcp) ? 0 : 1; +} + static int CloneCommand(struct cmdargs const *arg) { @@ -441,6 +466,8 @@ command_Expand(char **nargv, int argc, char const *const *oargv, inet_ntoa(bundle->ncp.ipcp.ns.dns[0])); nargv[arg] = subst(nargv[arg], "DNS1", inet_ntoa(bundle->ncp.ipcp.ns.dns[1])); + nargv[arg] = subst(nargv[arg], "VERSION", Version); + nargv[arg] = subst(nargv[arg], "COMPILATIONDATE", __DATE__); } nargv[arg] = NULL; } @@ -681,6 +708,8 @@ static struct cmdtab const Commands[] = { "Generate a down event", "down [ccp|lcp]"}, {"enable", NULL, NegotiateCommand, LOCAL_AUTH | LOCAL_CX_OPT, "Enable option", "enable option .."}, + {"ident", NULL, IdentCommand, LOCAL_AUTH | LOCAL_CX, + "Set the link identity", "ident text..."}, {"iface", "interface", RunListCommand, LOCAL_AUTH, "interface control", "iface option ...", IfaceCommands}, {"link", "datalink", LinkCommand, LOCAL_AUTH, @@ -705,6 +734,8 @@ static struct cmdtab const Commands[] = { "Manipulate resolv.conf", "resolv readonly|reload|restore|rewrite|writable"}, {"save", NULL, SaveCommand, LOCAL_AUTH, "Save settings", "save"}, + {"sendident", NULL, SendIdentification, LOCAL_AUTH | LOCAL_CX, + "Transmit the link identity", "sendident"}, {"set", "setup", SetCommand, LOCAL_AUTH | LOCAL_CX_OPT, "Set parameters", "set[up] var value"}, {"shell", "!", FgShellCommand, LOCAL_AUTH, diff --git a/usr.sbin/ppp/datalink.c b/usr.sbin/ppp/datalink.c index 3d5bc3604f4b..619c14f46eb7 100644 --- a/usr.sbin/ppp/datalink.c +++ b/usr.sbin/ppp/datalink.c @@ -45,10 +45,10 @@ #include "defs.h" #include "timer.h" #include "fsm.h" -#include "lcp.h" #include "descriptor.h" #include "lqr.h" #include "hdlc.h" +#include "lcp.h" #include "async.h" #include "throughput.h" #include "ccp.h" diff --git a/usr.sbin/ppp/deflate.c b/usr.sbin/ppp/deflate.c index 9478fdda47f4..aacc438710c3 100644 --- a/usr.sbin/ppp/deflate.c +++ b/usr.sbin/ppp/deflate.c @@ -38,6 +38,8 @@ #include "log.h" #include "timer.h" #include "fsm.h" +#include "lqr.h" +#include "hdlc.h" #include "lcp.h" #include "ccp.h" #include "deflate.h" diff --git a/usr.sbin/ppp/fsm.c b/usr.sbin/ppp/fsm.c index 082f95ced32c..80acc33565e7 100644 --- a/usr.sbin/ppp/fsm.c +++ b/usr.sbin/ppp/fsm.c @@ -86,7 +86,7 @@ static const struct fsmcodedesc { { FsmRecvEchoReq, 0, 0, "EchoRequest" }, { FsmRecvEchoRep, 0, 0, "EchoReply" }, { FsmRecvDiscReq, 0, 0, "DiscardReq" }, - { FsmRecvIdent, 0, 0, "Ident" }, + { FsmRecvIdent, 0, 1, "Ident" }, { FsmRecvTimeRemain,0, 0, "TimeRemain" }, { FsmRecvResetReq, 0, 0, "ResetReq" }, { FsmRecvResetAck, 0, 1, "ResetAck" } @@ -208,6 +208,9 @@ fsm_Output(struct fsm *fp, u_int code, u_int id, u_char *ptr, int count, log_DumpBp(LogDEBUG, "fsm_Output", bp); link_PushPacket(fp->link, bp, fp->bundle, LINK_QUEUES(fp->link) - 1, fp->proto); + + if (code == CODE_CONFIGREJ) + lcp_SendIdentification(&fp->link->lcp); } static void @@ -374,6 +377,7 @@ FsmSendConfigReq(struct fsm *fp) if (fp->more.reqs < 0) log_Printf(LogPHASE, "%s: Too many %s REQs sent - abandoning " "negotiation\n", fp->link->name, fp->name); + lcp_SendIdentification(&fp->link->lcp); fsm_Close(fp); } } @@ -562,6 +566,7 @@ FsmRecvConfigReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp) FsmInitRestartCounter(fp, FSM_TRM_TIMER); FsmSendTerminateReq(fp); NewState(fp, ST_CLOSING); + lcp_SendIdentification(&fp->link->lcp); } } break; @@ -575,12 +580,14 @@ FsmRecvConfigReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp) if (dec.rejend != dec.rej && --fp->more.rejs <= 0) { log_Printf(LogPHASE, "%s: Too many %s REJs sent - abandoning negotiation\n", fp->link->name, fp->name); + lcp_SendIdentification(&fp->link->lcp); fsm_Close(fp); } if (dec.nakend != dec.nak && --fp->more.naks <= 0) { log_Printf(LogPHASE, "%s: Too many %s NAKs sent - abandoning negotiation\n", fp->link->name, fp->name); + lcp_SendIdentification(&fp->link->lcp); fsm_Close(fp); } } @@ -615,6 +622,7 @@ FsmRecvConfigAck(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp) FsmInitRestartCounter(fp, FSM_TRM_TIMER); FsmSendTerminateReq(fp); NewState(fp, ST_CLOSING); + lcp_SendIdentification(&fp->link->lcp); } break; case ST_OPENED: @@ -769,6 +777,8 @@ FsmRecvConfigRej(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp) return; } + lcp_SendIdentification(&fp->link->lcp); + /* * Check and process easy case */ @@ -932,6 +942,22 @@ FsmRecvDiscReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp) static void FsmRecvIdent(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp) { + u_int32_t magic; + u_short len; + u_char *cp; + + len = ntohs(lhp->length) - sizeof *lhp; + if (len >= 4) { + bp = m_pullup(m_append(bp, "", 1)); + cp = MBUF_CTOP(bp); + ua_ntohl(cp, &magic); + if (magic != fp->link->lcp.his_magic) + log_Printf(fp->LogLevel, "%s: RecvIdent: magic 0x%08lx is wrong," + " expecting 0x%08lx\n", fp->link->name, (u_long)magic, + (u_long)fp->link->lcp.his_magic); + cp[len] = '\0'; + lcp_RecvIdentification(&fp->link->lcp, cp + 4); + } m_freem(bp); } @@ -976,13 +1002,11 @@ fsm_Input(struct fsm *fp, struct mbuf *bp) } bp = mbuf_Read(bp, &lh, sizeof lh); - if (ntohs(lh.length) != len) { - if (ntohs(lh.length) > len) { - log_Printf(LogWARN, "%s: Oops: Got %d bytes but %d byte payload " - "- dropped\n", fp->link->name, len, (int)ntohs(lh.length)); - m_freem(bp); - return; - } + if (ntohs(lh.length) > len) { + log_Printf(LogWARN, "%s: Oops: Got %d bytes but %d byte payload " + "- dropped\n", fp->link->name, len, (int)ntohs(lh.length)); + m_freem(bp); + return; } if (lh.code < fp->min_code || lh.code > fp->max_code || diff --git a/usr.sbin/ppp/ipcp.c b/usr.sbin/ppp/ipcp.c index f7a632a590a4..2fafac1da1c6 100644 --- a/usr.sbin/ppp/ipcp.c +++ b/usr.sbin/ppp/ipcp.c @@ -59,12 +59,12 @@ #include "timer.h" #include "fsm.h" #include "proto.h" -#include "lcp.h" #include "iplist.h" #include "throughput.h" #include "slcompress.h" #include "lqr.h" #include "hdlc.h" +#include "lcp.h" #include "ipcp.h" #include "filter.h" #include "descriptor.h" diff --git a/usr.sbin/ppp/lcp.c b/usr.sbin/ppp/lcp.c index a4ebd0782db0..b2b56e05e81c 100644 --- a/usr.sbin/ppp/lcp.c +++ b/usr.sbin/ppp/lcp.c @@ -43,12 +43,12 @@ #include "timer.h" #include "fsm.h" #include "iplist.h" -#include "lcp.h" #include "throughput.h" #include "proto.h" #include "descriptor.h" #include "lqr.h" #include "hdlc.h" +#include "lcp.h" #include "ccp.h" #include "async.h" #include "link.h" @@ -182,6 +182,7 @@ lcp_ReportStatus(struct cmdargs const *arg) " REQ%s, %u Term REQ%s\n", lcp->cfg.fsm.timeout, lcp->cfg.fsm.maxreq, lcp->cfg.fsm.maxreq == 1 ? "" : "s", lcp->cfg.fsm.maxtrm, lcp->cfg.fsm.maxtrm == 1 ? "" : "s"); + prompt_Printf(arg->prompt, " Ident: %s\n", lcp->cfg.ident); prompt_Printf(arg->prompt, "\n Negotiation:\n"); prompt_Printf(arg->prompt, " ACFCOMP = %s\n", command_ShowNegval(lcp->cfg.acfcomp)); @@ -247,6 +248,7 @@ lcp_Init(struct lcp *lcp, struct bundle *bundle, struct link *l, lcp->cfg.lqr = NEG_ACCEPTED; lcp->cfg.pap = NEG_ACCEPTED; lcp->cfg.protocomp = NEG_ENABLED|NEG_ACCEPTED; + *lcp->cfg.ident = '\0'; lcp_Setup(lcp, lcp->cfg.openmode); } @@ -451,6 +453,40 @@ lcp_SendProtoRej(struct lcp *lcp, u_char *option, int count) MB_LCPOUT); } +int +lcp_SendIdentification(struct lcp *lcp) +{ + static u_char id; /* Use a private id */ + u_char msg[DEF_MRU - 3]; + const char *argv[2]; + char *exp[2]; + + if (*lcp->cfg.ident == '\0') + return 0; + + argv[0] = lcp->cfg.ident; + argv[1] = NULL; + + command_Expand(exp, 1, argv, lcp->fsm.bundle, 1, getpid()); + + ua_htonl(&lcp->want_magic, msg); + strncpy(msg + 4, exp[0], sizeof msg - 5); + msg[sizeof msg - 1] = '\0'; + + log_Printf(LogLCP, "Sending ident magic %08x text %s\n", lcp->want_magic, + msg + 4); + fsm_Output(&lcp->fsm, CODE_IDENT, id++, msg, 4 + strlen(msg + 4), MB_LCPOUT); + + free(exp[0]); + return 1; +} + +void +lcp_RecvIdentification(struct lcp *lcp, char *data) +{ + log_Printf(LogLCP, "Received ident: %s\n", data); +} + static void LcpSentTerminateReq(struct fsm *fp) { @@ -500,6 +536,8 @@ LcpLayerUp(struct fsm *fp) hdlc_StartTimer(&p->hdlc); fp->more.reqs = fp->more.naks = fp->more.rejs = lcp->cfg.fsm.maxreq * 3; + lcp_SendIdentification(lcp); + return 1; } diff --git a/usr.sbin/ppp/lcp.h b/usr.sbin/ppp/lcp.h index 06f2ded48daa..5c6d1bb7ea9a 100644 --- a/usr.sbin/ppp/lcp.h +++ b/usr.sbin/ppp/lcp.h @@ -87,10 +87,11 @@ struct lcp { unsigned lqr : 2; /* Link Quality Report */ unsigned pap : 2; /* Password Authentication protocol */ unsigned protocomp : 2; /* Protocol field compression */ + char ident[DEF_MRU - 7]; /* SendIdentification() data */ } cfg; }; -#define LCP_MAXCODE CODE_DISCREQ +#define LCP_MAXCODE CODE_IDENT #define LCP_MINMPCODE CODE_CODEREJ #define TY_MRU 1 /* Maximum-Receive-Unit */ @@ -135,6 +136,8 @@ extern void lcp_Init(struct lcp *, struct bundle *, struct link *, extern void lcp_Setup(struct lcp *, int); extern void lcp_SendProtoRej(struct lcp *, u_char *, int); +extern int lcp_SendIdentification(struct lcp *); +extern void lcp_RecvIdentification(struct lcp *, char *); extern int lcp_ReportStatus(struct cmdargs const *); extern struct mbuf *lcp_Input(struct bundle *, struct link *, struct mbuf *); extern void lcp_SetupCallbacks(struct lcp *); diff --git a/usr.sbin/ppp/lqr.c b/usr.sbin/ppp/lqr.c index dad0e461cfbe..bb3bd03fe4a0 100644 --- a/usr.sbin/ppp/lqr.c +++ b/usr.sbin/ppp/lqr.c @@ -40,9 +40,9 @@ #include "fsm.h" #include "acf.h" #include "proto.h" -#include "lcp.h" #include "lqr.h" #include "hdlc.h" +#include "lcp.h" #include "async.h" #include "throughput.h" #include "ccp.h" diff --git a/usr.sbin/ppp/pap.c b/usr.sbin/ppp/pap.c index 7a7071d7b232..d70e198555e9 100644 --- a/usr.sbin/ppp/pap.c +++ b/usr.sbin/ppp/pap.c @@ -38,11 +38,11 @@ #include "defs.h" #include "timer.h" #include "fsm.h" -#include "lcp.h" #include "auth.h" #include "pap.h" #include "lqr.h" #include "hdlc.h" +#include "lcp.h" #include "proto.h" #include "async.h" #include "throughput.h" diff --git a/usr.sbin/ppp/ppp.8 b/usr.sbin/ppp/ppp.8 index 5050bca34d76..5136fa35832c 100644 --- a/usr.sbin/ppp/ppp.8 +++ b/usr.sbin/ppp/ppp.8 @@ -3404,6 +3404,16 @@ Show a list of available commands. If .Ar command is specified, show the usage string for that command. +.It ident Op Ar text Ns No ... +Identify the link to the peer using +.Ar text . +If +.Ar text +is empty, link identification is disabled. Refer to the +.Ic sendident +command for details of when +.Nm +identifies itself to the peer. .It iface Ar command Op args This command is used to control the interface used by .Nm ppp . @@ -3697,6 +3707,24 @@ command. .El .It save This option is not (yet) implemented. +.It sendident +This command tells +.Nm +to identify itself to the peer. The link must be in LCP state or higher. +If no identity has been set (via the +.Ic ident +command), +.Ic sendident +will fail. +.Pp +When an identity has been set, +.Nm +will automatically identify itself when it sends or receives a configure +reject, when negotiation fails or when LCP reaches the opened state. +.Pp +Received identification packets are logged to the LCP log (see +.Ic set log +for details) and are never responded to. .It set Ns Xo .No Op up .Ar var value diff --git a/usr.sbin/ppp/ppp.8.m4 b/usr.sbin/ppp/ppp.8.m4 index 5050bca34d76..5136fa35832c 100644 --- a/usr.sbin/ppp/ppp.8.m4 +++ b/usr.sbin/ppp/ppp.8.m4 @@ -3404,6 +3404,16 @@ Show a list of available commands. If .Ar command is specified, show the usage string for that command. +.It ident Op Ar text Ns No ... +Identify the link to the peer using +.Ar text . +If +.Ar text +is empty, link identification is disabled. Refer to the +.Ic sendident +command for details of when +.Nm +identifies itself to the peer. .It iface Ar command Op args This command is used to control the interface used by .Nm ppp . @@ -3697,6 +3707,24 @@ command. .El .It save This option is not (yet) implemented. +.It sendident +This command tells +.Nm +to identify itself to the peer. The link must be in LCP state or higher. +If no identity has been set (via the +.Ic ident +command), +.Ic sendident +will fail. +.Pp +When an identity has been set, +.Nm +will automatically identify itself when it sends or receives a configure +reject, when negotiation fails or when LCP reaches the opened state. +.Pp +Received identification packets are logged to the LCP log (see +.Ic set log +for details) and are never responded to. .It set Ns Xo .No Op up .Ar var value diff --git a/usr.sbin/ppp/prompt.c b/usr.sbin/ppp/prompt.c index debd7ca1483b..af333eef130c 100644 --- a/usr.sbin/ppp/prompt.c +++ b/usr.sbin/ppp/prompt.c @@ -49,7 +49,6 @@ #include "descriptor.h" #include "prompt.h" #include "fsm.h" -#include "lcp.h" #include "auth.h" #include "iplist.h" #include "throughput.h" @@ -57,6 +56,7 @@ #include "mbuf.h" #include "lqr.h" #include "hdlc.h" +#include "lcp.h" #include "ipcp.h" #include "filter.h" #include "async.h" diff --git a/usr.sbin/ppp/proto.c b/usr.sbin/ppp/proto.c index 63513b339740..e4719987313a 100644 --- a/usr.sbin/ppp/proto.c +++ b/usr.sbin/ppp/proto.c @@ -39,10 +39,10 @@ #include "fsm.h" #include "mbuf.h" #include "proto.h" -#include "lcp.h" #include "throughput.h" #include "lqr.h" #include "hdlc.h" +#include "lcp.h" #include "ccp.h" #include "link.h"