source: rtems-libbsd/freebsd-userspace/commands/sbin/ifconfig/ifgre.c @ ebbe3cc

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since ebbe3cc was ebbe3cc, checked in by Jennifer Averett <jennifer.averett@…>, on 09/07/12 at 18:16:22

Added the ifconfig command.

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*-
2 * Copyright (c) 2008 Andrew Thompson. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
17 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
22 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef lint
27static const char rcsid[] =
28  "$FreeBSD$";
29#endif
30
31#include <sys/param.h>
32#include <sys/ioctl.h>
33#include <sys/socket.h>
34#include <sys/sockio.h>
35
36#include <stdlib.h>
37#include <unistd.h>
38
39#include <net/ethernet.h>
40#include <net/if.h>
41#ifdef __rtems__
42#include <freebsd/net/if_gre.h>
43#else
44#include <net/if_gre.h>
45#endif
46#include <net/route.h>
47
48#include <ctype.h>
49#include <stdio.h>
50#include <string.h>
51#include <stdlib.h>
52#include <unistd.h>
53#include <err.h>
54#include <errno.h>
55
56#include "ifconfig.h"
57
58static  void gre_status(int s);
59
60static void
61gre_status(int s)
62{
63        int grekey = 0;
64
65        ifr.ifr_data = (caddr_t)&grekey;
66        if (ioctl(s, GREGKEY, &ifr) == 0)
67                if (grekey != 0)
68                        printf("\tgrekey: %d\n", grekey);
69}
70
71static void
72setifgrekey(const char *val, int dummy __unused, int s,
73    const struct afswtch *afp)
74{
75        uint32_t grekey = atol(val);
76
77        strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
78        ifr.ifr_data = (caddr_t)&grekey;
79        if (ioctl(s, GRESKEY, (caddr_t)&ifr) < 0)
80                warn("ioctl (set grekey)");
81}
82
83static struct cmd gre_cmds[] = {
84        DEF_CMD_ARG("grekey",                   setifgrekey),
85};
86static struct afswtch af_gre = {
87        .af_name        = "af_gre",
88        .af_af          = AF_UNSPEC,
89        .af_other_status = gre_status,
90};
91
92static __constructor void
93gre_ctor(void)
94{
95#define N(a)    (sizeof(a) / sizeof(a[0]))
96        size_t i;
97
98        for (i = 0; i < N(gre_cmds);  i++)
99                cmd_register(&gre_cmds[i]);
100        af_register(&af_gre);
101#undef N
102}
Note: See TracBrowser for help on using the repository browser.