static void blockprotocol_notify(void *buffer, unsigned int count) { union event_message message; event_create(&message, EVENT_DATA); event_append(&message, count, buffer); kernel_multicast(EVENT_BROADCAST, &blockprotocol.data.states, &message); }
static void ethernetprotocol_notify(struct ethernet_header *ethernetheader, void *buffer, unsigned int count) { union event_message message; struct arp_header *header = buffer; unsigned char *data = (unsigned char *)(header + 1); unsigned int htype = (header->htype[0] << 8) | header->htype[1]; unsigned int ptype = (header->ptype[0] << 8) | header->ptype[1]; unsigned int operation = (header->operation[0] << 8) | header->operation[1]; unsigned char *sha = data; unsigned char *spa = data + header->hlength; unsigned char *tha = data + header->hlength + header->plength; unsigned char *tpa = data + header->hlength + header->plength + header->hlength; struct arp_hook *hook = findhook(htype, header->hlength, ptype, header->plength); if (hook) { switch (operation) { case ARP_REQUEST: hook->save(sha, spa); tha = hook->lookup(tpa); if (tha) { unsigned char response[ETHERNET_MTU]; unsigned char *current = arp_writehead(response, htype, header->hlength, ptype, header->plength, ARP_REPLY, tha, tpa, sha, spa); ethernet_send(response, current - response); } break; case ARP_REPLY: hook->save(sha, spa); break; } } event_create(&message, EVENT_DATA); event_append(&message, count, buffer); kernel_multicast(EVENT_BROADCAST, ðernetprotocol.data.states, &message); }
static void ethernetprotocol_notify(struct ethernet_interface *interface, void *buffer, unsigned int count) { struct arp_header *header = buffer; unsigned char *data = (unsigned char *)(header + 1); unsigned short htype; unsigned short ptype; unsigned short operation; struct list_item *current; if (count < sizeof (struct arp_header)) return; htype = (header->htype[0] << 8) | header->htype[1]; ptype = (header->ptype[0] << 8) | header->ptype[1]; operation = (header->operation[0] << 8) | header->operation[1]; for (current = hooks.head; current; current = current->next) { struct arp_hook *hook = current->data; unsigned char response[ETHERNET_MTU]; unsigned char *haddress; unsigned int c = 0; if (!hook->match(htype, header->hlength, ptype, header->plength)) continue; switch (operation) { case ARP_REQUEST: haddress = hook->lookup(data + header->hlength + header->plength + header->hlength); if (!haddress) continue; c += ethernet_writeheader(ðernetprotocol, interface->haddress, data, response); c += arp_writeheader(htype, header->hlength, ptype, header->plength, ARP_REPLY, haddress, data + header->hlength + header->plength + header->hlength, data, data + header->hlength, response + c); interface->send(response, c); break; } } kernel_multicast(ðernetprotocol.datalinks, buffer, count); }
static void write(struct list *states, unsigned int level, char *string, char *file, unsigned int line) { union event_message message; char num[FUDGE_NSIZE]; event_create(&message, EVENT_DATA); switch (level) { case DEBUG_CRITICAL: event_append(&message, 7, "[CRIT] "); break; case DEBUG_ERROR: event_append(&message, 7, "[ERRO] "); break; case DEBUG_WARNING: event_append(&message, 7, "[WARN] "); break; case DEBUG_INFO: event_append(&message, 7, "[INFO] "); break; } event_append(&message, ascii_length(string), string); event_append(&message, 2, " ("); event_append(&message, ascii_length(file), file); event_append(&message, 1, ":"); event_append(&message, ascii_wvalue(num, FUDGE_NSIZE, line, 10), num); event_append(&message, 2, ")\n"); kernel_multicast(EVENT_BROADCAST, states, &message); }
void ethernet_notify(struct ethernet_interface *interface, void *buffer, unsigned int count) { union event_message message; struct ethernet_header *header = buffer; unsigned int type = (header->type[0] << 8) | header->type[1]; struct resource *current = 0; while ((current = resource_foreachtype(current, RESOURCE_ETHERNETPROTOCOL))) { struct ethernet_protocol *protocol = current->data; if (protocol->type == type) protocol->notify(header, header + 1, count - 18); } event_create(&message, EVENT_DATA); event_append(&message, count, buffer); kernel_multicast(EVENT_BROADCAST, &interface->data.states, &message); }