| 1 | /* |
| 2 | * This file is part of secnet. |
| 3 | * See README for full list of copyright holders. |
| 4 | * |
| 5 | * secnet is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version d of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * secnet is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * version 3 along with secnet; if not, see |
| 17 | * https://www.gnu.org/licenses/gpl.html. |
| 18 | */ |
| 19 | |
| 20 | #ifndef netlink_h |
| 21 | #define netlink_h |
| 22 | |
| 23 | #include "ipaddr.h" |
| 24 | |
| 25 | #define DEFAULT_BUFSIZE 2048 |
| 26 | #define DEFAULT_MTU 1000 |
| 27 | #define ICMP_BUFSIZE 1024 |
| 28 | |
| 29 | struct netlink; |
| 30 | |
| 31 | struct netlink_client { |
| 32 | closure_t cl; |
| 33 | struct netlink_if ops; |
| 34 | struct netlink *nst; |
| 35 | struct ipset *networks; |
| 36 | struct subnet_list *subnets; /* Same information as 'networks' */ |
| 37 | uint32_t priority; /* Higher priority clients have their networks |
| 38 | checked first during routing. This allows |
| 39 | things like laptops to supersede whole |
| 40 | networks. */ |
| 41 | netlink_deliver_fn *deliver; |
| 42 | void *dst; |
| 43 | string_t name; |
| 44 | uint32_t link_quality; |
| 45 | int32_t mtu; |
| 46 | uint32_t options; |
| 47 | uint32_t outcount; |
| 48 | bool_t up; /* Should these routes exist in the kernel? */ |
| 49 | bool_t kup; /* Do these routes exist in the kernel? */ |
| 50 | struct netlink_client *next; |
| 51 | }; |
| 52 | |
| 53 | /* options field in 'struct netlink_client' */ |
| 54 | #define OPT_SOFTROUTE 1 |
| 55 | #define OPT_ALLOWROUTE 2 |
| 56 | |
| 57 | typedef bool_t netlink_route_fn(void *cst, struct netlink_client *routes); |
| 58 | |
| 59 | /* Netlink provides one function to the device driver, to call to deliver |
| 60 | a packet from the device. The device driver provides one function to |
| 61 | netlink, for it to call to deliver a packet to the device. */ |
| 62 | |
| 63 | struct netlink { |
| 64 | closure_t cl; |
| 65 | void *dst; /* Pointer to host interface state */ |
| 66 | cstring_t name; |
| 67 | struct ipset *networks; /* Local networks */ |
| 68 | struct subnet_list *subnets; /* Same as networks, for display */ |
| 69 | struct ipset *remote_networks; /* Allowable remote networks */ |
| 70 | uint32_t local_address; /* host interface address */ |
| 71 | uint32_t secnet_address; /* our own address, or the address of the |
| 72 | other end of a point-to-point link */ |
| 73 | bool_t ptp; |
| 74 | int32_t mtu; |
| 75 | struct netlink_client *clients; /* Linked list of clients */ |
| 76 | struct netlink_client **routes; /* Array of clients, sorted by priority */ |
| 77 | int32_t n_clients; |
| 78 | netlink_deliver_fn *deliver_to_host; /* Provided by driver */ |
| 79 | netlink_route_fn *set_routes; /* Provided by driver */ |
| 80 | struct buffer_if icmp; /* Buffer for assembly of outgoing ICMP */ |
| 81 | uint32_t outcount; /* Packets sent to host */ |
| 82 | uint32_t localcount; /* Packets sent to secnet */ |
| 83 | }; |
| 84 | |
| 85 | extern netlink_deliver_fn *netlink_init(struct netlink *st, |
| 86 | void *dst, struct cloc loc, |
| 87 | dict_t *dict, cstring_t description, |
| 88 | netlink_route_fn *set_routes, |
| 89 | netlink_deliver_fn *to_host); |
| 90 | |
| 91 | #endif /* netlink_h */ |