среда, 28 марта 2012 г.

Allied telesis AT-8000GS/48 работает как хаб

Итак, есть свежекупленные AT-8000GS/48 с прошивкой 2.0.0.22.

С ними приколы:
1. Не лёрнятся маки. Вернее, некоторые лёрнятся, но единицы из сотен. Установить чёткую зависимость не удалось.
2. Перестают подниматься порты. Т.е. физически линк есть, ethtool показывает, что всё ок. Сам свич видит, что физический линк есть, но по статусу порт в дауне и не апается.
3. Были приколы с тем, что не форвардились кадры в пределах отдельно взятого влана, пока тэг не сменили.

Прошили на 2.0.0.26, любезно предоставленную коллегами из Allied Telesis (свободную скачку зареганным юзерам запретили), и как минимум первая проблема исчезла. 2 и 3 пока не проявились.

В общем, надо прошиваться на 2.0.0.26, если свич не лёрнит, как надо )

суббота, 24 марта 2012 г.

Новая площадка

Осваиваем новый ЦОД:











понедельник, 19 марта 2012 г.

libpcap, продолжение

Дополнил хэлло экстракцией http пакета, теперь вывод выглядит так:
Packet captured
IP header lengh:  20
Packet size:  60
Source IP:        192.168.10.108
Destination IP:   178.21.10.7
Source port:      52987
Destination port: 80
Flags:            SYN


Packet captured
IP header lengh:  20
Packet size:  60
Source IP:        178.21.10.7
Destination IP:   192.168.10.108
Source port:      80
Destination port: 52987
Flags:            SYN ACK


Packet captured
IP header lengh:  20
Packet size:  52
Source IP:        192.168.10.108
Destination IP:   178.21.10.7
Source port:      52987
Destination port: 80
Flags:            ACK


Packet captured
IP header lengh:  20
Packet size:  372
Source IP:        192.168.10.108
Destination IP:   178.21.10.7
Source port:      52987
Destination port: 80
Flags:            ACK
GET / HTTP/1.1
Host: speedcorezombie.net
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.1) Gecko/20100101 Firefox/10.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive



Packet captured
IP header lengh:  20
Packet size:  52
Source IP:        178.21.10.7
Destination IP:   192.168.10.108
Source port:      80
Destination port: 52987
Flags:            ACK


Packet captured
IP header lengh:  20
Packet size:  323
Source IP:        178.21.10.7
Destination IP:   192.168.10.108
Source port:      80
Destination port: 52987
Flags:            ACK
HTTP/1.1 200 OK
Date: Mon, 19 Mar 2012 19:26:14 GMT
Server: Apache/2.2.15 (CentOS)
Last-Modified: Sun, 18 Mar 2012 20:52:54 GMT
ETag: "6e653-6-4bb8aa02c9580"
Accept-Ranges: bytes
Content-Length: 6
Connection: close
Content-Type: text/html; charset=UTF-8

hello


Packet captured
IP header lengh:  20
Packet size:  52
Source IP:        192.168.10.108
Destination IP:   178.21.10.7
Source port:      52987
Destination port: 80
Flags:            ACK


Packet captured
IP header lengh:  20
Packet size:  52
Source IP:        192.168.10.108
Destination IP:   178.21.10.7
Source port:      52987
Destination port: 80
Flags:            ACK FYN


Packet captured
IP header lengh:  20
Packet size:  52
Source IP:        178.21.10.7
Destination IP:   192.168.10.108
Source port:      80
Destination port: 52987
Flags:            ACK FYN


Packet captured
IP header lengh:  20
Packet size:  52
Source IP:        192.168.10.108
Destination IP:   178.21.10.7
Source port:      52987
Destination port: 80
Flags:            ACK


Packet captured
IP header lengh:  20
Packet size:  52
Source IP:        178.21.10.7
Destination IP:   192.168.10.108
Source port:      80
Destination port: 52987
Flags:            ACK
Теперь осталось решить, какие поля http заголовка заграббить в базу )

libpcap hello

Надо граббить ip,tcp и http хэдеры для последующего анализа. Пока вот для теста наваял этакий хелловорлд:

#include <pcap/pcap.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <netinet/in.h>

int main() {

        char* device;                    // Sniffing device
        char errbuf[PCAP_ERRBUF_SIZE];   // Error message buffer
        pcap_t* handle;                  // Session handle
        struct bpf_program fp;           // The compiled filter expression
        char filter_exp[] = "port 80";   // The filter expression
        bpf_u_int32 mask;                // The netmask of our sniffing device
        bpf_u_int32 net;                 // The IP of our sniffing device
        struct pcap_pkthdr header;       // The header that pcap gives us
        const u_char* packet;            // The actual packet
        struct iphdr* ipheader = NULL;   // Pointer to the IP header
        struct tcphdr* tcpheader = NULL; // Pointer to the TCP header
        device = NULL;
        memset(errbuf, 0, PCAP_ERRBUF_SIZE);
        int count;

        device = pcap_lookupdev(errbuf);
        printf("Device: %s\n", device);
        printf("filter: %s\n", filter_exp);
        if (pcap_lookupnet(device, &net, &mask, errbuf) == -1) {
                fprintf(stderr, "Can't get netmask for device %s\n", device);
                net = 0;
                mask = 0;
        }

        handle = pcap_open_live(device, 2048, 0, 512, errbuf);

        if (pcap_compile(handle, &fp, filter_exp, 0, net) == -1) {
                fprintf(stderr, "Couldn't parse filter %s: %s\n", filter_exp, pcap_geterr(handle));
                exit(1);
        }

        if (pcap_setfilter(handle, &fp) == -1) {
                fprintf(stderr, "Couldn't install filter %s: %s\n", filter_exp, pcap_geterr(handle));
                exit(1);
        }
        count = 100;
        while (count) {
                // Try to get packet. If capture fail - try next.
                if ( (packet = pcap_next(handle, &header)) == NULL) {
                        fprintf(stderr, "ERROR: Error getting the packet\n", errbuf);
                        continue;
                } else
                        fprintf(stderr, "Packet captured\n");

                // Extract IP header
                ipheader = (struct iphdr *)(packet + 14);
                printf("IP header lengh:  %d\n", ipheader->ihl);
                printf("Source IP:        %s\n", inet_ntoa( *(struct in_addr *) &ipheader->saddr));
                printf("Destination IP:   %s\n", inet_ntoa( *(struct in_addr *) &ipheader->daddr));
                // Extract TCP header
                tcpheader = (struct tcphdr *)(packet + 14 + ipheader->ihl * 4);
                printf("Source port:      %d\n", ntohs(tcpheader->source));
                printf("Destination port: %d\n", ntohs(tcpheader->dest));
                printf("Flags:            ");
                if (tcpheader->syn)
                        printf("SYN ");
                if (tcpheader->ack)
                        printf("ACK ");
                if (tcpheader->fin)
                        printf("FYN ");
                printf("\n");
                printf("\n");

        }
        pcap_close(handle);
        return 0;
}

Вывод такой (запрос простой html странички):
# ./pcap
Device: wlan0
filter: port 80
ERROR: Error getting the packet
ERROR: Error getting the packet
ERROR: Error getting the packet
ERROR: Error getting the packet
ERROR: Error getting the packet
Packet captured
IP header lengh:  5
Source IP:        192.168.10.108
Destination IP:   178.21.10.7
Source port:      53375
Destination port: 80
Flags:            SYN

Packet captured
IP header lengh:  5
Source IP:        178.21.10.7
Destination IP:   192.168.10.108
Source port:      80
Destination port: 53375
Flags:            SYN ACK

Packet captured
IP header lengh:  5
Source IP:        192.168.10.108
Destination IP:   178.21.10.7
Source port:      53375
Destination port: 80
Flags:            ACK

Packet captured
IP header lengh:  5
Source IP:        192.168.10.108
Destination IP:   178.21.10.7
Source port:      53375
Destination port: 80
Flags:            ACK

Packet captured
IP header lengh:  5
Source IP:        178.21.10.7
Destination IP:   192.168.10.108
Source port:      80
Destination port: 53375
Flags:            ACK

Packet captured
IP header lengh:  5
Source IP:        178.21.10.7
Destination IP:   192.168.10.108
Source port:      80
Destination port: 53375
Flags:            ACK

Packet captured
IP header lengh:  5
Source IP:        192.168.10.108
Destination IP:   178.21.10.7
Source port:      53375
Destination port: 80
Flags:            ACK

Packet captured
IP header lengh:  5
Source IP:        178.21.10.7
Destination IP:   192.168.10.108
Source port:      80
Destination port: 53375
Flags:            ACK FYN

Packet captured
IP header lengh:  5
Source IP:        192.168.10.108
Destination IP:   178.21.10.7
Source port:      53375
Destination port: 80
Flags:            ACK FYN

Packet captured
IP header lengh:  5
Source IP:        178.21.10.7
Destination IP:   192.168.10.108
Source port:      80
Destination port: 53375
Flags:            ACK

ERROR: Error getting the packet

понедельник, 12 марта 2012 г.

Госы сданы

Пришли в инст, у нас отобрали зачётки и отвели куда-то на нижние этажи, где усадили за работу. Через 2 часа стали сдавать. В итоге почти всем дали по пять, но зачётки не отдали )

суббота, 10 марта 2012 г.

Как заставить работать 6pm.com

1. Купить за 4.5$ в месяц впс в BurstNET. Я там на какую-то срочную акцию попал, поэтому мну скинули доллар. Взял в Лос Анжелесе.
2. Вкатить openvpn. Не забыть врубить tun. Настроить можно, например, как тут:
http://wolandblog.com/1103-ustanovka-i-nastrojka-openvpn-na-centos-5-3

Мой хистори:
   17  wget http://mirror.optus.net/epel/5Server/x86_64/epel-release-5-4.noarch.rpm
   18  yum localinstall epel-release-5-4.noarch.rpm --nogpgcheck
   19  yum install openvpn
   20  touch /etc/openvpn/openvpn.conf
   21  mkdir /etc/openvpn/ccd
   22  mkdir /etc/openvpn/keys
   26  mkdir /etc/openvpn/easy-rsa
   36  cp -r /usr/share/openvpn/easy-rsa/2.0/* /etc/openvpn/easy-rsa/
   38  cd /etc/openvpn/easy-rsa/
   39  chmod +x clean-all
   40  chmod +x build*
   41  vi /etc/openvpn/easy-rsa/vars
   42  cd /etc/openvpn/easy-rsa
   48  source ./vars
   49  ./clean-all
   50  ./build-ca
   51  ./build-key-server vpnserver
   52  cp /etc/openvpn/easy-rsa/keys/ca.crt /etc/openvpn/keys/ca.crt
   53  cp /etc/openvpn/easy-rsa/keys/vpnserver.crt /etc/openvpn/keys/vpnserver.crt
   54  cp /etc/openvpn/easy-rsa/keys/vpnserver.key /etc/openvpn/keys/vpnserver.key
   56  ./build-dh
   57  cp /etc/openvpn/easy-rsa/keys/dh1024.pem /etc/openvpn/keys/dh1024.pem
   58  vi /etc/openvpn/openvpn.conf
   59  echo "ifconfig-push 172.16.0.101 172.16.0.102" > /etc/openvpn/ccd/accessd
   61  ./build-key accessd
   68  cd /etc/openvpn/easy-rsa/keys/
   69  tar czf accessd.tgz accessd.key accessd.crt ca.crt

3. Настроить NAT:
sysctl net.ipv4.ip_forward=1
/sbin/iptables -t nat -A POSTROUTING -o venet0 -j MASQUERADE
/sbin/iptables -A FORWARD -i venet0 -o tun0 -m state/sbin/iptables -A FORWARD -i venet0 -o tun0 -m state --state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A FORWARD -i tun0 -o venet0 -j ACCEPT
 4. Настроить клиента и можно пулять трафик в заппосовскую сеть через наш впс в ЛА.

Альтернатива - халявный инстанс в амазоне. Но на мои 2 акка халява не положена, а ещё один делать впадлу.