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