pktloc_syntax.y 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. %{
  2. #include <netlink-private/netlink.h>
  3. #include <netlink-private/tc.h>
  4. #include <netlink/netlink.h>
  5. #include <netlink/utils.h>
  6. #include <netlink/route/pktloc.h>
  7. %}
  8. %locations
  9. %error-verbose
  10. %define api.pure
  11. %name-prefix "pktloc_"
  12. %parse-param {void *scanner}
  13. %lex-param {void *scanner}
  14. %expect 1
  15. %union {
  16. struct rtnl_pktloc *l;
  17. uint32_t i;
  18. char *s;
  19. }
  20. %{
  21. extern int pktloc_lex(YYSTYPE *, YYLTYPE *, void *);
  22. static void yyerror(YYLTYPE *locp, void *scanner, const char *msg)
  23. {
  24. NL_DBG(1, "Error while parsing packet location file: %s\n", msg);
  25. }
  26. %}
  27. %token <i> ERROR NUMBER LAYER ALIGN
  28. %token <s> NAME
  29. %type <i> mask layer align shift
  30. %type <l> location
  31. %destructor { free($$); } NAME
  32. %start input
  33. %%
  34. input:
  35. /* empty */
  36. | location input
  37. ;
  38. location:
  39. NAME align layer NUMBER mask shift
  40. {
  41. struct rtnl_pktloc *loc;
  42. if (!(loc = rtnl_pktloc_alloc())) {
  43. NL_DBG(1, "Allocating a packet location "
  44. "object failed.\n");
  45. YYABORT;
  46. }
  47. loc->name = $1;
  48. loc->align = $2;
  49. loc->layer = $3;
  50. loc->offset = $4;
  51. loc->mask = $5;
  52. loc->shift = $6;
  53. if (rtnl_pktloc_add(loc) < 0) {
  54. NL_DBG(1, "Duplicate packet location entry "
  55. "\"%s\"\n", $1);
  56. }
  57. $$ = loc;
  58. }
  59. ;
  60. align:
  61. ALIGN
  62. { $$ = $1; }
  63. | NUMBER
  64. { $$ = $1; }
  65. ;
  66. layer:
  67. /* empty */
  68. { $$ = TCF_LAYER_NETWORK; }
  69. | LAYER '+'
  70. { $$ = $1; }
  71. ;
  72. mask:
  73. /* empty */
  74. { $$ = 0; }
  75. | NUMBER
  76. { $$ = $1; }
  77. ;
  78. shift:
  79. /* empty */
  80. { $$ = 0; }
  81. | NUMBER
  82. { $$ = $1; }
  83. ;