亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? uip-fw.c

?? 最新版FreeRTOS, 包擴多種開發平臺的移植
?? C
字號:
/*
 * Copyright (c) 2004, Swedish Institute of Computer Science.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the Institute nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * This file is part of the uIP TCP/IP stack
 *
 * Author: Adam Dunkels <adam@sics.se>
 *
 * $Id: uip-fw.c,v 1.2 2006/06/12 08:00:30 adam Exp $
 */
/**
 * \addtogroup uip
 * @{
 */

/**
 * \defgroup uipfw uIP packet forwarding
 * @{
 *
 */

/**
 * \file
 * uIP packet forwarding.
 * \author Adam Dunkels <adam@sics.se>
 *
 * This file implements a number of simple functions which do packet
 * forwarding over multiple network interfaces with uIP.
 *
 */

#include "uip.h"
#include "uip_arch.h"
#include "uip-fw.h"

#include <string.h> /* for memcpy() */

/*
 * The list of registered network interfaces.
 */
static struct uip_fw_netif *netifs = NULL;

/*
 * A pointer to the default network interface.
 */
static struct uip_fw_netif *defaultnetif = NULL;

struct tcpip_hdr {
  /* IP header. */
  u8_t vhl,
    tos;
  u16_t len,
    ipid,
    ipoffset;
  u8_t ttl,
    proto;
  u16_t ipchksum;
  u16_t srcipaddr[2],
    destipaddr[2];
  
  /* TCP header. */
  u16_t srcport,
    destport;
  u8_t seqno[4],
    ackno[4],
    tcpoffset,
    flags,
    wnd[2];
  u16_t tcpchksum;
  u8_t urgp[2];
  u8_t optdata[4];
};

struct icmpip_hdr {
  /* IP header. */
  u8_t vhl,
    tos,
    len[2],
    ipid[2],
    ipoffset[2],
    ttl,
    proto;
  u16_t ipchksum;
  u16_t srcipaddr[2],
    destipaddr[2];
  /* ICMP (echo) header. */
  u8_t type, icode;
  u16_t icmpchksum;
  u16_t id, seqno;
  u8_t payload[1];
};

/* ICMP ECHO. */
#define ICMP_ECHO 8

/* ICMP TIME-EXCEEDED. */
#define ICMP_TE 11

/*
 * Pointer to the TCP/IP headers of the packet in the uip_buf buffer.
 */
#define BUF ((struct tcpip_hdr *)&uip_buf[UIP_LLH_LEN])

/*
 * Pointer to the ICMP/IP headers of the packet in the uip_buf buffer.
 */
#define ICMPBUF ((struct icmpip_hdr *)&uip_buf[UIP_LLH_LEN])

/*
 * Certain fields of an IP packet that are used for identifying
 * duplicate packets.
 */
struct fwcache_entry {
  u16_t timer;
  
  u16_t srcipaddr[2];
  u16_t destipaddr[2];
  u16_t ipid;
  u8_t proto;
  u8_t unused;

#if notdef
  u16_t payload[2];
#endif

#if UIP_REASSEMBLY > 0
  u16_t len, offset;
#endif
};

/*
 * The number of packets to remember when looking for duplicates.
 */
#ifdef UIP_CONF_FWCACHE_SIZE
#define FWCACHE_SIZE UIP_CONF_FWCACHE_SIZE
#else
#define FWCACHE_SIZE 2
#endif


/*
 * A cache of packet header fields which are used for
 * identifying duplicate packets.
 */
static struct fwcache_entry fwcache[FWCACHE_SIZE];

/**
 * \internal
 * The time that a packet cache is active.
 */
#define FW_TIME 20

/*------------------------------------------------------------------------------*/
/**
 * Initialize the uIP packet forwarding module.
 */
/*------------------------------------------------------------------------------*/
void
uip_fw_init(void)
{
  struct uip_fw_netif *t;
  defaultnetif = NULL;
  while(netifs != NULL) {
    t = netifs;
    netifs = netifs->next;
    t->next = NULL;
  }
}
/*------------------------------------------------------------------------------*/
/**
 * \internal
 * Check if an IP address is within the network defined by an IP
 * address and a netmask.
 *
 * \param ipaddr The IP address to be checked.
 * \param netipaddr The IP address of the network.
 * \param netmask The netmask of the network.
 *
 * \return Non-zero if IP address is in network, zero otherwise.
 */
/*------------------------------------------------------------------------------*/
static unsigned char
ipaddr_maskcmp(u16_t *ipaddr, u16_t *netipaddr, u16_t *netmask)
{
  return (ipaddr[0] & netmask [0]) == (netipaddr[0] & netmask[0]) &&
    (ipaddr[1] & netmask[1]) == (netipaddr[1] & netmask[1]);
}
/*------------------------------------------------------------------------------*/
/**
 * \internal
 * Send out an ICMP TIME-EXCEEDED message.
 *
 * This function replaces the packet in the uip_buf buffer with the
 * ICMP packet.
 */
/*------------------------------------------------------------------------------*/
static void
time_exceeded(void)
{
  u16_t tmp16;

  /* We don't send out ICMP errors for ICMP messages. */
  if(ICMPBUF->proto == UIP_PROTO_ICMP) {
    uip_len = 0;
    return;
  }
  /* Copy fields from packet header into payload of this ICMP packet. */
  memcpy(&(ICMPBUF->payload[0]), ICMPBUF, 28);

  /* Set the ICMP type and code. */
  ICMPBUF->type = ICMP_TE;
  ICMPBUF->icode = 0;

  /* Calculate the ICMP checksum. */
  ICMPBUF->icmpchksum = 0;
  ICMPBUF->icmpchksum = ~uip_chksum((u16_t *)&(ICMPBUF->type), 36);

  /* Set the IP destination address to be the source address of the
     original packet. */
  tmp16= BUF->destipaddr[0];
  BUF->destipaddr[0] = BUF->srcipaddr[0];
  BUF->srcipaddr[0] = tmp16;
  tmp16 = BUF->destipaddr[1];
  BUF->destipaddr[1] = BUF->srcipaddr[1];
  BUF->srcipaddr[1] = tmp16;

  /* Set our IP address as the source address. */
  BUF->srcipaddr[0] = uip_hostaddr[0];
  BUF->srcipaddr[1] = uip_hostaddr[1];

  /* The size of the ICMP time exceeded packet is 36 + the size of the
     IP header (20) = 56. */
  uip_len = 56;
  ICMPBUF->len[0] = 0;
  ICMPBUF->len[1] = uip_len;

  /* Fill in the other fields in the IP header. */
  ICMPBUF->vhl = 0x45;
  ICMPBUF->tos = 0;
  ICMPBUF->ipoffset[0] = ICMPBUF->ipoffset[1] = 0;
  ICMPBUF->ttl  = UIP_TTL;
  ICMPBUF->proto = UIP_PROTO_ICMP;
  
  /* Calculate IP checksum. */
  ICMPBUF->ipchksum = 0;
  ICMPBUF->ipchksum = ~(uip_ipchksum());


}
/*------------------------------------------------------------------------------*/
/**
 * \internal
 * Register a packet in the forwarding cache so that it won't be
 * forwarded again.
 */
/*------------------------------------------------------------------------------*/
static void
fwcache_register(void)
{
  struct fwcache_entry *fw;
  int i, oldest;

  oldest = FW_TIME;
  fw = NULL;
  
  /* Find the oldest entry in the cache. */
  for(i = 0; i < FWCACHE_SIZE; ++i) {
    if(fwcache[i].timer == 0) {
      fw = &fwcache[i];
      break;
    } else if(fwcache[i].timer <= oldest) {
      fw = &fwcache[i];
      oldest = fwcache[i].timer;
    }
  }

  fw->timer = FW_TIME;
  fw->ipid = BUF->ipid;
  fw->srcipaddr[0] = BUF->srcipaddr[0];
  fw->srcipaddr[1] = BUF->srcipaddr[1];
  fw->destipaddr[0] = BUF->destipaddr[0];
  fw->destipaddr[1] = BUF->destipaddr[1];
  fw->proto = BUF->proto;
#if notdef
  fw->payload[0] = BUF->srcport;
  fw->payload[1] = BUF->destport;
#endif
#if UIP_REASSEMBLY > 0
  fw->len = BUF->len;
  fw->offset = BUF->ipoffset;
#endif
}
/*------------------------------------------------------------------------------*/
/**
 * \internal
 * Find a network interface for the IP packet in uip_buf.
 */
/*------------------------------------------------------------------------------*/
static struct uip_fw_netif *
find_netif(void)
{
  struct uip_fw_netif *netif;
  
  /* Walk through every network interface to check for a match. */
  for(netif = netifs; netif != NULL; netif = netif->next) {
    if(ipaddr_maskcmp(BUF->destipaddr, netif->ipaddr,
		      netif->netmask)) {
      /* If there was a match, we break the loop. */
      return netif;
    }
  }
  
  /* If no matching netif was found, we use default netif. */
  return defaultnetif;
}
/*------------------------------------------------------------------------------*/
/**
 * Output an IP packet on the correct network interface.
 *
 * The IP packet should be present in the uip_buf buffer and its
 * length in the global uip_len variable.
 *
 * \retval UIP_FW_ZEROLEN Indicates that a zero-length packet
 * transmission was attempted and that no packet was sent.
 *
 * \retval UIP_FW_NOROUTE No suitable network interface could be found
 * for the outbound packet, and the packet was not sent.
 *
 * \return The return value from the actual network interface output
 * function is passed unmodified as a return value.
 */
/*------------------------------------------------------------------------------*/
u8_t
uip_fw_output(void)
{
  struct uip_fw_netif *netif;

  if(uip_len == 0) {
    return UIP_FW_ZEROLEN;
  }

  fwcache_register();

#if UIP_BROADCAST
  /* Link local broadcasts go out on all interfaces. */
  if(/*BUF->proto == UIP_PROTO_UDP &&*/
     BUF->destipaddr[0] == 0xffff &&
     BUF->destipaddr[1] == 0xffff) {
    if(defaultnetif != NULL) {
      defaultnetif->output();
    }
    for(netif = netifs; netif != NULL; netif = netif->next) {
      netif->output();
    }
    return UIP_FW_OK;
  }
#endif /* UIP_BROADCAST */
  
  netif = find_netif();
  /*  printf("uip_fw_output: netif %p ->output %p len %d\n", netif,
	 netif->output,
	 uip_len);*/

  if(netif == NULL) {
    return UIP_FW_NOROUTE;
  }
  /* If we now have found a suitable network interface, we call its
     output function to send out the packet. */
  return netif->output();
}
/*------------------------------------------------------------------------------*/
/**
 * Forward an IP packet in the uip_buf buffer.
 *
 *
 *
 * \return UIP_FW_FORWARDED if the packet was forwarded, UIP_FW_LOCAL if
 * the packet should be processed locally.
 */
/*------------------------------------------------------------------------------*/
u8_t
uip_fw_forward(void)
{
  struct fwcache_entry *fw;

  /* First check if the packet is destined for ourselves and return 0
     to indicate that the packet should be processed locally. */
  if(BUF->destipaddr[0] == uip_hostaddr[0] &&
     BUF->destipaddr[1] == uip_hostaddr[1]) {
    return UIP_FW_LOCAL;
  }

  /* If we use ping IP address configuration, and our IP address is
     not yet configured, we should intercept all ICMP echo packets. */
#if UIP_PINGADDRCONF
  if((uip_hostaddr[0] | uip_hostaddr[1]) == 0 &&
     BUF->proto == UIP_PROTO_ICMP &&
     ICMPBUF->type == ICMP_ECHO) {
    return UIP_FW_LOCAL;
  }
#endif /* UIP_PINGADDRCONF */

  /* Check if the packet is in the forwarding cache already, and if so
     we drop it. */

  for(fw = fwcache; fw < &fwcache[FWCACHE_SIZE]; ++fw) {
    if(fw->timer != 0 &&
#if UIP_REASSEMBLY > 0
       fw->len == BUF->len &&
       fw->offset == BUF->ipoffset &&
#endif
       fw->ipid == BUF->ipid &&
       fw->srcipaddr[0] == BUF->srcipaddr[0] &&
       fw->srcipaddr[1] == BUF->srcipaddr[1] &&
       fw->destipaddr[0] == BUF->destipaddr[0] &&
       fw->destipaddr[1] == BUF->destipaddr[1] &&
#if notdef
       fw->payload[0] == BUF->srcport &&
       fw->payload[1] == BUF->destport &&
#endif
       fw->proto == BUF->proto) {
      /* Drop packet. */
      return UIP_FW_FORWARDED;
    }
  }

  /* If the TTL reaches zero we produce an ICMP time exceeded message
     in the uip_buf buffer and forward that packet back to the sender
     of the packet. */
  if(BUF->ttl <= 1) {
    /* No time exceeded for broadcasts and multicasts! */
    if(BUF->destipaddr[0] == 0xffff && BUF->destipaddr[1] == 0xffff) {
      return UIP_FW_LOCAL;
    }
    time_exceeded();
  }
  
  /* Decrement the TTL (time-to-live) value in the IP header */
  BUF->ttl = BUF->ttl - 1;
  
  /* Update the IP checksum. */
  if(BUF->ipchksum >= HTONS(0xffff - 0x0100)) {
    BUF->ipchksum = BUF->ipchksum + HTONS(0x0100) + 1;
  } else {
    BUF->ipchksum = BUF->ipchksum + HTONS(0x0100);
  }

  if(uip_len > 0) {
    uip_appdata = &uip_buf[UIP_LLH_LEN + UIP_TCPIP_HLEN];
    uip_fw_output();
  }

#if UIP_BROADCAST
  if(BUF->destipaddr[0] == 0xffff && BUF->destipaddr[1] == 0xffff) {
    return UIP_FW_LOCAL;
  }
#endif /* UIP_BROADCAST */

  /* Return non-zero to indicate that the packet was forwarded and that no
     other processing should be made. */
  return UIP_FW_FORWARDED;
}
/*------------------------------------------------------------------------------*/
/**
 * Register a network interface with the forwarding module.
 *
 * \param netif A pointer to the network interface that is to be
 * registered.
 */
/*------------------------------------------------------------------------------*/
void
uip_fw_register(struct uip_fw_netif *netif)
{
  netif->next = netifs;
  netifs = netif;
}
/*------------------------------------------------------------------------------*/
/**
 * Register a default network interface.
 *
 * All packets that don't go out on any of the other interfaces will
 * be routed to the default interface.
 *
 * \param netif A pointer to the network interface that is to be
 * registered.
 */
/*------------------------------------------------------------------------------*/
void
uip_fw_default(struct uip_fw_netif *netif)
{
  defaultnetif = netif;
}
/*------------------------------------------------------------------------------*/
/**
 * Perform periodic processing.
 */
/*------------------------------------------------------------------------------*/
void
uip_fw_periodic(void)
{
  struct fwcache_entry *fw;
  for(fw = fwcache; fw < &fwcache[FWCACHE_SIZE]; ++fw) {
    if(fw->timer > 0) {
      --fw->timer;
    }
  }
}
/*------------------------------------------------------------------------------*/

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
www.亚洲激情.com| 国产精品久久免费看| 亚洲va国产天堂va久久en| 91在线精品秘密一区二区| 亚洲日韩欧美一区二区在线| 成人丝袜高跟foot| 国产精品美女久久久久久| 丰满亚洲少妇av| 亚洲欧美另类图片小说| 日韩女优毛片在线| 欧美优质美女网站| 亚洲国产精品嫩草影院| 欧美日韩国产一级| 麻豆免费精品视频| 国产日韩欧美激情| jlzzjlzz欧美大全| 亚洲激情自拍视频| 91精品久久久久久蜜臀| 日韩—二三区免费观看av| 国产精品色一区二区三区| 色综合色狠狠天天综合色| 日韩1区2区日韩1区2区| 国产亚洲女人久久久久毛片| 北岛玲一区二区三区四区| 亚洲成人av资源| 久久久久国色av免费看影院| 色婷婷久久久久swag精品| 日本亚洲一区二区| 亚洲天堂av一区| 精品国产sm最大网站| 色呦呦网站一区| 中文一区在线播放| 亚洲女与黑人做爰| 精品毛片乱码1区2区3区| 99久久精品国产毛片| 天堂精品中文字幕在线| 国产精品卡一卡二| 欧美理论在线播放| 不卡一区二区三区四区| 麻豆成人91精品二区三区| 1000精品久久久久久久久| 日韩欧美成人午夜| 欧美亚洲自拍偷拍| 99久久er热在这里只有精品15 | 国产欧美日韩精品在线| 欧美在线播放高清精品| 床上的激情91.| 看电影不卡的网站| 亚洲成av人片一区二区| 国产精品久久三区| 国产香蕉久久精品综合网| 制服丝袜在线91| 色婷婷久久久综合中文字幕| 丁香天五香天堂综合| 91官网在线观看| 日本中文一区二区三区| 亚洲综合色丁香婷婷六月图片| 日本一区二区视频在线| 日韩亚洲国产中文字幕欧美| 欧美在线观看你懂的| jlzzjlzz国产精品久久| 处破女av一区二区| 国产一区二区三区免费| 久久se精品一区精品二区| 人人精品人人爱| 免费视频一区二区| 日韩av网站免费在线| 日韩av高清在线观看| 日韩激情在线观看| 日本不卡1234视频| 麻豆国产一区二区| 美国一区二区三区在线播放| 日韩二区三区在线观看| 五月天激情综合| 婷婷久久综合九色综合伊人色| 亚洲6080在线| 奇米色一区二区| 久久精品噜噜噜成人av农村| 国产午夜精品一区二区| 免费欧美在线视频| 日韩黄色小视频| 另类小说色综合网站| 男人的天堂久久精品| 另类人妖一区二区av| 精品亚洲国内自在自线福利| 久久99精品国产.久久久久久| 日韩电影在线一区| 国内久久婷婷综合| 岛国一区二区三区| 99久久久国产精品| 欧美日韩精品欧美日韩精品一| 欧美日本韩国一区二区三区视频| 欧美久久高跟鞋激| 精品国精品自拍自在线| 国产女主播一区| 亚洲一区在线观看网站| 欧美aaaaaa午夜精品| 国产激情精品久久久第一区二区| 不卡的电视剧免费网站有什么| 欧美在线三级电影| 欧美成人官网二区| 国产精品黄色在线观看| 亚洲图片欧美一区| 另类成人小视频在线| 国产乱码精品一区二区三区五月婷| 欧美日韩精品一区二区在线播放| 在线精品视频免费观看| 欧美一区二区三区在线| 久久免费国产精品 | 国产精品乱子久久久久| 亚洲综合视频在线| 免费看精品久久片| av电影天堂一区二区在线观看| 欧美无砖专区一中文字| 久久综合九色综合97_久久久| 亚洲啪啪综合av一区二区三区| 视频在线观看一区二区三区| 成人网页在线观看| 欧美精品少妇一区二区三区| 日本一区免费视频| 肉色丝袜一区二区| 91在线免费视频观看| 欧美成人a在线| 亚洲电影一区二区| 成人在线综合网| 日韩手机在线导航| 亚洲精品乱码久久久久久| 精品一二线国产| 欧美日韩国产综合一区二区三区 | 蜜桃91丨九色丨蝌蚪91桃色| 久久精品国产99久久6| 激情成人午夜视频| 欧洲一区二区三区免费视频| 欧美va亚洲va香蕉在线| 国产精品美女久久久久久| 亚洲国产成人高清精品| 亚洲久本草在线中文字幕| 国内精品伊人久久久久av影院| 色吧成人激情小说| 日韩毛片在线免费观看| 美女久久久精品| 3atv在线一区二区三区| 中文字幕在线免费不卡| 国产成a人亚洲精| 日韩欧美国产麻豆| 国产凹凸在线观看一区二区| 精品国产三级a在线观看| 99r国产精品| 秋霞电影网一区二区| 一区二区三区成人| 久久久精品中文字幕麻豆发布| 欧美精品成人一区二区三区四区| 欧美亚洲另类激情小说| 国产片一区二区| 韩国在线一区二区| 精品久久久久久无| 国产精品欧美极品| 国产精品夜夜爽| 国产精品国产三级国产三级人妇 | 国产91丝袜在线播放| 日韩一区二区在线看| 国产不卡视频在线播放| 最新中文字幕一区二区三区| 色婷婷精品久久二区二区蜜臂av | 不卡的av在线| 精品少妇一区二区三区免费观看 | 亚洲午夜久久久| 欧美亚洲动漫另类| 亚洲一区二区三区在线播放| 99精品久久只有精品| 成人免费在线视频| 91欧美激情一区二区三区成人| 国产精品日韩成人| 亚洲精品乱码久久久久久久久 | 粉嫩绯色av一区二区在线观看| 欧美一区二区美女| 日本不卡的三区四区五区| 91麻豆精品国产自产在线| 日本欧美韩国一区三区| 91精品国产免费| 麻豆精品一二三| 久久先锋影音av鲁色资源| 国产一区二区三区四区五区美女| 久久久国产精品午夜一区ai换脸| 国产风韵犹存在线视精品| 国产精品无人区| 欧美最新大片在线看| 日本三级亚洲精品| 欧美经典一区二区三区| 一本色道久久加勒比精品 | 在线观看三级视频欧美| 天天av天天翘天天综合网色鬼国产| 欧美乱妇15p| 美脚の诱脚舐め脚责91| 91小视频免费看| 亚洲裸体xxx| 欧美日韩在线播放三区四区| 午夜精品免费在线| 久久影音资源网| 欧美自拍丝袜亚洲|