summaryrefslogtreecommitdiffstats
path: root/src/ctl.h
blob: 7e5b076c7bc7d9dc6b9bfd0b7399b0a0cdc214bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* -*- mode: c; c-file-style: "openbsd" -*- */
/*
 * Copyright (c) 2012 Vincent Bernat <bernat@luffy.cx>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef _CTL_H
#define _CTL_H

#if HAVE_CONFIG_H
#  include <config.h>
#endif

#include <stdint.h>
#include "marshal.h"

enum hmsg_type {
	NONE,
	GET_CONFIG,	  /* Get global configuration */
	SET_CONFIG,	  /* Change global configuration */
	GET_INTERFACES,	  /* Get list of interfaces */
	SET_CHASSIS,	  /* Set local chassis */
	GET_CHASSIS,	  /* Get local chassis */
	GET_INTERFACE,	  /* Get all information related to an interface */
	GET_DEFAULT_PORT, /* Get all information related to default port */
	SET_PORT,	  /* Set port-related information (location, power, policy) */
	SUBSCRIBE,	  /* Subscribe to neighbor changes */
	NOTIFICATION,	  /* Notification message (sent by lldpd!) */
};

/** Header for the control protocol.
 *
 * The protocol is pretty simple. We send a single message containing the
 * provided message type with the message length, followed by the message
 * content.
 */
struct hmsg_header {
	enum hmsg_type type;
	size_t len;
};
#define HMSG_MAX_SIZE (1 << 19)

/* ctl.c */
int ctl_create(const char *);
int ctl_connect(const char *);
void ctl_cleanup(const char *);

int ctl_msg_send_unserialized(uint8_t **, size_t *, enum hmsg_type, void *,
    struct marshal_info *);
size_t ctl_msg_recv_unserialized(uint8_t **, size_t *, enum hmsg_type, void **,
    struct marshal_info *);

#endif