1cb9cadadSEd Warnicke/*
2cb9cadadSEd Warnicke * Copyright (c) 2015 Cisco and/or its affiliates.
3cb9cadadSEd Warnicke * Licensed under the Apache License, Version 2.0 (the "License");
4cb9cadadSEd Warnicke * you may not use this file except in compliance with the License.
5cb9cadadSEd Warnicke * You may obtain a copy of the License at:
6cb9cadadSEd Warnicke *
7cb9cadadSEd Warnicke *     http://www.apache.org/licenses/LICENSE-2.0
8cb9cadadSEd Warnicke *
9cb9cadadSEd Warnicke * Unless required by applicable law or agreed to in writing, software
10cb9cadadSEd Warnicke * distributed under the License is distributed on an "AS IS" BASIS,
11cb9cadadSEd Warnicke * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12cb9cadadSEd Warnicke * See the License for the specific language governing permissions and
13cb9cadadSEd Warnicke * limitations under the License.
14cb9cadadSEd Warnicke */
15cb9cadadSEd Warnicke/*
16cb9cadadSEd Warnicke * ppp.h: types/functions for ppp.
17cb9cadadSEd Warnicke *
18cb9cadadSEd Warnicke * Copyright (c) 2008 Eliot Dresselhaus
19cb9cadadSEd Warnicke *
20cb9cadadSEd Warnicke * Permission is hereby granted, free of charge, to any person obtaining
21cb9cadadSEd Warnicke * a copy of this software and associated documentation files (the
22cb9cadadSEd Warnicke * "Software"), to deal in the Software without restriction, including
23cb9cadadSEd Warnicke * without limitation the rights to use, copy, modify, merge, publish,
24cb9cadadSEd Warnicke * distribute, sublicense, and/or sell copies of the Software, and to
25cb9cadadSEd Warnicke * permit persons to whom the Software is furnished to do so, subject to
26cb9cadadSEd Warnicke * the following conditions:
27cb9cadadSEd Warnicke *
28cb9cadadSEd Warnicke * The above copyright notice and this permission notice shall be
29cb9cadadSEd Warnicke * included in all copies or substantial portions of the Software.
30cb9cadadSEd Warnicke *
31cb9cadadSEd Warnicke *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32cb9cadadSEd Warnicke *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33cb9cadadSEd Warnicke *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34cb9cadadSEd Warnicke *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35cb9cadadSEd Warnicke *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36cb9cadadSEd Warnicke *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37cb9cadadSEd Warnicke *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38cb9cadadSEd Warnicke */
39cb9cadadSEd Warnicke
40cb9cadadSEd Warnicke#ifndef included_ppp_h
41cb9cadadSEd Warnicke#define included_ppp_h
42cb9cadadSEd Warnicke
43cb9cadadSEd Warnicke#include <vnet/vnet.h>
44cb9cadadSEd Warnicke#include <vnet/ppp/packet.h>
45cb9cadadSEd Warnicke#include <vnet/pg/pg.h>
46cb9cadadSEd Warnicke
47b8abf877SDamjan Marionextern vnet_hw_interface_class_t ppp_hw_interface_class;
48cb9cadadSEd Warnicke
49aba0fe49SCalvintypedef enum
50aba0fe49SCalvin{
51cb9cadadSEd Warnicke#define ppp_error(n,s) PPP_ERROR_##n,
52cb9cadadSEd Warnicke#include <vnet/ppp/error.def>
53cb9cadadSEd Warnicke#undef ppp_error
54cb9cadadSEd Warnicke  PPP_N_ERROR,
55cb9cadadSEd Warnicke} ppp_error_t;
56cb9cadadSEd Warnicke
57aba0fe49SCalvintypedef struct
58aba0fe49SCalvin{
59cb9cadadSEd Warnicke  /* Name (a c string). */
60aba0fe49SCalvin  char *name;
61cb9cadadSEd Warnicke
62cb9cadadSEd Warnicke  /* PPP protocol type in host byte order. */
63cb9cadadSEd Warnicke  ppp_protocol_t protocol;
64cb9cadadSEd Warnicke
65cb9cadadSEd Warnicke  /* Node which handles this type. */
66cb9cadadSEd Warnicke  u32 node_index;
67cb9cadadSEd Warnicke
68cb9cadadSEd Warnicke  /* Next index for this type. */
69cb9cadadSEd Warnicke  u32 next_index;
70cb9cadadSEd Warnicke} ppp_protocol_info_t;
71cb9cadadSEd Warnicke
72aba0fe49SCalvintypedef struct
73aba0fe49SCalvin{
74aba0fe49SCalvin  vlib_main_t *vlib_main;
75cb9cadadSEd Warnicke
76aba0fe49SCalvin  ppp_protocol_info_t *protocol_infos;
77cb9cadadSEd Warnicke
78cb9cadadSEd Warnicke  /* Hash tables mapping name/protocol to protocol info index. */
79aba0fe49SCalvin  uword *protocol_info_by_name, *protocol_info_by_protocol;
80cb9cadadSEd Warnicke} ppp_main_t;
81cb9cadadSEd Warnicke
82cb9cadadSEd Warnickealways_inline ppp_protocol_info_t *
83cb9cadadSEd Warnickeppp_get_protocol_info (ppp_main_t * em, ppp_protocol_t protocol)
84cb9cadadSEd Warnicke{
85aba0fe49SCalvin  uword *p = hash_get (em->protocol_info_by_protocol, protocol);
86cb9cadadSEd Warnicke  return p ? vec_elt_at_index (em->protocol_infos, p[0]) : 0;
87cb9cadadSEd Warnicke}
88cb9cadadSEd Warnicke
89cb9cadadSEd Warnickeextern ppp_main_t ppp_main;
90cb9cadadSEd Warnicke
91cb9cadadSEd Warnicke/* Register given node index to take input for given ppp type. */
92cb9cadadSEd Warnickevoid
93cb9cadadSEd Warnickeppp_register_input_type (vlib_main_t * vm,
94aba0fe49SCalvin			 ppp_protocol_t protocol, u32 node_index);
95cb9cadadSEd Warnicke
96cb9cadadSEd Warnickeformat_function_t format_ppp_protocol;
97cb9cadadSEd Warnickeformat_function_t format_ppp_header;
98cb9cadadSEd Warnickeformat_function_t format_ppp_header_with_length;
99cb9cadadSEd Warnicke
100cb9cadadSEd Warnicke/* Parse ppp protocol as 0xXXXX or protocol name.
101cb9cadadSEd Warnicke   In either host or network byte order. */
102cb9cadadSEd Warnickeunformat_function_t unformat_ppp_protocol_host_byte_order;
103cb9cadadSEd Warnickeunformat_function_t unformat_ppp_protocol_net_byte_order;
104cb9cadadSEd Warnicke
105cb9cadadSEd Warnicke/* Parse ppp header. */
106cb9cadadSEd Warnickeunformat_function_t unformat_ppp_header;
107cb9cadadSEd Warnickeunformat_function_t unformat_pg_ppp_header;
108cb9cadadSEd Warnicke
109cb9cadadSEd Warnickealways_inline void
110cb9cadadSEd Warnickeppp_setup_node (vlib_main_t * vm, u32 node_index)
111cb9cadadSEd Warnicke{
112aba0fe49SCalvin  vlib_node_t *n = vlib_get_node (vm, node_index);
113aba0fe49SCalvin  pg_node_t *pn = pg_get_node (node_index);
114cb9cadadSEd Warnicke
115cb9cadadSEd Warnicke  n->format_buffer = format_ppp_header_with_length;
116cb9cadadSEd Warnicke  n->unformat_buffer = unformat_ppp_header;
117cb9cadadSEd Warnicke  pn->unformat_edit = unformat_pg_ppp_header;
118cb9cadadSEd Warnicke}
119cb9cadadSEd Warnicke
120cb9cadadSEd Warnickevoid
121cb9cadadSEd Warnickeppp_register_input_protocol (vlib_main_t * vm,
122aba0fe49SCalvin			     ppp_protocol_t protocol, u32 node_index);
123cb9cadadSEd Warnicke
124cb9cadadSEd Warnicke#endif /* included_ppp_h */
125aba0fe49SCalvin
126aba0fe49SCalvin/*
127aba0fe49SCalvin * fd.io coding-style-patch-verification: ON
128aba0fe49SCalvin *
129aba0fe49SCalvin * Local Variables:
130aba0fe49SCalvin * eval: (c-set-style "gnu")
131aba0fe49SCalvin * End:
132aba0fe49SCalvin */
133