Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 1 Jun 1997 16:01:36 +0200
From:      =?iso-8859-1?Q?=C5ge_R=F8bekk?= <aagero@aage.priv.no>
To:        freebsd-hackers@freebsd.org
Subject:   IPDIVERT not working in 2.2.2
Message-ID:  <19970601160135.28385@aage.priv.no>

index | next in thread | raw e-mail

[-- Attachment #1 --]
I'm having problems getting IPDIVERT and friends working on
FreeBSD-2.2.2.  When the kernel has booted and the drivers are
initialized, the kernel says

IP packet filtering initialized, divert enabled, unlimited logging

as expected.  However, binding to a divert socket and read()ing gives
no data no matter what i try.  The exact same setup works perfectly
fine in -CURRENT, although that is on another machine.  The 2.2.2 box
has 2 vx network cards, but I do not think that the divert layer can
be affected by such a low-level layer.  If someone could build and
test the extremely-crude and high-speed hacked together divert test
program attached to this mail, perhaps we could narrow out what i've
missed:

cc diverttest.c -o diverttest

ipfw add 00001 divert 32768 ip from any to any via <your-interface>
./diverttest 32768

any inbound traffic should be displayed as

read nn bytes

-aage

[-- Attachment #2 --]
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>

#define BUFFSIZ 1600 /* should be MTU perhaps? */

int
main(int argc, char **argv)
{
  int divertsock, port, rdsz;
  struct sockaddr_in addr;
  char *buff;

  if(argc < 2) {
    fprintf(stderr, "%s port\n", argv[0]);
    exit(1);
  }

  if((divertsock = socket(PF_INET, SOCK_RAW, IPPROTO_DIVERT)) == -1) {
    perror("socket");
    exit(1);
  }

  port = atoi(argv[1]);
  
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = INADDR_ANY;
  addr.sin_port = ntohs(port);

  if(bind(divertsock, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) < 0) {
    perror("bind");
    exit(1);
  }

  if((buff = malloc(BUFFSIZ)) == NULL) {
    fprintf(stderr, "malloc error\n");
    exit(1);
  }

  for(;;) {
    rdsz = read(divertsock, buff, BUFFSIZ);
    fprintf(stderr, "read %d bytes\n", rdsz);
  }

  return 0; /* Just to shut up gcc */
}

help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19970601160135.28385>