00001
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "mac_lib.h"
00037
00038
00039 long long null_throughput(void)
00040 {
00041 return 1;
00042 }
00043
00044
00045 int null_filter(struct oq_req_resp *rr)
00046 {
00047 if (rr == NULL)
00048 return -1;
00049
00050 rr->num_msgs = 1;
00051 rr->msgs[0].code = OQ_SKB_PASS;
00052 return 0;
00053 }
00054
00055
00056
00057
00058
00059 int protocol_filter(char *name, struct oq_req_resp *rr)
00060 {
00061 struct protocol_entry *entry =
00062 (struct protocol_entry *) &protocol_table;
00063 mac_filter_t filter = NULL;
00064
00065 while (entry != NULL) {
00066 if (strncmp(name, entry->name, strlen(entry->name)) == 0) {
00067 filter = entry->mac_filter;
00068 break;
00069 }
00070 entry = entry->next;
00071 }
00072 if (filter != NULL)
00073 return (*filter)(rr);
00074
00075 return -INT_MAX;
00076 }
00077
00078
00079 long long protocol_throughput(char *name)
00080 {
00081 struct protocol_entry *entry =
00082 (struct protocol_entry *) &protocol_table;
00083 mac_throughput_t thru = NULL;
00084
00085 while (entry != NULL) {
00086 if (strncmp(name, entry->name, strlen(entry->name)) == 0) {
00087 thru = entry->mac_throughput;
00088 break;
00089 }
00090 entry = entry->next;
00091 }
00092 if (thru != NULL)
00093 return (*thru)();
00094
00095 return -1;
00096 }
00097
00098
00099
00100 void add_protocol(char *path, char *name, char *filter, char *through)
00101 {
00102 void *lib;
00103 struct protocol_entry *entry =
00104 (struct protocol_entry *) &protocol_table;
00105
00106 while (entry->next != NULL)
00107 entry = entry->next;
00108
00109 if ((lib = dlopen(path, RTLD_LAZY)) != NULL) {
00110 struct protocol_entry *next_entry = (struct protocol_entry *)
00111 malloc(sizeof(struct protocol_entry));
00112 strncpy(next_entry->name, name, MAX_NAME);
00113 next_entry->mac_filter = (mac_filter_t) dlsym(lib, filter);
00114 next_entry->mac_throughput =
00115 (mac_throughput_t) dlsym(lib, through);
00116 next_entry->next = NULL;
00117 entry->next = next_entry;
00118 }
00119 }
00120
00121
00122 void remove_protocol(char *name)
00123 {
00124 struct protocol_entry *entry = protocol_table.next;
00125 struct protocol_entry *prev =
00126 (struct protocol_entry *) &protocol_table;
00127
00128 if (strncmp(name, "null", 4))
00129 return;
00130
00131 while (entry != NULL) {
00132 if (strncmp(name, entry->name, strlen(entry->name)) == 0) {
00133 prev->next = entry->next;
00134 free(entry);
00135 break;
00136 }
00137 prev = entry;
00138 entry = entry->next;
00139 }
00140 }