en10mb_api.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /* $Id$ */
  2. /*
  3. * Copyright (c) 2001-2010 Aaron Turner <aturner at synfin dot net>
  4. * Copyright (c) 2013-2017 Fred Klassen <tcpreplay at appneta dot com> - AppNeta
  5. *
  6. * The Tcpreplay Suite of tools is free software: you can redistribute it
  7. * and/or modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or with the authors permission any later version.
  10. *
  11. * The Tcpreplay Suite is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with the Tcpreplay Suite. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include "defines.h"
  22. #include "common.h"
  23. #include "tcpedit.h"
  24. #include "en10mb.h"
  25. #include "en10mb_api.h"
  26. /**
  27. * \brief Allows you to rewrite source & destination MAC addresses
  28. *
  29. * Pass the new MAC address in null terminated string format
  30. * "00:00:00:00:00:00\0" as well as the mac_mask value for which mac
  31. * address to rewrite. You can call this function up to 4 times,
  32. * once for each mac_mask value.
  33. */
  34. int
  35. tcpedit_en10mb_set_mac(tcpedit_t *tcpedit, char *mac, tcpedit_mac_mask mask)
  36. {
  37. u_char mac_addr[ETHER_ADDR_LEN];
  38. tcpeditdlt_t *ctx;
  39. tcpeditdlt_plugin_t *plugin;
  40. en10mb_config_t *config;
  41. assert(tcpedit);
  42. ctx = tcpedit->dlt_ctx;
  43. assert(ctx);
  44. plugin = ctx->decoder;
  45. assert(plugin);
  46. config = (en10mb_config_t *)plugin->config;
  47. assert(mac);
  48. mac2hex(mac, mac_addr, strlen(mac));
  49. switch (mask) {
  50. case TCPEDIT_MAC_MASK_DMAC1:
  51. config->mac_mask += TCPEDIT_MAC_MASK_DMAC1;
  52. memcpy(config->intf1_dmac, mac_addr, ETHER_ADDR_LEN);
  53. break;
  54. case TCPEDIT_MAC_MASK_DMAC2:
  55. config->mac_mask += TCPEDIT_MAC_MASK_DMAC2;
  56. memcpy(config->intf2_dmac, mac_addr, ETHER_ADDR_LEN);
  57. break;
  58. case TCPEDIT_MAC_MASK_SMAC1:
  59. config->mac_mask += TCPEDIT_MAC_MASK_SMAC1;
  60. memcpy(config->intf1_smac, mac_addr, ETHER_ADDR_LEN);
  61. break;
  62. case TCPEDIT_MAC_MASK_SMAC2:
  63. config->mac_mask += TCPEDIT_MAC_MASK_SMAC2;
  64. memcpy(config->intf2_smac, mac_addr, ETHER_ADDR_LEN);
  65. break;
  66. }
  67. switch (mask) {
  68. case TCPEDIT_MAC_MASK_DMAC1:
  69. case TCPEDIT_MAC_MASK_DMAC2:
  70. plugin->requires = plugin->requires & (0xffffffff ^ PLUGIN_MASK_DSTADDR);
  71. break;
  72. case TCPEDIT_MAC_MASK_SMAC1:
  73. case TCPEDIT_MAC_MASK_SMAC2:
  74. plugin->requires = plugin->requires & (0xffffffff ^ PLUGIN_MASK_SRCADDR);
  75. break;
  76. }
  77. return TCPEDIT_OK;
  78. }
  79. /**
  80. * Sets the 802.1q VLAN mode (add, delete, etc..)
  81. */
  82. int
  83. tcpedit_en10mb_set_vlan_mode(tcpedit_t *tcpedit, tcpedit_vlan vlan)
  84. {
  85. tcpeditdlt_t *ctx;
  86. tcpeditdlt_plugin_t *plugin;
  87. en10mb_config_t *config;
  88. assert(tcpedit);
  89. ctx = tcpedit->dlt_ctx;
  90. assert(ctx);
  91. plugin = ctx->decoder;
  92. assert(plugin);
  93. config = (en10mb_config_t *)plugin->config;
  94. config->vlan = vlan;
  95. return TCPEDIT_OK;
  96. }
  97. /**
  98. * Sets the VLAN tag value in add or edit mode
  99. */
  100. int
  101. tcpedit_en10mb_set_vlan_tag(tcpedit_t *tcpedit, uint16_t tag)
  102. {
  103. tcpeditdlt_t *ctx;
  104. tcpeditdlt_plugin_t *plugin;
  105. en10mb_config_t *config;
  106. assert(tcpedit);
  107. ctx = tcpedit->dlt_ctx;
  108. assert(ctx);
  109. plugin = ctx->decoder;
  110. assert(plugin);
  111. config = (en10mb_config_t *)plugin->config;
  112. config->vlan_tag = tag;
  113. return TCPEDIT_OK;
  114. }
  115. /**
  116. * Sets the VLAN priority field in add or edit mode
  117. */
  118. int
  119. tcpedit_en10mb_set_vlan_priority(tcpedit_t *tcpedit, uint8_t priority)
  120. {
  121. tcpeditdlt_t *ctx;
  122. tcpeditdlt_plugin_t *plugin;
  123. en10mb_config_t *config;
  124. assert(tcpedit);
  125. ctx = tcpedit->dlt_ctx;
  126. assert(ctx);
  127. plugin = ctx->decoder;
  128. assert(plugin);
  129. config = (en10mb_config_t *)plugin->config;
  130. config->vlan_pri = priority;
  131. return TCPEDIT_OK;
  132. }
  133. /**
  134. * Sets the VLAN CFI field in add or edit mode
  135. */
  136. int
  137. tcpedit_en10mb_set_vlan_cfi(tcpedit_t *tcpedit, uint8_t cfi)
  138. {
  139. tcpeditdlt_t *ctx;
  140. tcpeditdlt_plugin_t *plugin;
  141. en10mb_config_t *config;
  142. assert(tcpedit);
  143. ctx = tcpedit->dlt_ctx;
  144. assert(ctx);
  145. plugin = ctx->decoder;
  146. assert(plugin);
  147. config = (en10mb_config_t *)plugin->config;
  148. config->vlan_cfi = cfi;
  149. return TCPEDIT_OK;
  150. }