1 /* $OpenBSD: ifstated.h,v 1.19 2017/08/20 17:49:29 rob Exp $ */ 2 3 /* 4 * Copyright (c) 2004 Ryan McBride 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 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. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT, 20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 26 * THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #include <sys/types.h> 30 #include <sys/queue.h> 31 32 struct ifsd_expression; 33 TAILQ_HEAD(ifsd_expression_list, ifsd_expression); 34 35 struct ifsd_ifstate { 36 TAILQ_ENTRY(ifsd_ifstate) entries; 37 struct ifsd_expression_list expressions; 38 int ifstate; 39 #define IFSD_LINKUNKNOWN 0 40 #define IFSD_LINKDOWN 1 41 #define IFSD_LINKUP 2 42 int prevstate; 43 u_int32_t refcount; 44 char ifname[IFNAMSIZ]; 45 }; 46 47 struct ifsd_external { 48 TAILQ_ENTRY(ifsd_external) entries; 49 struct event ev; 50 struct ifsd_expression_list expressions; 51 char *command; 52 int prevstatus; 53 u_int32_t frequency; 54 u_int32_t refcount; 55 time_t lastexec; 56 pid_t pid; 57 }; 58 59 struct ifsd_action; 60 TAILQ_HEAD(ifsd_action_list, ifsd_action); 61 62 struct ifsd_action { 63 TAILQ_ENTRY(ifsd_action) entries; 64 struct ifsd_action *parent; 65 union { 66 char *command; 67 struct ifsd_state *nextstate; 68 char *statename; 69 struct { 70 struct ifsd_action_list actions; 71 struct ifsd_expression *expression; 72 } c; 73 } act; 74 u_int32_t type; 75 #define IFSD_ACTION_COMMAND 1 76 #define IFSD_ACTION_CHANGESTATE 2 77 #define IFSD_ACTION_CONDITION 3 78 }; 79 80 struct ifsd_expression { 81 TAILQ_ENTRY(ifsd_expression) entries; 82 TAILQ_ENTRY(ifsd_expression) eval; 83 struct ifsd_expression *parent; 84 struct ifsd_action *action; 85 struct ifsd_expression *left; 86 struct ifsd_expression *right; 87 union { 88 struct ifsd_ifstate *ifstate; 89 struct ifsd_external *external; 90 } u; 91 int depth; 92 u_int32_t type; 93 #define IFSD_OPER_AND 1 94 #define IFSD_OPER_OR 2 95 #define IFSD_OPER_NOT 3 96 #define IFSD_OPER_EXTERNAL 4 97 #define IFSD_OPER_IFSTATE 5 98 u_int8_t truth; 99 }; 100 101 TAILQ_HEAD(ifsd_ifstate_list, ifsd_ifstate); 102 TAILQ_HEAD(ifsd_external_list, ifsd_external); 103 104 struct ifsd_state { 105 struct event ev; 106 struct ifsd_ifstate_list interface_states; 107 struct ifsd_external_list external_tests; 108 TAILQ_ENTRY(ifsd_state) entries; 109 struct ifsd_action *init; 110 struct ifsd_action *body; 111 time_t entered; 112 char *name; 113 }; 114 115 TAILQ_HEAD(ifsd_state_list, ifsd_state); 116 117 struct ifsd_config { 118 struct ifsd_state initstate; 119 struct ifsd_state_list states; 120 struct ifsd_state *curstate; 121 struct ifsd_state *nextstate; 122 u_int32_t opts; 123 #define IFSD_OPT_VERBOSE 0x00000001 124 #define IFSD_OPT_VERBOSE2 0x00000002 125 #define IFSD_OPT_NOACTION 0x00000004 126 int maxdepth; 127 }; 128 129 enum { IFSD_EVTIMER_ADD, IFSD_EVTIMER_DEL }; 130 struct ifsd_config *parse_config(char *, int); 131 int cmdline_symset(char *); 132 void clear_config(struct ifsd_config *); 133