struct packet_info *packet_info_pool_clone(struct proto *p, struct packet_info *info) { struct packet_info *new_info = packet_info_pool_get(p); if (!new_info) return NULL; struct proto_pkt_field *fields = p->info->pkt_fields; int i; for (i = 0; fields[i].name; i++) { if (ptype_copy(new_info->fields_value[i], info->fields_value[i]) != POM_OK) { packet_info_pool_release(new_info, p->id); return NULL; } } return new_info; }
int registry_set_param_value(struct registry_param *p, char *value) { if (!p || !value) return POM_ERR; if (p->flags & REGISTRY_PARAM_FLAG_IMMUTABLE) return POM_ERR; if (p->set_pre_callback && p->set_pre_callback(p->callback_priv, value) != POM_OK) { return POM_ERR; } core_pause_processing(); struct ptype *old_value = ptype_alloc_from(p->value); if (ptype_parse_val(p->value, value) != POM_OK) { core_resume_processing(); ptype_cleanup(old_value); return POM_ERR; } if (p->set_post_callback && p->set_post_callback(p->callback_priv, p->value) != POM_OK) { // Revert the old value ptype_copy(p->value, old_value); core_resume_processing(); ptype_cleanup(old_value); return POM_ERR; } core_resume_processing(); ptype_cleanup(old_value); return POM_OK; }
int analyzer_ppp_pap_finalize(struct analyzer_ppp_pap_priv *apriv, struct analyzer_ppp_pap_ce_priv *cpriv) { if (!cpriv->evt_request) return POM_OK; struct event *evt = NULL; struct data *evt_data = NULL; struct data *evt_req_data = event_get_data(cpriv->evt_request); evt = event_alloc(apriv->evt_auth); if (!evt) return POM_ERR; evt_data = event_get_data(evt); if (ptype_copy(evt_data[analyzer_ppp_pap_auth_peer_id].value, evt_req_data[evt_ppp_pap_request_peer_id].value) != POM_OK) { event_cleanup(evt); return POM_ERR; } data_set(evt_data[analyzer_ppp_pap_auth_peer_id]); if (ptype_copy(evt_data[analyzer_ppp_pap_auth_password].value, evt_req_data[evt_ppp_pap_request_password].value) != POM_OK) { event_cleanup(evt); return POM_ERR; } data_set(evt_data[analyzer_ppp_pap_auth_password]); if (cpriv->client) { evt_data[analyzer_ppp_pap_auth_client].value = cpriv->client; data_set(evt_data[analyzer_ppp_pap_auth_client]); data_do_clean(evt_data[analyzer_ppp_pap_auth_client]); cpriv->client = NULL; } if (cpriv->server) { evt_data[analyzer_ppp_pap_auth_server].value = cpriv->server; data_set(evt_data[analyzer_ppp_pap_auth_server]); data_do_clean(evt_data[analyzer_ppp_pap_auth_server]); cpriv->server = NULL; } if (cpriv->vlan) { evt_data[analyzer_ppp_pap_auth_vlan].value = cpriv->vlan; data_set(evt_data[analyzer_ppp_pap_auth_vlan]); data_do_clean(evt_data[analyzer_ppp_pap_auth_vlan]); cpriv->vlan = NULL; } if (cpriv->top_proto) { PTYPE_STRING_SETVAL(evt_data[analyzer_ppp_pap_auth_top_proto].value, cpriv->top_proto); data_set(evt_data[analyzer_ppp_pap_auth_top_proto]); } if (ptype_copy(evt_data[analyzer_ppp_pap_auth_identifier].value, evt_req_data[evt_ppp_pap_request_identifier].value) != POM_OK) { event_cleanup(evt); return POM_ERR; } data_set(evt_data[analyzer_ppp_pap_auth_identifier]); if (cpriv->evt_ack_nack) { struct data *evt_ack_data = event_get_data(cpriv->evt_ack_nack); uint8_t code = *PTYPE_UINT8_GETVAL(evt_ack_data[evt_ppp_pap_ack_nack_code].value); if (code == 2) { PTYPE_BOOL_SETVAL(evt_data[analyzer_ppp_pap_auth_success].value, 1); } else { PTYPE_BOOL_SETVAL(evt_data[analyzer_ppp_pap_auth_success].value, 0); } data_set(evt_data[analyzer_ppp_pap_auth_success]); event_refcount_dec(cpriv->evt_ack_nack); cpriv->evt_ack_nack = NULL; } ptime ts = event_get_timestamp(cpriv->evt_request); event_refcount_dec(cpriv->evt_request); cpriv->evt_request = NULL; return event_process(evt, NULL, 0, ts); }
static int analyzer_rtp_pload_process(void *obj, struct packet *p, struct proto_process_stack *stack, unsigned int stack_index) { struct analyzer *analyzer = obj; struct analyzer_rtp_priv *priv = analyzer->priv; struct proto_process_stack *pload_stack = &stack[stack_index]; struct proto_process_stack *s = &stack[stack_index - 1]; if (!s->ce) return POM_ERR; struct analyzer_rtp_ce_priv *cp = conntrack_get_priv(s->ce, obj); if (!cp) { cp = malloc(sizeof(struct analyzer_rtp_ce_priv)); if (!cp) { pom_oom(sizeof(struct analyzer_rtp_ce_priv)); return POM_ERR; } memset(cp, 0, sizeof(struct analyzer_rtp_ce_priv)); if (conntrack_add_priv(s->ce, obj, cp, analyzer_rtp_ce_cleanup) != POM_OK) return POM_ERR; } int dir = s->direction; if (!cp->evt[dir]) { cp->evt[dir] = event_alloc(priv->evt_rtp_stream); if (!cp->evt[dir]) return POM_ERR; struct data *evt_data = event_get_data(cp->evt[dir]); ptype_copy(evt_data[analyzer_rtp_stream_ssrc].value, s->pkt_info->fields_value[proto_rtp_field_ssrc]); data_set(evt_data[analyzer_rtp_stream_ssrc]); // For now we always assume RTP is over UDP or TCP if (stack_index > 2) { struct proto_process_stack *l4_stack = &stack[stack_index - 2]; unsigned int i; for (i = 0; !data_is_set(evt_data[analyzer_rtp_stream_src_port]) || !data_is_set(evt_data[analyzer_rtp_stream_dst_port]); i++) { struct proto_reg_info *l4_info = proto_get_info(l4_stack->proto); char *name = l4_info->pkt_fields[i].name; if (!name) break; if (!data_is_set(evt_data[analyzer_rtp_stream_src_port]) && !strcmp(name, "sport")) { ptype_copy(evt_data[analyzer_rtp_stream_src_port].value, l4_stack->pkt_info->fields_value[i]); data_set(evt_data[analyzer_rtp_stream_src_port]); } else if (!data_is_set(evt_data[analyzer_rtp_stream_dst_port]) && !strcmp(name, "dport")) { ptype_copy(evt_data[analyzer_rtp_stream_dst_port].value, l4_stack->pkt_info->fields_value[i]); data_set(evt_data[analyzer_rtp_stream_dst_port]); } } } if (stack_index > 3) { struct proto_process_stack *l3_stack = &stack[stack_index - 3]; unsigned int i; for (i = 0; !data_is_set(evt_data[analyzer_rtp_stream_src_addr]) || !data_is_set(evt_data[analyzer_rtp_stream_dst_addr]); i++) { struct proto_reg_info *l3_info = proto_get_info(l3_stack->proto); char *name = l3_info->pkt_fields[i].name; if (!name) break; if (!data_is_set(evt_data[analyzer_rtp_stream_src_addr]) && !strcmp(name, "src")) { evt_data[analyzer_rtp_stream_src_addr].value = ptype_alloc_from(l3_stack->pkt_info->fields_value[i]); if (evt_data[analyzer_rtp_stream_src_addr].value) data_set(evt_data[analyzer_rtp_stream_src_addr]); } else if (!data_is_set(evt_data[analyzer_rtp_stream_dst_addr]) && !strcmp(name, "dst")) { evt_data[analyzer_rtp_stream_dst_addr].value = ptype_alloc_from(l3_stack->pkt_info->fields_value[i]); if (evt_data[analyzer_rtp_stream_dst_addr].value) data_set(evt_data[analyzer_rtp_stream_dst_addr]); } } } struct proto *sess_proto = telephony_stream_info_get_sess_proto(s->ce); if (sess_proto) { struct proto_reg_info *proto_reg = proto_get_info(sess_proto); PTYPE_STRING_SETVAL(evt_data[analyzer_rtp_stream_sess_proto].value, proto_reg->name); data_set(evt_data[analyzer_rtp_stream_sess_proto]); } char *call_id = telephony_stream_info_get_call_id(s->ce); if (call_id) { PTYPE_STRING_SETVAL_P(evt_data[analyzer_rtp_stream_call_id].value, call_id); data_set(evt_data[analyzer_rtp_stream_call_id]); } if (event_process_begin(cp->evt[dir], stack, stack_index, p->ts) != POM_OK) return POM_ERR; } if (!cp->pload[dir]) { cp->pload[dir] = pload_alloc(cp->evt[dir], 0); if (!cp->pload[dir]) return POM_ERR; struct telephony_codec_info info = { 0 }; if (telephony_stream_info_get_codec(&info, stack, stack_index - 1) == POM_OK) { char *pload_type = telephony_codec_info_get_pload_type(&info); if (pload_type) pload_set_type(cp->pload[dir], pload_type); } } if (pload_append(cp->pload[dir], pload_stack->pload, pload_stack->plen) != POM_OK) return POM_ERR; return POM_OK; }
static int analyzer_arp_pkt_process(void *obj, struct packet *p, struct proto_process_stack *stack, unsigned int stack_index) { struct analyzer *analyzer = obj; struct analyzer_arp_priv *priv = analyzer->priv; struct proto_process_stack *s = &stack[stack_index]; struct proto_process_stack *s_prev = &stack[stack_index - 1]; struct in_addr arp_ip = PTYPE_IPV4_GETADDR(s->pkt_info->fields_value[proto_arp_field_sender_proto_addr]); // Discard bogon 0.0.0.0 if (!arp_ip.s_addr) return POM_OK; // Find that IP in the table uint32_t id = arp_ip.s_addr & ANALYZER_ARP_HOST_MASK; char *arp_mac = PTYPE_MAC_GETADDR(s->pkt_info->fields_value[proto_arp_field_sender_hw_addr]); uint16_t vlan = 0; if (s_prev->proto == priv->proto_vlan) vlan = *PTYPE_UINT16_GETVAL(s_prev->pkt_info->fields_value[proto_vlan_field_vid]); pom_mutex_lock(&priv->lock); struct analyzer_arp_host *host; for (host = priv->hosts[id]; host; host = host->next) { if (host->ip.s_addr == arp_ip.s_addr && host->vlan == vlan) break; } if (!host) { // Host not found ! host = malloc(sizeof(struct analyzer_arp_host)); if (!host) { pom_mutex_unlock(&priv->lock); pom_oom(sizeof(struct analyzer_arp_host)); return POM_ERR; } memset(host, 0, sizeof(struct analyzer_arp_host)); host->ip.s_addr = arp_ip.s_addr; memcpy(host->mac, arp_mac, sizeof(host->mac)); host->vlan = vlan; host->next = priv->hosts[id]; if (host->next) host->next->prev = host; priv->hosts[id] = host; pom_mutex_unlock(&priv->lock); // Announce the new station if (event_has_listener(priv->evt_new_sta)) { struct event *evt = event_alloc(priv->evt_new_sta); if (!evt) return POM_ERR; struct data *evt_data = evt->data; ptype_copy(evt_data[analyzer_arp_new_sta_mac_addr].value, s->pkt_info->fields_value[proto_arp_field_sender_hw_addr]); data_set(evt_data[analyzer_arp_new_sta_mac_addr]); ptype_copy(evt_data[analyzer_arp_new_sta_ip_addr].value, s->pkt_info->fields_value[proto_arp_field_sender_proto_addr]); data_set(evt_data[analyzer_arp_new_sta_ip_addr]); PTYPE_UINT16_SETVAL(evt_data[analyzer_arp_new_sta_vlan].value, vlan); data_set(evt_data[analyzer_arp_new_sta_vlan]); PTYPE_STRING_SETVAL(evt_data[analyzer_arp_new_sta_input].value, p->input->name); data_set(evt_data[analyzer_arp_new_sta_input]); if (event_process(evt, stack, stack_index) != POM_OK) return POM_ERR; } // Nothing else to do return POM_OK; } // Host was found, check mac if (memcmp(host->mac, arp_mac, sizeof(host->mac))) { if (event_has_listener(priv->evt_sta_changed)) { struct event *evt = event_alloc(priv->evt_sta_changed); if (!evt) { pom_mutex_unlock(&priv->lock); return POM_ERR; } struct data *evt_data = evt->data; PTYPE_MAC_SETADDR(evt_data[analyzer_arp_sta_changed_old_mac_addr].value, host->mac); data_set(evt_data[analyzer_arp_sta_changed_old_mac_addr]); ptype_copy(evt_data[analyzer_arp_sta_changed_new_mac_addr].value, s->pkt_info->fields_value[proto_arp_field_sender_hw_addr]); data_set(evt_data[analyzer_arp_sta_changed_new_mac_addr]); ptype_copy(evt_data[analyzer_arp_sta_changed_ip_addr].value, s->pkt_info->fields_value[proto_arp_field_sender_proto_addr]); data_set(evt_data[analyzer_arp_sta_changed_ip_addr]); PTYPE_UINT16_SETVAL(evt_data[analyzer_arp_sta_changed_vlan].value, vlan); data_set(evt_data[analyzer_arp_sta_changed_vlan]); PTYPE_STRING_SETVAL(evt_data[analyzer_arp_sta_changed_input].value, p->input->name); data_set(evt_data[analyzer_arp_sta_changed_input]); if (event_process(evt, stack, stack_index) != POM_OK) { pom_mutex_unlock(&priv->lock); return POM_ERR; } } memcpy(host->mac, arp_mac, sizeof(host->mac)); } pom_mutex_unlock(&priv->lock); return POM_OK; }
int analyzer_eap_finalize(struct analyzer_eap_priv *apriv, struct analyzer_eap_ce_priv *cpriv) { if (!cpriv->evt_request || !cpriv->evt_response) return POM_OK; struct event *evt = NULL; struct data *evt_data = NULL; struct data *evt_req_data = event_get_data(cpriv->evt_request); struct data *evt_rsp_data = event_get_data(cpriv->evt_response); if (!data_is_set(evt_rsp_data[evt_eap_md5_challenge_value])) return POM_OK; if (!data_is_set(evt_req_data[evt_eap_md5_challenge_value])) return POM_OK; evt = event_alloc(apriv->evt_md5_auth); if (!evt) return POM_ERR; evt_data = event_get_data(evt); if (ptype_copy(evt_data[analyzer_eap_md5_challenge].value, evt_req_data[evt_eap_md5_challenge_value].value) != POM_OK) return POM_ERR; data_set(evt_data[analyzer_eap_md5_challenge]); if (ptype_copy(evt_data[analyzer_eap_md5_response].value, evt_rsp_data[evt_eap_md5_challenge_value].value) != POM_OK) return POM_ERR; data_set(evt_data[analyzer_eap_md5_response]); if (cpriv->client) { evt_data[analyzer_eap_common_client].value = cpriv->client; data_set(evt_data[analyzer_eap_common_client]); data_do_clean(evt_data[analyzer_eap_common_client]); cpriv->client = NULL; } if (cpriv->server) { evt_data[analyzer_eap_common_server].value = cpriv->server; data_set(evt_data[analyzer_eap_common_server]); data_do_clean(evt_data[analyzer_eap_common_server]); cpriv->server = NULL; } if (cpriv->vlan) { evt_data[analyzer_eap_common_vlan].value = cpriv->vlan; data_set(evt_data[analyzer_eap_common_vlan]); data_do_clean(evt_data[analyzer_eap_common_vlan]); cpriv->vlan = NULL; } if (cpriv->top_proto) { PTYPE_STRING_SETVAL(evt_data[analyzer_eap_common_top_proto].value, cpriv->top_proto); data_set(evt_data[analyzer_eap_common_top_proto]); } if (ptype_copy(evt_data[analyzer_eap_common_identifier].value, evt_req_data[evt_eap_common_identifier].value) != POM_OK) return POM_ERR; data_set(evt_data[analyzer_eap_common_identifier]); if (!data_is_set(evt_rsp_data[evt_eap_md5_challenge_name])) return POM_OK; if (ptype_copy(evt_data[analyzer_eap_common_username].value, evt_rsp_data[evt_eap_md5_challenge_name].value) != POM_OK) return POM_ERR; data_set(evt_data[analyzer_eap_common_username]); if (cpriv->evt_result) { struct data *evt_res_data = event_get_data(cpriv->evt_result); ptype_copy(evt_data[analyzer_eap_common_success].value, evt_res_data[evt_eap_success_failure_success].value); data_set(evt_data[analyzer_eap_common_success]); event_refcount_dec(cpriv->evt_result); cpriv->evt_result = NULL; } ptime ts = event_get_timestamp(cpriv->evt_response); event_refcount_dec(cpriv->evt_request); cpriv->evt_request = NULL; event_refcount_dec(cpriv->evt_response); cpriv->evt_response = NULL; return event_process(evt, NULL, 0, ts); }