Exemplo n.º 1
0
// Connects to the group specified with the size
func (nflog *NfLog) makeGroup(group, size int) {
	if *Verbose {
		log.Printf("Binding this socket to group %d", group)
	}
	gh, err := C._nflog_bind_group(nflog.h, C.int(group))
	if gh == nil || err != nil {
		log.Fatalf("nflog_bind_group failed: %s", nflogError(err))
	}
	nflog.gh = gh

	// Set the maximum amount of logs in buffer for this group
	if rc, err := C.nflog_set_qthresh(gh, MaxQueueLogs); rc < 0 || err != nil {
		log.Fatalf("nflog_set_qthresh failed: %s", nflogError(err))
	}

	// Set local sequence numbering to detect missing packets
	if rc, err := C.nflog_set_flags(gh, C.NFULNL_CFG_F_SEQ); rc < 0 || err != nil {
		log.Fatalf("nflog_set_flags failed: %s", nflogError(err))
	}

	// Set buffer size large
	if rc, err := C.nflog_set_nlbufsiz(gh, NflogBufferSize); rc < 0 || err != nil {
		log.Fatalf("nflog_set_nlbufsiz: %s", nflogError(err))
	}

	// Set recv buffer large - this produces ENOBUFS when too small
	if rc, err := C.nfnl_rcvbufsiz(C.nflog_nfnlh(nflog.h), NfRecvBufferSize); rc < 0 || err != nil {
		log.Fatalf("nfnl_rcvbufsiz: %s", err)
	} else {
		if rc < NfRecvBufferSize {
			log.Fatalf("nfnl_rcvbufsiz: Failed to set buffer to %d got %d", NfRecvBufferSize, rc)
		}
	}

	// Set timeout
	if rc, err := C.nflog_set_timeout(gh, NflogTimeout); rc < 0 || err != nil {
		log.Fatalf("nflog_set_timeout: %s", nflogError(err))
	}

	if *Verbose {
		log.Printf("Setting copy_packet mode to %d bytes", size)
	}
	if rc, err := C.nflog_set_mode(gh, C.NFULNL_COPY_PACKET, (C.uint)(size)); rc < 0 || err != nil {
		log.Fatalf("nflog_set_mode failed: %s", nflogError(err))
	}

	// Register the callback now we are set up
	//
	// Note that we pass a block of memory allocated by C.malloc -
	// it isn't a good idea for C to hold pointers to go objects
	// which might move
	C._callback_register(gh, nflog.packets)
}
Exemplo n.º 2
0
// Connects to the group specified with the size
func (nflog *NfLog) makeGroup(group, size int) {
	if *Debug {
		log.Printf("Binding this socket to group %d", group)
	}
	gh := C.nflog_bind_group(nflog.h, (C.u_int16_t)(group))
	if gh == nil {
		log.Fatalf("nflog_bind_group failed: %s", strerror())
	}
	nflog.gh = gh

	// Set the maximum amount of logs in buffer for this group
	if C.nflog_set_qthresh(gh, MaxQueueLogs) < 0 {
		log.Fatalf("nflog_set_qthresh failed: %s", strerror())
	}

	// Set local sequence numbering to detect missing packets
	if C.nflog_set_flags(gh, C.NFULNL_CFG_F_SEQ) < 0 {
		log.Fatalf("nflog_set_flags failed: %s", strerror())
	}

	// Set buffer size large
	if C.nflog_set_nlbufsiz(gh, NflogBufferSize) < 0 {
		log.Fatalf("nflog_set_nlbufsiz: %s", strerror())
	}

	// Set timeout
	// Doesn't seem to make any difference and don't know the unit
	// if C.nflog_set_timeout(gh, NflogTimeout) < 0 {
	// 	log.Fatalf("nflog_set_timeout: %s", strerror())
	// }

	if *Debug {
		log.Printf("Setting copy_packet mode to %d bytes", size)
	}
	if C.nflog_set_mode(gh, C.NFULNL_COPY_PACKET, (C.uint)(size)) < 0 {
		log.Fatalf("nflog_set_mode failed: %s", strerror())
	}

	// Register the callback now we are set up
	C._callback_register(gh, unsafe.Pointer(nflog))
}