ifpfsync.c revision 142215
113840Swosch/* 213840Swosch * Copyright (c) 2003 Ryan McBride. All rights reserved. 313840Swosch * Copyright (c) 2004 Max Laier. All rights reserved. 413840Swosch * 513840Swosch * Redistribution and use in source and binary forms, with or without 613840Swosch * modification, are permitted provided that the following conditions 713840Swosch * are met: 813840Swosch * 1. Redistributions of source code must retain the above copyright 913840Swosch * notice, this list of conditions and the following disclaimer. 1013840Swosch * 2. Redistributions in binary form must reproduce the above copyright 1113840Swosch * notice, this list of conditions and the following disclaimer in the 1213840Swosch * documentation and/or other materials provided with the distribution. 1313840Swosch * 1413840Swosch * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1513840Swosch * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1613840Swosch * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1713840Swosch * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1813840Swosch * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1913840Swosch * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2013840Swosch * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2113840Swosch * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2213840Swosch * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2313840Swosch * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2413840Swosch * SUCH DAMAGE. 2513840Swosch * 2613840Swosch * $FreeBSD: head/sbin/ifconfig/ifpfsync.c 142215 2005-02-22 13:04:05Z glebius $ 2713840Swosch */ 2813840Swosch 2913840Swosch#include <sys/types.h> 3013840Swosch#include <sys/ioctl.h> 3113840Swosch#include <sys/socket.h> 3213840Swosch 3313840Swosch#include <net/if.h> 3413840Swosch#include <netinet/in.h> 3513840Swosch#include <net/pfvar.h> 3613840Swosch#include <net/if_pfsync.h> 3713840Swosch#include <net/route.h> 3813840Swosch 3913840Swosch#include <err.h> 4013840Swosch#include <stdio.h> 4113840Swosch#include <stdlib.h> 4213840Swosch#include <string.h> 4313840Swosch#include <unistd.h> 4413840Swosch 4513840Swosch#include "ifconfig.h" 4613840Swosch 4713840Swoschvoid setpfsync_syncif(const char *, int, int, const struct afswtch *rafp); 4813840Swoschvoid unsetpfsync_syncif(const char *, int, int, const struct afswtch *rafp); 4913840Swoschvoid setpfsync_maxupd(const char *, int, int, const struct afswtch *rafp); 5013840Swoschvoid pfsync_status(int, const struct rt_addrinfo *); 5113840Swosch 5213840Swoschvoid 5313840Swoschsetpfsync_syncif(const char *val, int d, int s, const struct afswtch *rafp) 5413840Swosch{ 5513840Swosch struct pfsyncreq preq; 5613840Swosch 5713840Swosch bzero((char *)&preq, sizeof(struct pfsyncreq)); 5813840Swosch ifr.ifr_data = (caddr_t)&preq; 5913840Swosch 6013840Swosch if (ioctl(s, SIOCGETPFSYNC, (caddr_t)&ifr) == -1) 6113840Swosch err(1, "SIOCGETPFSYNC"); 6213840Swosch 6313840Swosch strlcpy(preq.pfsyncr_syncif, val, sizeof(preq.pfsyncr_syncif)); 6413840Swosch 6513840Swosch if (ioctl(s, SIOCSETPFSYNC, (caddr_t)&ifr) == -1) 6613840Swosch err(1, "SIOCSETPFSYNC"); 6713840Swosch} 6813840Swosch 6913840Swoschvoid 7013840Swoschunsetpfsync_syncif(const char *val, int d, int s, const struct afswtch *rafp) 7113840Swosch{ 7213840Swosch struct pfsyncreq preq; 7313840Swosch 7413840Swosch bzero((char *)&preq, sizeof(struct pfsyncreq)); 7513840Swosch ifr.ifr_data = (caddr_t)&preq; 7613840Swosch 7713840Swosch if (ioctl(s, SIOCGETPFSYNC, (caddr_t)&ifr) == -1) 7813840Swosch err(1, "SIOCGETPFSYNC"); 7913840Swosch 8013840Swosch bzero((char *)&preq.pfsyncr_syncif, sizeof(preq.pfsyncr_syncif)); 8113840Swosch 8213840Swosch if (ioctl(s, SIOCSETPFSYNC, (caddr_t)&ifr) == -1) 8313840Swosch err(1, "SIOCSETPFSYNC"); 8413840Swosch} 8513840Swosch 8613840Swoschvoid 8713840Swoschsetpfsync_maxupd(const char *val, int d, int s, const struct afswtch *rafp) 8813840Swosch{ 8913840Swosch int maxupdates; 9013840Swosch struct pfsyncreq preq; 9113840Swosch 9213840Swosch maxupdates = atoi(val); 9313840Swosch 9413840Swosch memset((char *)&preq, 0, sizeof(struct pfsyncreq)); 9513840Swosch ifr.ifr_data = (caddr_t)&preq; 9613840Swosch 9713840Swosch if (ioctl(s, SIOCGETPFSYNC, (caddr_t)&ifr) == -1) 9813840Swosch err(1, "SIOCGETPFSYNC"); 9913840Swosch 10013840Swosch preq.pfsyncr_maxupdates = maxupdates; 10113840Swosch 10213840Swosch if (ioctl(s, SIOCSETPFSYNC, (caddr_t)&ifr) == -1) 10313840Swosch err(1, "SIOCSETPFSYNC"); 10413840Swosch} 10513840Swosch 10613840Swoschvoid 10713840Swoschpfsync_status(int s, const struct rt_addrinfo *info __unused) 10813840Swosch{ 10913840Swosch struct pfsyncreq preq; 11013840Swosch 11113840Swosch bzero((char *)&preq, sizeof(struct pfsyncreq)); 11213840Swosch ifr.ifr_data = (caddr_t)&preq; 11313840Swosch 11413840Swosch if (ioctl(s, SIOCGETPFSYNC, (caddr_t)&ifr) == -1) 11513840Swosch return; 11613840Swosch 11713840Swosch if (preq.pfsyncr_syncif[0] != '\0') { 11813840Swosch printf("\tpfsync: syncif: %s maxupd: %d\n", 11913840Swosch preq.pfsyncr_syncif, preq.pfsyncr_maxupdates); 12013840Swosch } 12113840Swosch} 12213840Swosch 12313840Swoschstatic struct cmd pfsync_cmds[] = { 12413840Swosch DEF_CMD_ARG("syncif", setpfsync_syncif), 12513840Swosch DEF_CMD_ARG("maxupd", setpfsync_maxupd), 12613840Swosch DEF_CMD("-syncif", 1, unsetpfsync_syncif), 12713840Swosch}; 12813840Swoschstatic struct afswtch af_pfsync = { 12913840Swosch .af_name = "af_pfsync", 13013840Swosch .af_af = AF_UNSPEC, 13113840Swosch .af_status = pfsync_status, 13213840Swosch}; 13313840Swosch 13413840Swoschstatic __constructor void 13513840Swoschpfsync_ctor(void) 13613840Swosch{ 13713840Swosch#define N(a) (sizeof(a) / sizeof(a[0])) 13813840Swosch int i; 13913840Swosch 14013840Swosch for (i = 0; i < N(pfsync_cmds); i++) 14113840Swosch cmd_register(&pfsync_cmds[i]); 14213840Swosch af_register(&af_pfsync); 14313840Swosch#undef N 14413840Swosch} 14513840Swosch