2015.10.05 Updated > Network Device Development - Part 1: Switch

  • View
    3.237

  • Download
    0

  • Category

    Software

Preview:

Citation preview

Network Device Development

PART 1 – Switch

SEAN

Sean

• Developer

• erinus.startup@gmail.com

• https://www.facebook.com/erinus

GitHub

https://github.com/erinus/NetworkDeviceDevelopment

Choose your Board

Simple, Support, Easy, …

X86 Board

X86 Board with 6 Ethernet

Specification

Specification

LAN-1037-6L

http://tw.taobao.com/item/42824613011.htm

Choose your Operating System

Simple, Clean, Easy, …

Debian

Debian 6.0.10

http://cdimage.debian.org/mirror/cdimage/archive/6.0.10/i386/iso-cd/debian-6.0.10-i386-

businesscard.iso

Debian 7.9.0

http://cdimage.debian.org/mirror/cdimage/archive/7.9.0/i386/iso-cd/debian-7.9.0-i386-netinst.iso

Choose your Virtual Machine

Simple, Stable, Fast, …

VMware Workstation

Setup your Board

X86 Board with 6 Ethernet

eth5 eth4 eth3 eth2 eth1 eth0

X86 Board with 6 Ethernet

Internet

mSATA mSATA

RAM

USBDVD-ROM

Setup your Virtual Machine

Simple, Stable, Fast, …

VMware Workstation

Virtual Network Editor

Add Network: VMnet2, VMnet3, …, VMnet8

Virtual Network Editor

Modify IP number (192.168.10X.0) to match VMnetX for debugging

Modify this

Virtual Network Editor

Uncheck "Connect a host virtual adapter to this network" to make isolated subnet

Uncheck this

New Virtual Machine

Install Operating System Later

Choose Guest Operating System

Linux + Debian 6

Linux + Debian 7

Name and Location

Disk Capacity

32+ GB

Customize Hardware Profile

Add 6 Virtual Network Adapter

Done

Install your Operating System

Splash Screen

Install

Uncheck them to keepsmallest installation

Setup your Operating System

Reboot

Login by root

Remove account

$ deluser --remove-home user

Update and Upgrade

$ apt-get update

$ apt-get –y upgrade

$ apt-get –y dist-upgrade

Install Packages

$ apt-get install –y vim gcc g++ ssh make cmakeopenssh-server openssh-client binutils build-

essential git python python-dev python-pip zip unzip bzip2 bridge-utils

Check Kernel Version

Search Kernel Development Packages

Debian 6.0.10

VMware use linux-headers-2.6.32-5-686

Debian 7.8.0

VMware use linux-headers-3.2.0-4-686-pae

Search Kernel Development Packages

Debian 6.0.10

VMware use linux-headers-2.6.32-5-686

Debian 7.9.0

VMware use linux-headers-3.2.0-4-686-pae

Install Kernel Development Packages

Debian 6.0.10

$ apt-get install –y linux-headers-2.6.32-5-commonlinux-headers-2.6.32-5-686

Debian 7.9.0

$ apt-get install –y linux-headers-3.2.0-4-commonlinux-headers-3.2.0-4-686-pae

Final

# release 100+ MB

$ apt-get autoremove

$ apt-get autoclean

$ rm /var/cache/apt/archives/*.deb

Before Development

Development More Easily

Use SSH Client, SFTP Client, and Smart Text Editor

Recommended

Xshell

Xftp

Sublime Text

First Kernel Module

Always

Hello World

Create Makefile

Return kernel version

Create main.c

Include Header File

Init$ insmod *.ko

Exit$ rmmod *.ko

Register Module

Clear Kernel Message Buffer

$ dmesg -c

Build

$ make

Install

$ make install

$ dmesg

Remove

$ make remove

$ dmesg

About Netfilter

PREROUTING POSTROUTING

IN

dest is localhost

?FORWARD

LOCALHOSTINPUT OUTPUT

OUT

About Network Topology

VMnet2

192.168.102.?

VMnet3

192.168.103.?

CLIENTUbuntu Desktop192.168.102.128

CLIENTUbuntu Desktop192.168.103.128

SWITCHDebian

VMnet1

NAT

eth1 eth2

eth0

About Bridge-Utils

Set Promisc Mode

$ ifconfig eth1 0.0.0.0 promisc up

$ ifconfig eth2 0.0.0.0 promisc up

Create Bridge

$ brctl addbr br0

$ brctl setfd br0 0

# Debian 6.0.10

$ brctl sethello br0 0

# Debian 7.9.0

$ brctl sethello br0 1

$ brctl addif br0 eth1

$ brctl addif br0 eth2

$ brctl stp br0 off

$ ifconfig br0 up

Avoid Unknown Problems

$ echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts

$ echo 0 > /proc/sys/net/ipv4/ip_forward

$ echo 0 > /proc/sys/net/ipv4/tcp_syncookies

First Netfilter Kernel Module

Modify main.c

Include Header Files

Forward Hook

Hook Declaration

Modify main.c

Include Header Files

Forward Hook

Hook Declaration

If one header miss,compilation still success.

But, operating systemwill crash when module inserting.

Modify main.c

Register Hook

Unregister Hook

Install

$ make

$ make install

$ dmesg

Test your Netfilter Kernel Module

CLIENT of VMnet2

$ sudo ip route add 192.168.103.0/24 via 192.168.102.128

CLIENT of VMnet3

$ sudo ip route add 192.168.102.0/24 via 192.168.103.128

Test on CLIENT of VMnet2

$ ping 192.168.103.128

For all packets, forwarding is accepted.

Modify main.c

Include Header Files

Forward Hook

Hook Declaration

Reinstall

$ make remove

$ make

$ make install

Test on CLIENT of VMnet2

$ ping 192.168.103.128

For all packets, forwarding is rejected.

Next Part

Firewall 101

Recommended