Last active
June 1, 2016 14:14
-
-
Save alejolp/c96089059af378bffd3c0363d8a29b03 to your computer and use it in GitHub Desktop.
TAP AX.25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ 2525.145364] IPv6: ADDRCONF(NETDEV_CHANGE): em1: link becomes ready | |
[ 2589.973799] skbuff: skb_under_panic: text:ffffffffa0a36810 len:20 put:15 head:ffff880223282a00 data:ffff8802232829fe tail:0x12 end:0xc0 dev:<NULL> | |
[ 2589.973854] ------------[ cut here ]------------ | |
[ 2589.976829] kernel BUG at /build/linux-RYwSFv/linux-3.16.7-ckt20/net/core/skbuff.c:100! | |
[ 2589.980700] invalid opcode: 0000 [#3] SMP | |
[ 2589.984244] Modules linked in: ax25 tun ctr ccm bnep rtsx_usb_ms memstick rtsx_usb_sdmmc rtsx_usb openafs(PO) nfsd auth_rpcgss oid_registry nfs_acl nfs lockd fscache sunrpc snd_hda_codec_hdmi snd_hda_codec_conexant snd_hda_codec_generic uvcvideo videobuf2_vmalloc videobuf2_memops videobuf2_core v4l2_common videodev media ecb arc4 brcmsmac cordic brcmutil btusb bluetooth b43 6lowpan_iphc mac80211 cfg80211 ssb x86_pkg_temp_thermal intel_powerclamp mmc_core rng_core intel_rapl pcmcia coretemp pcmcia_core iTCO_wdt iTCO_vendor_support kvm_intel kvm crc32_pclmul joydev cryptd psmouse evdev i2c_i801 serio_raw pcspkr snd_hda_intel i915 snd_hda_controller snd_hda_codec snd_hwdep bcma snd_pcm snd_timer snd soundcore lpc_ich mfd_core shpchp drm_kms_helper drm i2c_algo_bit ideapad_laptop sparse_keymap i2c_core | |
[ 2589.998557] rfkill battery ac mei_me video mei button processor fuse parport_pc ppdev lp parport autofs4 ext4 crc16 mbcache jbd2 hid_generic usbhid hid sg sd_mod crc_t10dif sr_mod cdrom crct10dif_generic ahci libahci crct10dif_pclmul crct10dif_common crc32c_intel libata scsi_mod thermal thermal_sys ehci_pci xhci_hcd ehci_hcd alx mdio usbcore usb_common | |
[ 2590.004952] CPU: 1 PID: 2811 Comm: beacon Tainted: P D O 3.16.0-4-amd64 #1 Debian 3.16.7-ckt20-1+deb8u3 | |
[ 2590.006998] Hardware name: LENOVO 20150/INVALID, BIOS 5ECN95WW(V9.00) 12/19/2012 | |
[ 2590.010248] task: ffff8801f6bd8250 ti: ffff8801d7c3c000 task.ti: ffff8801d7c3c000 | |
[ 2590.014238] RIP: 0010:[<ffffffff8150f184>] [<ffffffff8150f184>] skb_panic+0x5f/0x61 | |
[ 2590.016624] RSP: 0018:ffff8801d7c3fc98 EFLAGS: 00010282 | |
[ 2590.019352] RAX: 0000000000000086 RBX: ffff88022545e400 RCX: 0000000000000000 | |
[ 2590.021485] RDX: ffff88022f24eda0 RSI: ffff88022f24d478 RDI: 0000000000000246 | |
[ 2590.025157] RBP: 0000000000000000 R08: 000000000000000a R09: 0000000000000000 | |
[ 2590.028843] R10: 000000000000038c R11: ffff8801d7c3f9d6 R12: 0000000000000012 | |
[ 2590.032482] R13: 0000000000000004 R14: ffff8801d7d5dc00 R15: ffff8800b919f000 | |
[ 2590.034357] FS: 00007fd7360b4700(0000) GS:ffff88022f240000(0000) knlGS:0000000000000000 | |
[ 2590.037990] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 | |
[ 2590.041671] CR2: 00007fd735a73c60 CR3: 00000001cea42000 CR4: 00000000000407e0 | |
[ 2590.045382] Stack: | |
[ 2590.049070] ffff8802232829fe 0000000000000012 00000000000000c0 ffffffff8173760c | |
[ 2590.052813] ffffffff8140d946 ffffffffa0a36810 0000000000000000 88920003cb817400 | |
[ 2590.056578] 360de10040a89c8a ffff880100000000 ffffffff8113da58 ffff880225ea3220 | |
[ 2590.060288] Call Trace: | |
[ 2590.064071] [<ffffffff8140d946>] ? skb_push+0x36/0x40 | |
[ 2590.067791] [<ffffffffa0a36810>] ? ax25_sendmsg+0x310/0x3f0 [ax25] | |
[ 2590.071497] [<ffffffff8113da58>] ? filemap_map_pages+0x1d8/0x230 | |
[ 2590.075188] [<ffffffff814060fb>] ? sock_sendmsg+0x8b/0xc0 | |
[ 2590.078860] [<ffffffff8116987c>] ? handle_mm_fault+0x63c/0x11c0 | |
[ 2590.082470] [<ffffffff8116509c>] ? tlb_flush_mmu_free+0x2c/0x50 | |
[ 2590.086124] [<ffffffff81190144>] ? __kmalloc+0x4b4/0x4c0 | |
[ 2590.089726] [<ffffffff81406261>] ? SYSC_sendto+0xf1/0x180 | |
[ 2590.093250] [<ffffffff811c451a>] ? __fd_install+0x1a/0x50 | |
[ 2590.093275] [<ffffffff81513d0d>] ? system_call_fast_compare_end+0x10/0x15 | |
[ 2590.093334] Code: 00 00 48 89 44 24 10 8b 87 c8 00 00 00 48 89 44 24 08 48 8b 87 d8 00 00 00 48 c7 c7 38 6f 77 81 48 89 04 24 31 c0 e8 a4 be ff ff <0f> 0b 48 8b 47 30 48 8b 17 80 e6 80 48 0f 44 c7 c3 0f 0b 0f 0b | |
[ 2590.093340] RIP [<ffffffff8150f184>] skb_panic+0x5f/0x61 | |
[ 2590.093341] RSP <ffff8801d7c3fc98> | |
[ 2590.093391] ---[ end trace d031dce997a41d8a ]--- | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* GNU GPLv2+ | |
* | |
* Alejandro Santos 2015 | |
* @alejolp | |
* | |
* gcc -Wall -lax25 tapax25test.c | |
* | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <fcntl.h> | |
#include <unistd.h> | |
#include <sys/stat.h> | |
#include <sys/types.h> | |
#include <sys/socket.h> | |
#include <sys/ioctl.h> | |
#include <netax25/ax25.h> | |
#include <netax25/axlib.h> | |
#include <netax25/axconfig.h> | |
#include <netdb.h> | |
/* #include <net/if.h> */ | |
#include <net/if_arp.h> | |
#include <linux/if.h> | |
#include <linux/if_tun.h> | |
int tun_alloc(char *dev) | |
{ | |
struct ifreq ifr; | |
int fd, err; | |
if( (fd = open("/dev/net/tun", O_RDWR)) < 0 ) | |
return -1; | |
memset(&ifr, 0, sizeof(ifr)); | |
ifr.ifr_flags = IFF_TAP | IFF_NO_PI; | |
if( *dev ) | |
strncpy(ifr.ifr_name, dev, IFNAMSIZ); | |
if( (err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 ){ | |
close(fd); | |
return err; | |
} | |
strcpy(dev, ifr.ifr_name); | |
if (ioctl(fd, TUNSETLINK, ARPHRD_AX25) == -1) { | |
perror("ioctl"); | |
close(fd); | |
return -1; | |
} | |
if (ioctl(fd, TUNSETPERSIST, 0) == -1) { | |
perror("ioctl"); | |
close(fd); | |
return -1; | |
} | |
return fd; | |
} | |
int setifcall(int s, char *ifn, char *name) | |
{ | |
char call[7]; | |
struct ifreq ifr; | |
if (ax25_aton_entry(name, call) == -1) | |
return 1; | |
memset(&ifr, 0, sizeof(ifr)); | |
strcpy(ifr.ifr_name, ifn); | |
memcpy(ifr.ifr_hwaddr.sa_data, call, 7); | |
ifr.ifr_hwaddr.sa_family = AF_AX25; | |
if (ioctl(s, SIOCSIFHWADDR, &ifr) != 0) { | |
perror("ioctl: SIOCSIFHWADDR"); | |
return 1; | |
} | |
return 0; | |
} | |
int setifmtu(int s, char *ifn, int mtu) | |
{ | |
struct ifreq ifr; | |
memset(&ifr, 0, sizeof(ifr)); | |
strcpy(ifr.ifr_name, ifn); | |
ifr.ifr_mtu = mtu; | |
if (ioctl(s, SIOCSIFMTU, &ifr) != 0) { | |
perror("ioctl: SIOCSIFMTU"); | |
return 1; | |
} | |
return 0; | |
} | |
int startiface(int fd, const char* dev, int mtu, struct hostent * hp) | |
{ | |
struct ifreq ifr; | |
memset(&ifr, 0, sizeof(ifr)); | |
strcpy(ifr.ifr_name, dev); | |
if (hp != NULL) { | |
ifr.ifr_addr.sa_family = AF_INET; | |
ifr.ifr_addr.sa_data[0] = 0; | |
ifr.ifr_addr.sa_data[1] = 0; | |
ifr.ifr_addr.sa_data[2] = hp->h_addr_list[0][0]; | |
ifr.ifr_addr.sa_data[3] = hp->h_addr_list[0][1]; | |
ifr.ifr_addr.sa_data[4] = hp->h_addr_list[0][2]; | |
ifr.ifr_addr.sa_data[5] = hp->h_addr_list[0][3]; | |
ifr.ifr_addr.sa_data[6] = 0; | |
if (ioctl(fd, SIOCSIFADDR, &ifr) < 0) { | |
perror("SIOCSIFADDR"); | |
return FALSE; | |
} | |
} | |
ifr.ifr_mtu = mtu; | |
if (ioctl(fd, SIOCSIFMTU, &ifr) < 0) { | |
perror("SIOCSIFMTU"); | |
return FALSE; | |
} | |
if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) { | |
perror("SIOCGIFFLAGS"); | |
return FALSE; | |
} | |
ifr.ifr_flags &= IFF_NOARP; | |
ifr.ifr_flags |= IFF_UP; | |
ifr.ifr_flags |= IFF_RUNNING; | |
if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) { | |
perror("SIOCSIFFLAGS"); | |
return FALSE; | |
} | |
return TRUE; | |
} | |
int main(int argc, char** argv) { | |
char dev_name[1024] = "em0"; | |
char call_name[1024] = "LU4EXT-15"; | |
int tap_fd; | |
int i; | |
int s, n; | |
int mtu = 256; | |
if (argc > 1) strncpy(dev_name, argv[1], 1024); | |
if (argc > 2) strncpy(call_name, argv[2], 1024); | |
printf("Creating TAP AX25 device name %s, call name %s\n", dev_name, call_name); | |
tap_fd = tun_alloc(dev_name); | |
printf("dev %d name %s\n", tap_fd, dev_name); | |
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { | |
perror("axparms: socket"); | |
return 1; | |
} | |
n = setifcall(s, dev_name, call_name); | |
//n = n | setifmtu(s, dev_name, 256); | |
startiface(s, dev_name, mtu, 0); | |
close(s); | |
for (;;) { | |
int nread; | |
char buffer[2048]; | |
nread = read(tap_fd,buffer,sizeof(buffer)); | |
if(nread < 0) { | |
perror("Reading from interface"); | |
close(tap_fd); | |
exit(1); | |
} | |
printf("Read %d bytes from device %s\n", nread, dev_name); | |
for (i=0; i<nread; ++i) { | |
printf("%02x ", buffer[i]); | |
} | |
printf("\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment