<commit_before>#!/usr/bin/env python

import argparse

import sys, socket, time, os
from multiprocessing import Process

import yaml
import ipaddress

PORT = 514
NR_LISTENERS = 1
CORES = 0

SO_REUSEPORT = 15

BUFSIZE = 1024

CONFIG = 'config.yml'

def listener_work(num, config, port):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.setsockopt(socket.SOL_SOCKET, SO_REUSEPORT, 1)   # set SO_REUSEPORT
    s.bind(("", port))

    src_security = ipaddress.ip_network(config['syslog']['src-security'])

    try:
        while True:
            data, addr = s.recvfrom(BUFSIZE)

            # syslog
            if port == config['port']['syslog']:
                # security only
                src_ip = ipaddress.ip_network(dst)

#                if addr[0] in config['syslog']['src-security']:
                if src_ip.compare_networks(src_security) == 1:
                    # src securityからのsyslog
                    for dst in config['syslog']['dst-security-only']:
                        # security-onlyへ飛ばす
                        s.sendto(data, (dst, port))
                else:
                    # mgmt(security以外)からのsyslog
                    for dst in config['syslog']['dst-mgmt-only']:
                        # mgmt-onlyへ飛ばす
                        s.sendto(data, (dst, port))

                # all
                for dst in config['syslog']['dst-all']:
                    s.sendto(data, (dst, port))
            # trap
            elif port == config['port']['trap']:
                for dst in config['trap']['dst-all']:
                    s.sendto(data, (dst, port))
            # xflow<commit_msg>fix bug<commit_after>#!/usr/bin/env python

import argparse

import sys, socket, time, os
from multiprocessing import Process

import yaml
import ipaddress

PORT = 514
NR_LISTENERS = 1
CORES = 0

SO_REUSEPORT = 15

BUFSIZE = 1024

CONFIG = 'config.yml'

def listener_work(num, config, port):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.setsockopt(socket.SOL_SOCKET, SO_REUSEPORT, 1)   # set SO_REUSEPORT
    s.bind(("", port))

    src_security = ipaddress.ip_network(config['syslog']['src-security'])

    try:
        while True:
            data, addr = s.recvfrom(BUFSIZE)

            # syslog
            if port == config['port']['syslog']:
                # security only
                src_ip = ipaddress.ip_network(addr[0])

#                if addr[0] in config['syslog']['src-security']:
                if src_ip.compare_networks(src_security) == 1:
                    # src securityからのsyslog
                    for dst in config['syslog']['dst-security-only']:
                        # security-onlyへ飛ばす
                        s.sendto(data, (dst, port))
                else:
                    # mgmt(security以外)からのsyslog
                    for dst in config['syslog']['dst-mgmt-only']:
                        # mgmt-onlyへ飛ばす
                        s.sendto(data, (dst, port))

                # all
                for dst in config['syslog']['dst-all']:
                    s.sendto(data, (dst, port))
            # trap
            elif port == config['port']['trap']:
                for dst in config['trap']['dst-all']:
                    s.sendto(data, (dst, port))
            # xflow
{'fraction_non_alphanumeric': 0.12026862026862027, 'fraction_numerical': 0.008852258852258852, 'mean_word_length': 1.6599025974025974, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6289322', 'n_tokens_mistral': 1054, 'n_tokens_neox': 975, 'n_words': 212}