2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (C) 2011 Hiroki Sato <hrs@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/queue.h>
33 #include <sys/types.h>
34 #include <sys/socket.h>
39 #include <net/if_dl.h>
40 #include <netinet/in.h>
41 #include <netinet/icmp6.h>
53 #include "pathnames.h"
57 #include "control_client.h"
60 cm_handler_client(int fd, int state, char *buf_orig)
62 char buf[CM_MSG_MAXLEN];
63 struct ctrl_msg_hdr *cm;
64 struct ctrl_msg_hdr *cm_orig;
69 syslog(LOG_DEBUG, "<%s> enter", __func__);
71 memset(buf, 0, sizeof(buf));
72 cm = (struct ctrl_msg_hdr *)buf;
73 cm_orig = (struct ctrl_msg_hdr *)buf_orig;
74 msg = (char *)buf + sizeof(*cm);
75 msg_orig = (char *)buf_orig + sizeof(*cm_orig);
77 if (cm_orig->cm_len > CM_MSG_MAXLEN) {
78 syslog(LOG_DEBUG, "<%s> msg too long", __func__);
82 cm->cm_type = cm_orig->cm_type;
83 if (cm_orig->cm_len > sizeof(*cm_orig)) {
84 memcpy(msg, msg_orig, cm_orig->cm_len - sizeof(*cm));
85 cm->cm_len = cm_orig->cm_len;
87 while (state != CM_STATE_EOM) {
88 syslog(LOG_DEBUG, "<%s> state = %d", __func__, state);
94 case CM_STATE_MSG_DISPATCH:
95 cm->cm_version = CM_VERSION;
96 error = cm_send(fd, buf);
99 "<%s> cm_send()", __func__);
102 state = CM_STATE_ACK_WAIT;
104 case CM_STATE_ACK_WAIT:
105 error = cm_recv(fd, buf);
108 "<%s> cm_recv()", __func__);
112 switch (cm->cm_type) {
115 "<%s> CM_TYPE_ACK", __func__);
119 "<%s> CM_TYPE_ERR", __func__);
124 "<%s> unknown status", __func__);
128 memcpy(buf_orig, buf, cm->cm_len);
129 state = CM_STATE_EOM;