Statistics
| Branch: | Revision:

iof-bird-daemon / sysdep / unix / krt-set.c @ 1567edea

History | View | Annotate | Download (2.21 KB)

1
/*
2
 *        BIRD -- Unix Routing Table Syncing
3
 *
4
 *        (c) 1998--2000 Martin Mares <mj@ucw.cz>
5
 *
6
 *        Can be freely distributed and used under the terms of the GNU GPL.
7
 */
8

    
9
#include <sys/types.h>
10
#include <sys/socket.h>
11
#include <netinet/in.h>
12
#include <sys/ioctl.h>
13
#include <net/route.h>
14

    
15
#undef LOCAL_DEBUG
16

    
17
#include "nest/bird.h"
18
#include "nest/iface.h"
19
#include "nest/route.h"
20
#include "nest/protocol.h"
21
#include "lib/unix.h"
22
#include "lib/krt.h"
23
#include "lib/string.h"
24

    
25
int
26
krt_capable(rte *e)
27
{
28
  rta *a = e->attrs;
29

    
30
#ifdef CONFIG_AUTO_ROUTES
31
  if (a->source == RTS_DEVICE)
32
    return 0;
33
#endif
34
  return
35
    a->cast == RTC_UNICAST &&
36
    (a->dest == RTD_ROUTER
37
     || a->dest == RTD_DEVICE
38
#ifdef RTF_REJECT
39
     || a->dest == RTD_UNREACHABLE
40
#endif
41
     );
42
}
43

    
44
static void
45
krt_ioctl(int ioc, rte *e, char *name)
46
{
47
  net *net = e->net;
48
  struct rtentry re;
49
  rta *a = e->attrs;
50

    
51
  bzero(&re, sizeof(re));
52
  fill_in_sockaddr((struct sockaddr_in *) &re.rt_dst, net->n.prefix, 0);
53
  fill_in_sockaddr((struct sockaddr_in *) &re.rt_genmask, ipa_mkmask(net->n.pxlen), 0);
54
  re.rt_flags = RTF_UP;
55
  if (net->n.pxlen == 32)
56
    re.rt_flags |= RTF_HOST;
57
  switch (a->dest)
58
    {
59
    case RTD_ROUTER:
60
      fill_in_sockaddr((struct sockaddr_in *) &re.rt_gateway, a->gw, 0);
61
      re.rt_flags |= RTF_GATEWAY;
62
      break;
63
    case RTD_DEVICE:
64
      if (!a->iface)
65
        return;
66
      re.rt_dev = a->iface->name;
67
      break;
68
#ifdef RTF_REJECT
69
    case RTD_UNREACHABLE:
70
      re.rt_flags |= RTF_REJECT;
71
      break;
72
#endif
73
    default:
74
      bug("krt set: unknown flags, but not filtered");
75
    }
76

    
77
  if (ioctl(if_scan_sock, ioc, &re) < 0)
78
    log(L_ERR "%s(%I/%d): %m", name, net->n.prefix, net->n.pxlen);
79
}
80

    
81
void
82
krt_set_notify(struct krt_proto *p, net *net, rte *new, rte *old)
83
{
84
  if (old)
85
    {
86
      DBG("krt_remove_route(%I/%d)\n", net->n.prefix, net->n.pxlen);
87
      krt_ioctl(SIOCDELRT, old, "SIOCDELRT");
88
    }
89
  if (new)
90
    {
91
      DBG("krt_add_route(%I/%d)\n", net->n.prefix, net->n.pxlen);
92
      krt_ioctl(SIOCADDRT, new, "SIOCADDRT");
93
    }
94
}
95

    
96
void
97
krt_set_start(struct krt_proto *x, int first)
98
{
99
  if (if_scan_sock < 0)
100
    bug("krt set: missing socket");
101
}
102

    
103
void
104
krt_set_construct(struct krt_config *c)
105
{
106
}
107

    
108
void
109
krt_set_shutdown(struct krt_proto *x, int last)
110
{
111
}