Skip to content

Instantly share code, notes, and snippets.

@jovimon
Last active February 6, 2024 17:44
Show Gist options
  • Star 48 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save jovimon/524e116471f249626fd2ccd141f3fe05 to your computer and use it in GitHub Desktop.
Save jovimon/524e116471f249626fd2ccd141f3fe05 to your computer and use it in GitHub Desktop.
compile realtek network driver for pfsense 2.4.x

How to compile and install latest realtek network driver in pfSense 2.4.x (FreeBSD 11.1)

  1. Download FreeBSD 11.1 VMDK and create a VM with it as HDD.

  2. Get FreeBSD source tree for your exact FreeBSD version and uncompress it to /usr/src:

    fetch -o /tmp ftp://ftp.freebsd.org/pub/`uname -s`/releases/`uname -m`/`uname -r | cut -d'-' -f1,2`/src.txz
    tar -C / -xvf /tmp/src.txz
    
  3. Download latest Realtek network driver (you need to input an email address).

  4. Uncompress driver:

    tar xvzf 0007-rtl_bsd_drv_v194.01.tgz
    
  5. Make driver:

    cd rtl_bsd_drv_v194.01
    make
    
    1. If the last command fails, change the following line in file if_re.c

      From: #include <dev/re/if_rereg.h>

      To: #include "if_rereg.h"

  6. Copy the file if_re.ko to the /boot/kernel folder in pfSense device.

    scp if_re.ko root@<pfSense device IP>:/boot/kernel

  7. Change file permissions in if_re.ko file accessing through SSH to pfSense.

    chmod 555 /boot/kernel/if_re.ko

  8. Modify /boot/loader.conf.local file and add the following line at the end of the file: if_re_load="YES"

    • Through console: vi /boot/loader.conf.local
    • Through web: Diagnostics > Edit File and click Load. When finished editing click Save.
  9. Reboot pfSense.

  10. After restart, verify if module is installed through ssh with kldstat. Example execution:

    [2.4.2-RELEASE][root@pfSense.local]/root: kldstat
        Id Refs Address            Size     Name
         1    7 0xffffffff80200000 2c3ea98  kernel
         2    1 0xffffffff82e3f000 80900    if_re.ko
         3    1 0xffffffff83021000 46c6     cryptodev.ko
    

Based on:

@cooljimy84
Copy link

Thank you !

@ygaeon
Copy link

ygaeon commented Sep 29, 2020

About 1 month ago I ditched my XCP-ng installation of pfSense in favor of bare metal installation. Since then I've had weird disconnects (seemingly when I load the connection a bit ~>300Mbit/s) and Gateway alarms going of, causing the gateway to be brought DOWN and UP again. Also saw a lot of pfSense kernel: arpresolve: can't allocate llinfo for <IP> on <iface> messages.

I saw messages floating around about FreeBSD and Realtek, but I didn't have a solution to it, until this guide. Thanks!

I've made a few additions to the guide as I discovered some issues:

  • I downloaded the qcow2 version from here: https://download.freebsd.org/ftp/releases/VM-IMAGES/11.3-RELEASE/amd64/Latest/
  • Extracting the src.txz filled the volume and I couldn't continue and had to resize the volume first:
    • $ qemu-img resize FreeBSD-11.3-RELEASE-amd64.qcow2 +3G
    • Boot up the image. (eg. $ qemu-system-x86_64 -m 4096 -enable-kvm -drive file=FreeBSD-11.3-RELEASE-amd64.qcow2,format=qcow2 -cpu host -smp cores=4 -usb -device usb-tablet)
    • # gpart show ada0 will say that the volume is [CORRUPT] but a simple # gpart recover ada0 will solve that.
    • Check what partition "freebsd-ufs" is on and if you're lucky, it's the last partition and you won't have to remove swap first.
    • # gpart resize -i <partition id> -s 6G -a 4k ada0
    • # growfs /dev/ada0p<partition id> will probably fail on you "Operation not permitted" but I found that I could use # service growfs onestart successfully instead.

Hope this helps the next guy :-)

PS! I'm on ~30 minutes stable connection now, where it would die on me every 5 minutes before this. Fingers crossed!

@jddonovan
Copy link

This guide still works for pfsense 2.5.x. Note that I used Freebsd 12 to build the latest driver available from Realtek.

I didn't try dropping in the previous version built with Freebsd 11. No idea if that would work (when e.g. upgrading from pfsense 2.4.x to 2.5.x).

@riprip74
Copy link

Thanks for the guide.
I did it on pfsense 2.5.1-RELEASE (amd64)built on Mon Apr 12 07:50:14 EDT 2021FreeBSD 12.2-STABLE
Of course, I used a freebsd 12.2 VM and 12.2 source files.
I edited the /boot/loader.conf instead of /boot/loader.conf.local which doesn't exist.
Everything is up and running with the new driver!

@jddonovan
Copy link

Just as a FYI, the driver is available as a pfsense package. Look for realtek-re-kmod. Might be behind Realtek source or freebsd-freshports though. Current pfsense package version is realtek-re-kmod-v196.04_2, freshports version is _3.

@jovimon
Copy link
Author

jovimon commented Sep 6, 2021

Hello @jddonovan, thank you very much for your find!
I have not tested it, but for everyone else, you have to enter the shell (through SSH or Diagnostics > Command Prompt) and issue this command: pgk search realtek-re-kmod.
Then, issue this command pkg install realtek-re-kmod-<version> with the version number returned in the previous command.

@chris-topher
Copy link

getting a sysdir.mk error that I have no clue about

chris@freebsd:~/scrap/rtl_bsd_drv_v198.00 $ make
make: "/usr/share/mk/bsd.sysdir.mk" line 17: Unable to locate the kernel source tree. Set SYSDIR to override.

make: stopped in /home/chris/scrap/rtl_bsd_drv_v198.00

any thoughts?

@ygaeon
Copy link

ygaeon commented Jun 3, 2023

@chris-topher .. the /usr/src existed on my image so can't help you there.
Perhaps try a search? :-)

@Hoto-Cocoa
Copy link

For future users:
You can just search package using this command: pkg search realtek-re-kmod, and this output will like to this:

realtek-re-kmod-198.00_3       Kernel driver for Realtek PCIe Ethernet Controllers

Then you can install using following command: pkg install realtek-re-kmod-198.00_3

And follow package's message.

In my case, Realtek provided source is broken to build in FreeBSD 14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment