xref: /onnv-gate/usr/src/cmd/cmd-inet/usr.lib/in.dhcpd/logging.c (revision 7240:c4957ab6a78e)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7240Srh87107  * Common Development and Distribution License (the "License").
6*7240Srh87107  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*7240Srh87107  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*7240Srh87107  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <stdio.h>
290Sstevel@tonic-gate #include <stdlib.h>
300Sstevel@tonic-gate #include <ctype.h>
310Sstevel@tonic-gate #include <syslog.h>
320Sstevel@tonic-gate #include <stdarg.h>
330Sstevel@tonic-gate #include <sys/types.h>
340Sstevel@tonic-gate #include <sys/socket.h>
350Sstevel@tonic-gate #include <net/if.h>
360Sstevel@tonic-gate #include <netinet/in.h>
370Sstevel@tonic-gate #include <netinet/if_ether.h>
380Sstevel@tonic-gate #include <arpa/inet.h>
390Sstevel@tonic-gate #include <netinet/dhcp.h>
400Sstevel@tonic-gate #include <netdb.h>
410Sstevel@tonic-gate #include "dhcpd.h"
420Sstevel@tonic-gate 
430Sstevel@tonic-gate static char	*dhcp_msg_cats[] = {
440Sstevel@tonic-gate 	/* L_ASSIGN */		"ASSIGN",
450Sstevel@tonic-gate 	/* L_REPLY */		"EXTEND",
460Sstevel@tonic-gate 	/* L_RELEASE */		"RELEASE",
470Sstevel@tonic-gate 	/* L_DECLINE */		"DECLINE",
480Sstevel@tonic-gate 	/* L_INFORM */		"INFORM",
490Sstevel@tonic-gate 	/* L_NAK */		"NAK",
500Sstevel@tonic-gate 	/* L_ICMP_ECHO */	"ICMP-ECHO",
510Sstevel@tonic-gate 	/* L_RELAY_REQ */	"RELAY-SRVR",
520Sstevel@tonic-gate 	/* L_RELAY_REP */	"RELAY-CLNT"
530Sstevel@tonic-gate };
540Sstevel@tonic-gate 
550Sstevel@tonic-gate static char	*protos[] = {
560Sstevel@tonic-gate 	/* P_BOOTP */		"BOOTP",
570Sstevel@tonic-gate 	/* P_DHCP */		"DHCP"
580Sstevel@tonic-gate };
590Sstevel@tonic-gate 
600Sstevel@tonic-gate /*
610Sstevel@tonic-gate  * Transaction logging. Note - if we're in debug mode, the transactions
620Sstevel@tonic-gate  * are logged to the console!
630Sstevel@tonic-gate  *
640Sstevel@tonic-gate  * 'cip' and 'sip' are expected in network order.
650Sstevel@tonic-gate  */
660Sstevel@tonic-gate void
logtrans(DHCP_PROTO p,DHCP_MSG_CATEGORIES type,time_t lease,struct in_addr cip,struct in_addr sip,PKT_LIST * plp)670Sstevel@tonic-gate logtrans(DHCP_PROTO p, DHCP_MSG_CATEGORIES type, time_t lease,
680Sstevel@tonic-gate     struct in_addr cip, struct in_addr sip, PKT_LIST *plp)
690Sstevel@tonic-gate {
700Sstevel@tonic-gate 	char	*cat, *proto, *t, *class_id;
710Sstevel@tonic-gate 	uint_t	maclen;
720Sstevel@tonic-gate 	char	class_idbuf[DHCP_MAX_OPT_SIZE];
730Sstevel@tonic-gate 	char	cidbuf[DHCP_MAX_OPT_SIZE];
740Sstevel@tonic-gate 	char	ntoabc[INET_ADDRSTRLEN], ntoabs[INET_ADDRSTRLEN];
750Sstevel@tonic-gate 	char	macbuf[(sizeof (((PKT *)NULL)->chaddr) * 2) + 1];
760Sstevel@tonic-gate 
770Sstevel@tonic-gate 	if (log_local < 0)
780Sstevel@tonic-gate 		return;
790Sstevel@tonic-gate 
800Sstevel@tonic-gate 	proto = protos[p];
810Sstevel@tonic-gate 	cat = dhcp_msg_cats[type];
820Sstevel@tonic-gate 
830Sstevel@tonic-gate 	(void) disp_cid(plp, cidbuf, sizeof (cidbuf));
840Sstevel@tonic-gate 
850Sstevel@tonic-gate 	class_id = get_class_id(plp, class_idbuf, sizeof (class_idbuf));
860Sstevel@tonic-gate 
870Sstevel@tonic-gate 	/* convert white space in class id into periods (.) */
880Sstevel@tonic-gate 	if (class_id != NULL) {
890Sstevel@tonic-gate 		for (t = class_id; *t != '\0'; t++) {
900Sstevel@tonic-gate 			if (isspace(*t))
910Sstevel@tonic-gate 				*t = '.';
920Sstevel@tonic-gate 		}
930Sstevel@tonic-gate 	} else
940Sstevel@tonic-gate 		class_id = "N/A";
950Sstevel@tonic-gate 
960Sstevel@tonic-gate 	maclen = sizeof (macbuf);
970Sstevel@tonic-gate 	macbuf[0] = '\0';
980Sstevel@tonic-gate 	(void) octet_to_hexascii(plp->pkt->chaddr, plp->pkt->hlen, macbuf,
990Sstevel@tonic-gate 	    &maclen);
1000Sstevel@tonic-gate 
101*7240Srh87107 	dhcpmsg(log_local | LOG_NOTICE, "%s %s %010ld %010ld %s %s %s %s %s\n",
1020Sstevel@tonic-gate 	    proto, cat, time(NULL), lease,
1030Sstevel@tonic-gate 	    inet_ntop(AF_INET, &cip, ntoabc, sizeof (ntoabc)),
1040Sstevel@tonic-gate 	    inet_ntop(AF_INET, &sip, ntoabs, sizeof (ntoabs)),
1050Sstevel@tonic-gate 	    cidbuf, class_id, macbuf);
1060Sstevel@tonic-gate }
107