interface.c 1.91 KB
Newer Older
Arne Øslebø's avatar
Arne Øslebø committed
1
2
3
4
5
6
7
8
9
10
11
12
#include <stdlib.h>
#include <stdio.h>
#include <sys/shm.h>
#include <string.h>
#include <errno.h>
#include <dagapi.h>
#include "mapidflib.h"
#include "mapidlib.h"
#include "mapidevices.h"
#include "mapid.h"
#include "fhelp.h"

's avatar
committed
13
typedef struct interface_instance_type {
Arne Øslebø's avatar
Arne Øslebø committed
14
15
16
17
  int ifindex;
} interface_instance_t;

static int interface_instance(mapidflib_function_instance_t *instance,
18
19
			      MAPI_UNUSED int fd,
			   MAPI_UNUSED mapidflib_flow_mod_t *flow_mod)
Arne Øslebø's avatar
Arne Øslebø committed
20
21
22
23
24
25
26
27
28
29
30
{
  mapiFunctArg* a=instance->args;
  int ifindex = getargint(&a);
  
  if(ifindex<0)
    return MFUNCT_INVALID_ARGUMENT;
  
  return 0;
}

static int interface_init(mapidflib_function_instance_t *instance,
31
			  MAPI_UNUSED int fd)
Arne Øslebø's avatar
Arne Øslebø committed
32
33
34
35
36
37
38
39
40
41
42
43
44
//Initializes the function
{
  interface_instance_t *i=malloc(sizeof(interface_instance_t)); 
  mapiFunctArg* fargs=instance->args;

  i->ifindex=getargint(&fargs);

  instance->internal_data=i;
  return 0;
}

static int interface_process(mapidflib_function_instance_t *instance,
			const unsigned char* dev_pkt,
45
46
			MAPI_UNUSED const unsigned char* link_pkt,
			MAPI_UNUSED mapid_pkthdr_t* pkt_head)  
Arne Øslebø's avatar
Arne Øslebø committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{
  dag_record_t *rec=(dag_record_t*)dev_pkt;
  interface_instance_t *i=instance->internal_data;

   if(rec->flags.iface==i->ifindex)
    return 1;
   
  return 0;
}

static mapidflib_function_def_t finfo={
  "", //libname
  "INTERFACE", //name
  "Filters packets from specific interfaces on an adapter", //descr
  "i", //argdescr
  MAPI_DEVICE_DAG, //devtype
  MAPIRES_NONE, //Method for returning results
  0, //shm size
  0, //modifies_pkts
66
67
  1, //filters packets
  MAPIOPT_AUTO,
Arne Øslebø's avatar
Arne Øslebø committed
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
  interface_instance, //instance
  interface_init, //init
  interface_process, //process
  NULL, //get_result,
  NULL, //change_args
  NULL, //reset
  NULL, //cleanup
  NULL, //client_init
  NULL, //client_read_result
  NULL  //client_cleanup
};

mapidflib_function_def_t* interface_get_funct_info();

mapidflib_function_def_t* interface_get_funct_info() {
  return &finfo;
};