1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 #pragma ident "%Z%%M% %I% %E% SMI"
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <ctype.h>
31 #include <syslog.h>
32 #include <stdarg.h>
33 #include <sys/types.h>
34 #include <sys/socket.h>
35 #include <net/if.h>
36 #include <netinet/in.h>
37 #include <netinet/if_ether.h>
38 #include <arpa/inet.h>
39 #include <netinet/dhcp.h>
40 #include <netdb.h>
41 #include "dhcpd.h"
42
43 static char *dhcp_msg_cats[] = {
44 /* L_ASSIGN */ "ASSIGN",
45 /* L_REPLY */ "EXTEND",
46 /* L_RELEASE */ "RELEASE",
47 /* L_DECLINE */ "DECLINE",
48 /* L_INFORM */ "INFORM",
49 /* L_NAK */ "NAK",
50 /* L_ICMP_ECHO */ "ICMP-ECHO",
51 /* L_RELAY_REQ */ "RELAY-SRVR",
52 /* L_RELAY_REP */ "RELAY-CLNT"
53 };
54
55 static char *protos[] = {
56 /* P_BOOTP */ "BOOTP",
57 /* P_DHCP */ "DHCP"
58 };
59
60 /*
61 * Transaction logging. Note - if we're in debug mode, the transactions
62 * are logged to the console!
63 *
64 * 'cip' and 'sip' are expected in network order.
65 */
66 void
logtrans(DHCP_PROTO p,DHCP_MSG_CATEGORIES type,time_t lease,struct in_addr cip,struct in_addr sip,PKT_LIST * plp)67 logtrans(DHCP_PROTO p, DHCP_MSG_CATEGORIES type, time_t lease,
68 struct in_addr cip, struct in_addr sip, PKT_LIST *plp)
69 {
70 char *cat, *proto, *t, *class_id;
71 uint_t maclen;
72 char class_idbuf[DHCP_MAX_OPT_SIZE];
73 char cidbuf[DHCP_MAX_OPT_SIZE];
74 char ntoabc[INET_ADDRSTRLEN], ntoabs[INET_ADDRSTRLEN];
75 char macbuf[(sizeof (((PKT *)NULL)->chaddr) * 2) + 1];
76
77 if (log_local < 0)
78 return;
79
80 proto = protos[p];
81 cat = dhcp_msg_cats[type];
82
83 (void) disp_cid(plp, cidbuf, sizeof (cidbuf));
84
85 class_id = get_class_id(plp, class_idbuf, sizeof (class_idbuf));
86
87 /* convert white space in class id into periods (.) */
88 if (class_id != NULL) {
89 for (t = class_id; *t != '\0'; t++) {
90 if (isspace(*t))
91 *t = '.';
92 }
93 } else
94 class_id = "N/A";
95
96 maclen = sizeof (macbuf);
97 macbuf[0] = '\0';
98 (void) octet_to_hexascii(plp->pkt->chaddr, plp->pkt->hlen, macbuf,
99 &maclen);
100
101 dhcpmsg(log_local | LOG_NOTICE, "%s %s %010ld %010ld %s %s %s %s %s\n",
102 proto, cat, time(NULL), lease,
103 inet_ntop(AF_INET, &cip, ntoabc, sizeof (ntoabc)),
104 inet_ntop(AF_INET, &sip, ntoabs, sizeof (ntoabs)),
105 cidbuf, class_id, macbuf);
106 }
107