File: host.c

package info (click to toggle)
tcng 10b-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 3,644 kB
  • sloc: ansic: 19,040; pascal: 4,640; yacc: 2,619; sh: 1,914; perl: 1,546; lex: 772; makefile: 751
file content (62 lines) | stat: -rw-r--r-- 1,388 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * host.c - Host and route handling
 *
 * Written 2001,2002 by Werner Almesberger
 * Copyright 2001 EPFL-ICA
 * Copyright 2002 Werner Almesberger
 */


#include <stdlib.h>
#include <stdio.h>

#include <memutil.h>

#include "tcsim.h"
#include "tckernel.h"
#include "host.h"


static struct host *hosts = NULL;


struct host *create_host(void)
{
    struct host *host;

    host = alloc_t(struct host);
    host->routes = NULL;
    host->next = hosts;
    hosts = host;
    return host;
}


void add_route(struct host *host,uint32_t addr,uint32_t mask,
  struct net_device *dev)
{
    struct route **rt;

    if (dev->host != host)
	errorf("route to \"%s\" on different host",dev->name);
    addr &= mask; /* should this be an error ? */
    for (rt = &host->routes; *rt; rt = &(*rt)->next)
	if (!((*rt)->mask & ~mask) && !(((*rt)->addr^addr) & (*rt)->mask))
	    errorf("%u.%u.%u.%u netmask %u.%u.%u.%u clashes with %u.%u.%u.%u "
	      "netmask %u.%u.%u.%u",IPQ(addr),IPQ(mask),IPQ((*rt)->addr),
	      IPQ((*rt)->mask));
    *rt = alloc_t(struct route);
    (*rt)->addr = addr;
    (*rt)->mask = mask;
    (*rt)->dev = dev;
    (*rt)->next = NULL;
}


void connect_dev(struct net_device *a,struct net_device *b)
{
    if (a->peer) errorf("device %s is already connected",a->name);
    if (b->peer) errorf("device %s is already connected",b->name);
    a->peer = b;
    b->peer = a;
}