137241896SHiroki Sato /*- 2*1de7b4b8SPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3*1de7b4b8SPedro F. Giffuni * 437241896SHiroki Sato * Copyright (C) 2011 Hiroki Sato <hrs@FreeBSD.org> 537241896SHiroki Sato * All rights reserved. 637241896SHiroki Sato * 737241896SHiroki Sato * Redistribution and use in source and binary forms, with or without 837241896SHiroki Sato * modification, are permitted provided that the following conditions 937241896SHiroki Sato * are met: 1037241896SHiroki Sato * 1. Redistributions of source code must retain the above copyright 1137241896SHiroki Sato * notice, this list of conditions and the following disclaimer. 1237241896SHiroki Sato * 2. Redistributions in binary form must reproduce the above copyright 1337241896SHiroki Sato * notice, this list of conditions and the following disclaimer in the 1437241896SHiroki Sato * documentation and/or other materials provided with the distribution. 1537241896SHiroki Sato * 1637241896SHiroki Sato * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 1737241896SHiroki Sato * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1837241896SHiroki Sato * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1937241896SHiroki Sato * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 2037241896SHiroki Sato * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2137241896SHiroki Sato * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2237241896SHiroki Sato * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2337241896SHiroki Sato * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2437241896SHiroki Sato * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2537241896SHiroki Sato * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2637241896SHiroki Sato * SUCH DAMAGE. 2737241896SHiroki Sato * 2837241896SHiroki Sato * $FreeBSD$ 2937241896SHiroki Sato * 3037241896SHiroki Sato */ 3137241896SHiroki Sato 3237241896SHiroki Sato #define SOCK_BACKLOG 5 3337241896SHiroki Sato 3437241896SHiroki Sato #define CM_MSG_MAXLEN 8192 3537241896SHiroki Sato #define CM_VERSION 1 3637241896SHiroki Sato #define CM_VERSION_STR "1.0" 3737241896SHiroki Sato 3837241896SHiroki Sato #define CM_TYPE_EOM 0 3937241896SHiroki Sato #define CM_TYPE_ACK 1 4037241896SHiroki Sato #define CM_TYPE_ERR 2 4137241896SHiroki Sato #define CM_TYPE_NUL 3 4237241896SHiroki Sato #define CM_TYPE_REQ_SET_PROP 4 4337241896SHiroki Sato #define CM_TYPE_REQ_GET_PROP 5 4437241896SHiroki Sato #define CM_TYPE_MAX 6 4537241896SHiroki Sato 4637241896SHiroki Sato #define CM_STATE_EOM 0 4737241896SHiroki Sato #define CM_STATE_INIT 1 4837241896SHiroki Sato #define CM_STATE_MSG_DISPATCH 2 4937241896SHiroki Sato #define CM_STATE_MSG_RECV 3 5037241896SHiroki Sato #define CM_STATE_ACK_WAIT 4 5137241896SHiroki Sato 5237241896SHiroki Sato struct ctrl_msg_hdr { 5337241896SHiroki Sato int cm_version; 5437241896SHiroki Sato size_t cm_len; 5537241896SHiroki Sato int cm_type; 5637241896SHiroki Sato }; 5737241896SHiroki Sato 5837241896SHiroki Sato struct ctrl_msg_pl { 5937241896SHiroki Sato char *cp_ifname; 6037241896SHiroki Sato char *cp_key; 6137241896SHiroki Sato 6237241896SHiroki Sato size_t cp_val_len; 6337241896SHiroki Sato char *cp_val; 6437241896SHiroki Sato }; 6537241896SHiroki Sato 6637241896SHiroki Sato int csock_open(struct sockinfo *, mode_t); 6737241896SHiroki Sato int csock_close(struct sockinfo *); 6837241896SHiroki Sato int csock_listen(struct sockinfo *); 6937241896SHiroki Sato int csock_accept(struct sockinfo *); 70aed37872SHiroki Sato int cm_send(int, char *); 71aed37872SHiroki Sato int cm_recv(int, char *); 7237241896SHiroki Sato 73aed37872SHiroki Sato size_t cm_pl2bin(char *, struct ctrl_msg_pl *); 74aed37872SHiroki Sato struct ctrl_msg_pl *cm_bin2pl(char *, struct ctrl_msg_pl *); 75aed37872SHiroki Sato size_t cm_str2bin(char *, void *, size_t); 76aed37872SHiroki Sato void *cm_bin2str(char *, void *, size_t); 77