Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame^] | 1 | ;;; tunnel-h-skel.el - tunnel encap header file skeleton |
| 2 | |
| 3 | (require 'skeleton) |
| 4 | |
| 5 | (define-skeleton tunnel-h-skel |
| 6 | "Insert a tunnel encap header file" |
| 7 | nil |
| 8 | '(setq encap_stack (skeleton-read "encap_stack (e.g ip4_udp_lisp): ")) |
| 9 | '(setq ENCAP_STACK (upcase encap_stack)) |
| 10 | '(setq encap-stack (replace-regexp-in-string "_" "-" encap_stack)) |
| 11 | " |
| 12 | #ifndef included_vnet_" encap_stack "_h |
| 13 | #define included_vnet_" encap_stack "_h |
| 14 | |
| 15 | #include <clib/error.h> |
| 16 | #include <clib/hash.h> |
| 17 | #include <vnet/vnet.h> |
| 18 | #include <vnet/ip/ip.h> |
| 19 | #include <vnet/l2/l2_input.h> |
| 20 | #include <vnet/ethernet/ethernet.h> |
| 21 | #include <vnet/" encap-stack "/" encap_stack "_packet.h> |
| 22 | #include <vnet/ip/ip4_packet.h> |
| 23 | #include <vnet/ip/udp.h> |
| 24 | |
| 25 | /* Encap stack built in encap.c */ |
| 26 | typedef CLIB_PACKED (struct { |
| 27 | ip4_header_t ip4; /* 20 bytes */ |
| 28 | udp_header_t udp; /* 8 bytes */ |
| 29 | " encap_stack "_header_t lisp; /* 8 bytes */ |
| 30 | }) " encap_stack "_header_t; |
| 31 | |
| 32 | typedef CLIB_PACKED(struct { |
| 33 | /* |
| 34 | * Key fields: |
| 35 | * all fields in NET byte order |
| 36 | */ |
| 37 | union { |
| 38 | struct { |
| 39 | u32 FIXME_NET_BYTE_ORDER; |
| 40 | }; |
| 41 | u64 as_u64[1]; |
| 42 | }; |
| 43 | }) " encap_stack "_tunnel_key_t; |
| 44 | |
| 45 | typedef struct { |
| 46 | /* Rewrite string. $$$$ maybe: embed vnet_rewrite header */ |
| 47 | u8 * rewrite; |
| 48 | |
| 49 | /* decap next index */ |
| 50 | u32 decap_next_index; |
| 51 | |
| 52 | /* tunnel src and dst addresses */ |
| 53 | ip4_address_t src; |
| 54 | ip4_address_t dst; |
| 55 | |
| 56 | /* FIB indices */ |
| 57 | u32 encap_fib_index; /* tunnel partner lookup here */ |
| 58 | u32 decap_fib_index; /* inner IP lookup here */ |
| 59 | |
| 60 | /* vnet intfc hw/sw_if_index */ |
| 61 | u32 hw_if_index; |
| 62 | |
| 63 | /* encap header fields in HOST byte order */ |
| 64 | u32 FIXME; |
| 65 | } " encap_stack "_tunnel_t; |
| 66 | |
| 67 | #define foreach_" encap_stack "_input_next \\ |
| 68 | _(DROP, \"error-drop\") \\ |
| 69 | _(IP4_INPUT, \"ip4-input\") \\ |
| 70 | _(IP6_INPUT, \"ip6-input\") \\ |
| 71 | _(ETHERNET_INPUT, \"ethernet-input\") \\ |
| 72 | _(" ENCAP_STACK "_ENCAP, \"" encap-stack "-encap\") |
| 73 | |
| 74 | typedef enum { |
| 75 | #define _(s,n) " ENCAP_STACK "_INPUT_NEXT_##s, |
| 76 | foreach_" encap_stack "_input_next |
| 77 | #undef _ |
| 78 | " ENCAP_STACK "_INPUT_N_NEXT, |
| 79 | } " encap_stack "_input_next_t; |
| 80 | |
| 81 | typedef enum { |
| 82 | #define " encap_stack "_error(n,s) " ENCAP_STACK "_ERROR_##n, |
| 83 | #include <vnet/" encap-stack "/" encap_stack "_error.def> |
| 84 | #undef " encap_stack "_error |
| 85 | " ENCAP_STACK "_N_ERROR, |
| 86 | } " encap_stack "_input_error_t; |
| 87 | |
| 88 | typedef struct { |
| 89 | /* vector of encap tunnel instances */ |
| 90 | " encap_stack "_tunnel_t *tunnels; |
| 91 | |
| 92 | /* lookup tunnel by key */ |
| 93 | uword * " encap_stack "_tunnel_by_key; |
| 94 | |
| 95 | /* Free vlib hw_if_indices */ |
| 96 | u32 * free_" encap_stack "_tunnel_hw_if_indices; |
| 97 | |
| 98 | /* convenience */ |
| 99 | vlib_main_t * vlib_main; |
| 100 | vnet_main_t * vnet_main; |
| 101 | } " encap_stack "_main_t; |
| 102 | |
| 103 | " encap_stack "_main_t " encap_stack "_main; |
| 104 | |
| 105 | vlib_node_registration_t " encap_stack "_input_node; |
| 106 | vlib_node_registration_t " encap_stack "_encap_node; |
| 107 | |
| 108 | u8 * format_" encap_stack "_encap_trace (u8 * s, va_list * args); |
| 109 | u8 * format_" encap_stack "_header_with_length (u8 * s, va_list * args); |
| 110 | |
| 111 | typedef struct { |
| 112 | u8 is_add; |
| 113 | ip4_address_t src, dst; |
| 114 | u32 encap_fib_index; |
| 115 | u32 decap_fib_index; |
| 116 | u32 decap_next_index; |
| 117 | /* encap fields in HOST byte order */ |
| 118 | u8 FIXME_HOST_BYTE_ORDER; |
| 119 | } vnet_" encap_stack "_add_del_tunnel_args_t; |
| 120 | |
| 121 | int vnet_" encap_stack "_add_del_tunnel |
| 122 | (vnet_" encap_stack "_add_del_tunnel_args_t *a, u32 * hw_if_indexp); |
| 123 | |
| 124 | u8 * format_" encap_stack "_header_with_length (u8 * s, va_list * args); |
| 125 | |
| 126 | #endif /* included_vnet_" encap_stack "_h */ |
| 127 | |
| 128 | ") |