<commit_before>/*
 *
 * (C) 2015    - ntop.org
 * (C) 2014-15 - Accolade Technology Inc.
 *
 */

#include "pfring_mod_accolade.h"
#include "pfring_mod.h" /* to print stats under /proc */

//#define DEBUG

void *anic_hugepageGet(anic_handle_t anic_handle, int count, int *shmidP);
int anic_hugepageDmaMap(anic_handle_t anic_handle, void *virtualP, int hugepageCount, struct anic_dma_info *dmacbP);

/* **************************************************** */

static void accolade_release_resources(pfring *ring) {
  pfring_anic *accolade = (pfring_anic *) ring->priv_data;

  if (accolade) {
    anic_close(accolade->anic_handle);
    free(ring->priv_data);
    ring->priv_data = NULL;
  }
}

/* **************************************************** */

int pfring_anic_open(pfring *ring) {
  pfring_anic *accolade;
  u_int32_t page, blk;
  u_int8_t *buf_p;
  int i;

  ring->close              = pfring_anic_close;
  ring->stats              = pfring_anic_stats;
  ring->recv               = pfring_anic_recv;
  ring->poll               = pfring_anic_poll;
  ring->set_direction      = pfring_anic_set_direction;
  ring->enable_ring        = pfring_anic_enable_ring;
  ring->get_bound_device_ifindex = pfring_anic_get_bound_device_ifindex;

  /* Inherited from pfring_mod.c */
  ring->set_socket_mode          = pfring_mod_set_socket_mode;
  ring->set_bound_dev_name       = pfring_mod_set_bound_dev_name;
  ring->set_application_name     = pfring_mod_set_application_name;
  ring->set_application_stats    = pfring_mod_set_application_stats;
  ring->get_appl_stats_file_name = pfring_mod_get_appl_stats_file_name;

  ring->priv_data = NULL;

  ring->fd = socket(PF_RING, SOCK_RAW, htons(ETH_P_ALL)); /* opening PF_RING socket to priaccolade stats under /proc */
  if(ring->fd < 0) return(-1);

  ring->priv_data = calloc(1, sizeof(pfring_anic));

  if(ring->priv_data == NULL)
    goto free_private;

  accolade = (pfring_anic *) ring->priv_data;

  /*
   * Device name anic:X@Y where
   * X port
   * Y ring-id
   */

#ifdef MFL_SUPPORT
  if (strchr(ring->device_name, '@')) {
    sscanf(ring->device_name, "%u@%u", &accolade->device_id, &accolade->ring_id);
    accolade->mfl_mode = 1;
  } else {
#endif
    if (sscanf(ring->device_name, "%u:%u", &accolade->device_id, &accolade->ring_id) != 2) {
      accolade->device_id = 0;
      sscanf(ring->device_name, "%u", &accolade->ring_id);
    }
#ifdef MFL_SUPPORT
    accolade->mfl_mode = 0;
  }
#endif

//#ifdef DEBUG
  printf("[ANIC] Opening anic device=%u, %s=%u\n", accolade->device_id, accolade->mfl_mode ? "ring" : "port" , accolade->ring_id);
//#endif

  accolade->anic_handle = anic_open("/dev/anic", accolade->device_id);

  if (anic_error_code(accolade->anic_handle) != ANIC_ERR_NONE) {
    goto free_private;
  }

#ifdef DEBUG
  printf("[ANIC] Open device /dev/anic\n");
#endif

  accolade->blocksize = ACCOLADE_HUGEPAGE_SIZE;
<commit_msg>comment<commit_after>/*
 *
 * (C) 2015    - ntop.org
 * (C) 2014-15 - Accolade Technology Inc.
 *
 */

#include "pfring_mod_accolade.h"
#include "pfring_mod.h" /* to print stats under /proc */

//#define DEBUG

void *anic_hugepageGet(anic_handle_t anic_handle, int count, int *shmidP);
int anic_hugepageDmaMap(anic_handle_t anic_handle, void *virtualP, int hugepageCount, struct anic_dma_info *dmacbP);

/* **************************************************** */

static void accolade_release_resources(pfring *ring) {
  pfring_anic *accolade = (pfring_anic *) ring->priv_data;

  if (accolade) {
    anic_close(accolade->anic_handle);
    free(ring->priv_data);
    ring->priv_data = NULL;
  }
}

/* **************************************************** */

int pfring_anic_open(pfring *ring) {
  pfring_anic *accolade;
  u_int32_t page, blk;
  u_int8_t *buf_p;
  int i;

  ring->close              = pfring_anic_close;
  ring->stats              = pfring_anic_stats;
  ring->recv               = pfring_anic_recv;
  ring->poll               = pfring_anic_poll;
  ring->set_direction      = pfring_anic_set_direction;
  ring->enable_ring        = pfring_anic_enable_ring;
  ring->get_bound_device_ifindex = pfring_anic_get_bound_device_ifindex;

  /* Inherited from pfring_mod.c */
  ring->set_socket_mode          = pfring_mod_set_socket_mode;
  ring->set_bound_dev_name       = pfring_mod_set_bound_dev_name;
  ring->set_application_name     = pfring_mod_set_application_name;
  ring->set_application_stats    = pfring_mod_set_application_stats;
  ring->get_appl_stats_file_name = pfring_mod_get_appl_stats_file_name;

  ring->priv_data = NULL;

  ring->fd = socket(PF_RING, SOCK_RAW, htons(ETH_P_ALL)); /* opening PF_RING socket to priaccolade stats under /proc */
  if(ring->fd < 0) return(-1);

  ring->priv_data = calloc(1, sizeof(pfring_anic));

  if(ring->priv_data == NULL)
    goto free_private;

  accolade = (pfring_anic *) ring->priv_data;

  /*
   * Device name:
   * 1. anic:D@R
   * 2. anic:D:P
   * 3. anic:P
   * Where D = device, P = port, R = ring (defined with anic_rx_block_mfl, using --mode=2 for RSS or --mode=port for ring-to-port binding)
   * Note: in 2. and 3. it is not possible to run multiple application instances
   */

#ifdef MFL_SUPPORT
  if (strchr(ring->device_name, '@')) {
    sscanf(ring->device_name, "%u@%u", &accolade->device_id, &accolade->ring_id);
    accolade->mfl_mode = 1;
  } else {
#endif
    if (sscanf(ring->device_name, "%u:%u", &accolade->device_id, &accolade->ring_id) != 2) {
      accolade->device_id = 0;
      sscanf(ring->device_name, "%u", &accolade->ring_id);
    }
#ifdef MFL_SUPPORT
    accolade->mfl_mode = 0;
  }
#endif

#ifdef DEBUG
  printf("[ANIC] Opening anic device=%u, %s=%u\n", accolade->device_id, accolade->mfl_mode ? "ring" : "port" , accolade->ring_id);
#endif

  accolade->anic_handle = anic_open("/dev/anic", accolade->device_id);

  if (anic_error_code(accolade->anic_handle) != ANIC_ERR_NONE) {
    goto free_private;
  }

#ifdef DEBUG
  printf("[ANIC] Open device /dev/anic\n");
#endif

  accolade->blocksize = ACCOLADE_HUGEPAGE_SIZE;

{'fraction_non_alphanumeric': 0.16350947158524426, 'fraction_numerical': 0.007643735460285809, 'mean_word_length': 3.9054604726976363, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 85, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5305985', 'n_tokens_mistral': 2414, 'n_tokens_neox': 2293, 'n_words': 399}