/usr.sbin/atm/scspd/scsp_config_parse.y

https://bitbucket.org/cooljeanius/dragonflybsd · Happy · 396 lines · 348 code · 48 blank · 0 comment · 0 complexity · d7899debe25abc6e0d428493f48fe07d MD5 · raw file

  1. %{
  2. /*
  3. *
  4. * ===================================
  5. * HARP | Host ATM Research Platform
  6. * ===================================
  7. *
  8. *
  9. * This Host ATM Research Platform ("HARP") file (the "Software") is
  10. * made available by Network Computing Services, Inc. ("NetworkCS")
  11. * "AS IS". NetworkCS does not provide maintenance, improvements or
  12. * support of any kind.
  13. *
  14. * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
  15. * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
  16. * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
  17. * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
  18. * In no event shall NetworkCS be responsible for any damages, including
  19. * but not limited to consequential damages, arising from or relating to
  20. * any use of the Software or related support.
  21. *
  22. * Copyright 1994-1998 Network Computing Services, Inc.
  23. *
  24. * Copies of this Software may be made, however, the above copyright
  25. * notice must be reproduced on all copies.
  26. *
  27. * @(#) $FreeBSD: src/usr.sbin/atm/scspd/scsp_config_parse.y,v 1.3 1999/08/28 01:15:32 peter Exp $
  28. * @(#) $DragonFly: src/usr.sbin/atm/scspd/scsp_config_parse.y,v 1.4 2008/11/12 21:44:59 swildner Exp $
  29. */
  30. /*
  31. * Server Cache Synchronization Protocol (SCSP) Support
  32. * ----------------------------------------------------
  33. *
  34. * YACC input for configuration file processing
  35. *
  36. */
  37. #include <sys/types.h>
  38. #include <sys/param.h>
  39. #include <sys/socket.h>
  40. #include <net/if.h>
  41. #include <netinet/in.h>
  42. #include <netatm/port.h>
  43. #include <netatm/queue.h>
  44. #include <netatm/atm.h>
  45. #include <netatm/atm_if.h>
  46. #include <netatm/atm_sap.h>
  47. #include <netatm/atm_sys.h>
  48. #include <netatm/atm_ioctl.h>
  49. #include <libatm.h>
  50. #if __STDC__
  51. #include <stdarg.h>
  52. #else
  53. #include <varargs.h>
  54. #endif
  55. #include <stdio.h>
  56. #include <stdlib.h>
  57. #include <string.h>
  58. #include <syslog.h>
  59. #include "scsp_msg.h"
  60. #include "scsp_if.h"
  61. #include "scsp_var.h"
  62. void yyerror(char *);
  63. %}
  64. /*
  65. * Token value definition
  66. */
  67. %union {
  68. char *tv_alpha;
  69. int tv_int;
  70. char *tv_hex;
  71. }
  72. /*
  73. * Token types returned by scanner
  74. */
  75. %token <tv_alpha> TOK_NAME
  76. %token <tv_int> TOK_INTEGER
  77. %token <tv_hex> TOK_HEX
  78. /*
  79. * Reserved words
  80. */
  81. %token TOK_ATMARP
  82. %token TOK_DCS
  83. %token TOK_DCS_ADDR
  84. %token TOK_DCS_CA_REXMIT_INT
  85. %token TOK_DCS_CSUS_REXMIT_INT
  86. %token TOK_DCS_CSU_REXMIT_INT
  87. %token TOK_DCS_CSU_REXMIT_MAX
  88. %token TOK_DCS_HELLO_DF
  89. %token TOK_DCS_HELLO_INT
  90. %token TOK_DCS_HOP_CNT
  91. %token TOK_DCS_ID
  92. %token TOK_DHCP
  93. %token TOK_FAMILY
  94. %token TOK_LFN
  95. %token TOK_LNNI
  96. %token TOK_LOG
  97. %token TOK_MARS
  98. %token TOK_NETIF
  99. %token TOK_NHRP
  100. %token TOK_PROTOCOL
  101. %token TOK_SERVER
  102. %token TOK_SRVGRP
  103. %token TOK_SYSLOG
  104. %%
  105. cfg_file: /* Empty */
  106. | stmt_seq
  107. stmt_seq: stmt
  108. | stmt_seq stmt
  109. ;
  110. stmt: server_stmt ';'
  111. | log_stmt ';'
  112. ;
  113. /*
  114. * SCSP server definition statements
  115. */
  116. server_stmt: TOK_SERVER TOK_NAME
  117. {
  118. int rc;
  119. rc = start_server($2);
  120. UM_FREE($2);
  121. if (rc)
  122. return(rc);
  123. }
  124. '{' server_def '}'
  125. {
  126. int rc;
  127. rc = finish_server();
  128. if (rc)
  129. return(rc);
  130. }
  131. ;
  132. server_def: server_spec ';'
  133. | server_def server_spec ';'
  134. ;
  135. server_spec: /* Nothing */
  136. | dcs_stmt
  137. | TOK_NETIF TOK_NAME
  138. {
  139. int rc;
  140. /*
  141. * Configure the network interface
  142. */
  143. rc = set_intf($2);
  144. UM_FREE($2);
  145. if (rc)
  146. return(rc);
  147. }
  148. | TOK_PROTOCOL TOK_ATMARP
  149. {
  150. int rc;
  151. /*
  152. * Configure the protocol
  153. */
  154. rc = set_protocol(SCSP_PROTO_ATMARP);
  155. if (rc)
  156. return(rc);
  157. }
  158. | TOK_PROTOCOL TOK_DHCP | TOK_LNNI | TOK_MARS | TOK_NHRP
  159. {
  160. yyerror("Protocol not implemented");
  161. return(1);
  162. }
  163. | TOK_SRVGRP TOK_INTEGER
  164. {
  165. int rc;
  166. /*
  167. * Configure the SCSP server group ID
  168. */
  169. rc = set_server_group($2);
  170. if (rc)
  171. return(rc);
  172. }
  173. ;
  174. /*
  175. * SCSP DCS definition statements
  176. */
  177. dcs_stmt: TOK_DCS
  178. {
  179. int rc;
  180. rc = start_dcs();
  181. if (rc)
  182. return(rc);
  183. }
  184. '{' dcs_def '}'
  185. {
  186. int rc;
  187. rc = finish_dcs();
  188. if (rc)
  189. return(rc);
  190. }
  191. ;
  192. dcs_def: dcs_spec ';'
  193. | dcs_def dcs_spec ';'
  194. ;
  195. dcs_spec: /* Nothing */
  196. | TOK_DCS_ADDR TOK_HEX
  197. {
  198. int rc;
  199. /*
  200. * Set DCS address
  201. */
  202. rc = set_dcs_addr($2, NULL);
  203. UM_FREE($2);
  204. if (rc)
  205. return(rc);
  206. }
  207. | TOK_DCS_ADDR TOK_HEX TOK_HEX
  208. {
  209. int rc;
  210. /*
  211. * Set DCS address and subaddress
  212. */
  213. rc = set_dcs_addr($2, $3);
  214. UM_FREE($2);
  215. UM_FREE($3);
  216. if (rc)
  217. return(rc);
  218. }
  219. | TOK_DCS_CA_REXMIT_INT TOK_INTEGER
  220. {
  221. int rc;
  222. /*
  223. * Configure the CA retransmit interval
  224. */
  225. rc = set_dcs_ca_rexmit($2);
  226. if (rc)
  227. return(rc);
  228. }
  229. | TOK_DCS_CSUS_REXMIT_INT TOK_INTEGER
  230. {
  231. int rc;
  232. /*
  233. * Configure the CSUS retransmit interval
  234. */
  235. rc = set_dcs_csus_rexmit($2);
  236. if (rc)
  237. return(rc);
  238. }
  239. | TOK_DCS_CSU_REXMIT_INT TOK_INTEGER
  240. {
  241. int rc;
  242. /*
  243. * Configure the CSU retransmit interval
  244. */
  245. rc = set_dcs_csu_rexmit($2);
  246. if (rc)
  247. return(rc);
  248. }
  249. | TOK_DCS_CSU_REXMIT_MAX TOK_INTEGER
  250. {
  251. int rc;
  252. /*
  253. * Configure the CSU retransmit limit
  254. */
  255. rc = set_dcs_csu_rexmit_max($2);
  256. if (rc)
  257. return(rc);
  258. }
  259. | TOK_DCS_HELLO_DF TOK_INTEGER
  260. {
  261. int rc;
  262. /*
  263. * Configure the Hello dead factor
  264. */
  265. rc = set_dcs_hello_df($2);
  266. if (rc)
  267. return(rc);
  268. }
  269. | TOK_DCS_HELLO_INT TOK_INTEGER
  270. {
  271. int rc;
  272. /*
  273. * Configure the Hello interval
  274. */
  275. rc = set_dcs_hello_int($2);
  276. if (rc)
  277. return(rc);
  278. }
  279. | TOK_DCS_HOP_CNT TOK_INTEGER
  280. {
  281. int rc;
  282. /*
  283. * Configure the hop count
  284. */
  285. rc = set_dcs_hops($2);
  286. if (rc)
  287. return(rc);
  288. }
  289. | TOK_DCS_ID TOK_NAME
  290. {
  291. int rc;
  292. /*
  293. * Configure the DCS ID
  294. */
  295. rc = set_dcs_id($2);
  296. UM_FREE($2);
  297. if (rc)
  298. return(rc);
  299. }
  300. ;
  301. /*
  302. * Logging option statements
  303. */
  304. log_stmt: TOK_LOG
  305. '{' log_spec '}'
  306. ;
  307. log_spec: /* Nothing */
  308. | TOK_LFN TOK_NAME ';'
  309. {
  310. /*
  311. * Configure the log file name
  312. */
  313. int rc;
  314. rc = set_log_file($2);
  315. UM_FREE($2);
  316. if (rc)
  317. return(rc);
  318. }
  319. ;
  320. | TOK_SYSLOG ';'
  321. {
  322. /*
  323. * Configure logging to syslog
  324. */
  325. scsp_log_syslog = 1;
  326. }
  327. ;
  328. %%
  329. void
  330. parse_error(const char *fmt, ...)
  331. {
  332. va_list ap;
  333. char buff[256];
  334. va_start(ap, fmt);
  335. vsprintf(buff, fmt, ap);
  336. scsp_log(LOG_ERR, "%s: Config file error at line %d: %s\n",
  337. prog, parse_line, buff);
  338. #ifdef NOTDEF
  339. fprintf(stderr, "%s: Config file error at line %d: %s\n",
  340. prog, parse_line, buff);
  341. #endif
  342. va_end(ap);
  343. }
  344. void
  345. yyerror(char *s)
  346. {
  347. parse_error(s);
  348. }