Linux Kernel Development: Network Drivers

Linux Networking Subsystem, 2004 for Linux Kernel 2.4.18
Linux Kernel Networking (Presentation), 2007 for Linux Kernel 2.6.23
A Map of the Networking Code in Linux Kernel 2.4.20, 2004

O’Reilly

Understanding the Linux Kernel, 3rd Edition, 2005
Understanding Linux Network Internals, 2005
Linux Device Drivers, 3rd Edition, 2005

Oracle Linux: 6.7 About Network Device Drivers
linux network drivers — net_device_ops
struct net_device and net_device_ops

Understanding TCP/IP Network Stack & Writing Network Apps
Networking in the Linux Kernel
Queueing in the Linux Network Stack
Scaling in the Linux Networking Stack (TXT)
Networking › kernel_flow
Single RX queue kernel bypass in Netmap for high packet rate networking

struct net_device, struct net

what is the difference between register_pernet_subsys and register_pernet_device?
Getting list of network devices inside the Linux kernel

#include <linux/netdevice.h>

struct net_device *dev;

dev = first_net_device(&init_net);
while (dev) {
    printk(KERN_INFO "found [%s]\n", dev->name);
    dev = next_net_device(dev);
}

Linux Kernel Development: Proc

Tutorials

Creating a read write proc entry in kernel versions above 3.10
proc_create() example for kernel module
Using structures to set the functions
Driver porting: The seq_file interface

Linux.com: Linux Training

The Kernel Newbie Corner: Kernel Debugging Using proc “Sequence” Files–Part 1

KernelNewbies

Documents/SeqFileHowTo

CrashCourse: An introduction to Linux kernel programming

Lesson 11: Adding “proc” files to your modules — Part 1

The Linux Kernel Module Programming Guide

2005-12-31 ver 2.6.3 for Linux Kernels 2.6.x (2.6.14)
5.3. Manage /proc file with standard filesystem

Common LISP

Unterlagen PSPP HS15

Converting number to base-2 (binary) string representation [duplicate]

(defun int-to-binary-string (i)
  "convert an integer into it's binary representation in string format"
  (let ((res ""))
    (while (not (= i 0))
      (setq res (concat (if (= 1 (logand i 1)) "1" "0") res))
      (setq i (lsh i -1)))
    (if (string= res "")
        (setq res "0"))
    res))

Documentation

Common Lisp Quick Reference
Practical Common Lisp
The Common Lisp Cookbook
COMMON LISP: A Gentle Introduction to Symbolic Computation (PDF)
Land of LISP, No Starch Press github Source Code
Learning Lisp for CMPT 310
Implementation Notes for GNU CLISP
CLiki Common Lisp wiki
Using and Installing CLISP

Editors

Eclipse Common Lisp
CLiki: Development – Editor/IDE support
CLiki: Dandelion
CLiki: Cusp Eclipse IDE plugin
CLiki: Steel Bank Common Lisp (SBCL)
Dandelion – Eclipse Lisp Plugin Eclipse Update
Develop Lisp applications using the Cusp Eclipse plug-in
Does anyone have a CUSP plugin for Eclipse (Common Lisp)
Getting Cusp running from source
What are the good “rich” IDEs for Lisp?
LispWorks Personal Edition (free)

Common LISP

CLISP
Clozure Common Lisp

5.3 The Data and Control Flow Dictionary
14.2 The Conses Dictionary

LIST (System Class)
VALUES (Accessor)
PROGN (Special Operator)
KEYWORDP (Function)
LET (Special Operator)
NULL (Function)
FLOOR, CEILING, TRUNCATE, ROUND (Function)
COND (Macro)
REDUCE (Function)
MAPCAR, MAPLIST (Function)

Debugger

Top Level Loop
lisp, how to eliminate restarts

The following restarts are available:
USE-VALUE      :R1      Input a value to be used instead.
ABORT          :R2      Abort debug loop
ABORT          :R3      Abort debug loop
ABORT          :R4      Abort debug loop
ABORT          :R5      Abort main loop
Break 4 [6]> :q
[1]> (bye)
[1]> (exit)
[1]> (quit)

value

    • a. one of possibly several objects that are the result of an evaluation.
    • b. (in a situation where exactly one value is expected from the evaluation of a form) the primary value returned by the form.
    • c. (of forms in an implicit progn) one of possibly several objects that result from the evaluation of the last form, or nil if there are no forms.
  1. an object associated with a name in a binding.
  2. (of a symbol) the value of the dynamic variable named by that symbol.
  3. an object associated with a key in an association list, a property list, or a hash table.

multiple values

  1. more than one value.
    • “The function truncate returns multiple values.”
  2. a variable number of values, possibly including zero or one.
    • “The function values returns multiple values.”
  3. a fixed number of values other than one.
    • “The macro multiple-value-bind is among the few operators in Common Lisp which can detect and manipulate multiple values.”

form/forms vs. datum

Forms and the Top-Level Loop
Definition of “lisp form”?

The things which you type to the LISP interpreter are called forms; the LISP interpreter repeatedly reads a form, evaluates it, and prints the result. This procedure is called the read-eval-print loop.

Some forms will cause errors. After an error, LISP will put you into the debugger so you can try to figure out what caused the error. LISP debuggers are all different; but most will respond to the command “help” or “:help” by giving some form of help.

In general, a form is either an atom (for example, a symbol, an integer, or a string) or a list. If the form is an atom, LISP evaluates it immediately. Symbols evaluate to their value; integers and strings evaluate to themselves. If the form is a list, LISP treats its first element as the name of a function; it evaluates the remaining elements recursively, and then calls the function with the values of the remaining elements as arguments.

For example, if LISP sees the form (+ 3 4), it treats + as the name of a function. It then evaluates 3 to get 3 and 4 to get 4; finally it calls + with 3 and 4 as the arguments. The + function returns 7, which LISP prints.

form = datum + program, that can be evaluated without an error.
This is a lisp datum, it’s a list of 3, 4 and 1. This is not a form however as trying to evaluate it does not result into another datum. But rather an error:

(3 4 1)

This is a datum, and a form, also called a ‘normal form’ or a ‘self-evaluating datum’, it evaluates to itself:

3

This is a compound form, evaluating it results into the normal form 8:

(+ 3 4 1)

Apart from normal forms and compound forms, compound forms can be subdivided into procedure calls and special forms (also called syntax) but more properly, the head of a special form is the syntax, as in:

(if (oddp 2) (print "me") (print "or me"))

This is a special form because it’s head is syntax, and not a procedure, the only difference between procedure calls and special forms is that procedure calls see all of the arguments of the form as forms in itself and try to evaluate it first and special forms not necessarily do that. As we understand, only the second and fourth member of this compound form get evaluated, the first member is syntax, and the third is discarded in this case.
As we know for instance this code. But it’s not a form in Common Lisp:

((a 1) (b 2))

So:

(let ((a 1) (b 2)) (+ a b))

Is a special form, it does not evaluate its second member, and evaluates its third member in a different fashion than what would be expected if it was not a special form. That is, a and b as subforms of its third form have a different binding. let in this case is a syntactic keyword that signals the special form.

arguments &optional, &rest and &key

&optional = optional argument(s)
            Optionale Parameter

&rest     = rest arguments(s)
            Restparameter
            Werden in eine eigene Liste zusammengefasst.
            &rest steht an letzter Stelle, nach notwendigen
            und optionalen Parametern

&key      = key arguments
            Statt Parameter-Reihenfolge über Key/Value
[code]
(defun foo (&key a b c) (list a b c))

(foo)                ==> (NIL NIL NIL)
(foo :a 1)           ==> (1 NIL NIL)
(foo :b 1)           ==> (NIL 1 NIL)
(foo :c 1)           ==> (NIL NIL 1)
(foo :a 1 :c 3)      ==> (1 NIL 3)
(foo :a 1 :b 2 :c 3) ==> (1 2 3)
(foo :a 1 :c 3 :b 2) ==> (1 2 3)

keyword or keys in arguments (colons 🙂

What is the colon (:) in Emacs lisp?
Why colons precede variables in Common Lisp

[1] :yellow
:YELLOW

(list) vs. (values)

Most forms create only one value
A form typically returns only one value. Lisp has only a small number of forms which create or receive multiple values.

Normally multiple values are not used. Special forms are required both to produce multiple values and to receive them. If the caller of a function does not request multiple values, but the called function produces multiple values, then the first value is given to the caller and all others are discarded; if the called function produces zero values, then the caller gets nil as a value.

Constructs for Handling Multiple Values
Essential Multiple Values
alues function in Common Lisp
`values` vs `list` for returning multiple values from Lisp form

(cons) vs. Consing

Why is consing in Lisp slow?

(progn)

Object-Oriented equivalent of LISP’s progn function?

(setq) vs. (setf)

Lisp style: setq vs. setf

(set symbol  foo)   = set symbol to foo (Deprecated!)
(setf place  form)  = set place to primary values of forms (Macro to setq)
(setq symbol form)  = set symbol to primary values of form

EMACS Lisp

Tips on Writing Comments

Wikibooks

Basic topics

Lists
Functions

Examples

[1]> (+ 2 3)
5

[2]> (print "hello world")
"hello world"
"hello world"
[3]> (defun hello-name (name) (format nil "Hello ~A" name))
HELLO-NAME

[4]> (hello-name 'matt)
"Hello MATT"
[5]> (load "power.lisp")
;; Loading file power.lisp
;; Loaded file power.lisp
T

[6]> (power 3 4)
81

FAQ

Question

Why ‘x’ doesn’t be recognized?

[13]> (defun beispiel (a b c) (list a b c))
BEISPIEL

[14]> (beispiel 1 2 3)
(1 2 3)

[15]> (beispiel x y z)

*** - SYSTEM::READ-EVAL-PRINT: variable X has no value

Question

How to return a value?

[1]> (defun test123 ()
(print "hallo")
(print "welt")
(print "!"))
TEST123

[2]> (test123)
"hallo" 
"welt" 
"!" 
"!"

Answer

[3]> (defun test123 ()
(print "hallo")
(print "welt")
(print "!")
NIL)
TEST123

[4]> (test123)
"hallo" 
"welt" 
"!" 
NIL

Modula-2 / Modula-3

General

Modula-2
Modula-3
GNU Modula-2 (gm2)
Critical Mass Modula-3 (CM3)

Tutorials

Libraries

FAQ

Question

$ gm2 -g hello.mod
/usr/bin/ld: cannot find -lpth
collect2: error: ld returned 1 exit status

Answer

[Gm2] Re: still won’t compile and link

$ sudo apt-get install libpth-dev
[...]
The following NEW packages will be installed:
  libpth-dev libpth20
[...]

$ gm2 -g hello.mod
<no output>

Question

$ gm2 -o hello -g hello.mod
failed to find definition module InOut.def

Answer

Every compiler has other libraries with exactly the same functions/procedures:

  • InOut (ulm)
  • Terminal2
  • StrIO
$ ls -la /opt/gm2/lib/gcc/x86_64-linux-gnu/4.7.4/m2/
total 48
drwxr-xr-x 8 root root  4096 Jan  7 13:43 .
drwxr-xr-x 8 root root  4096 Jan  7 13:43 ..
drwxr-xr-x 2 root root  4096 Jan  7 13:43 cor
drwxr-xr-x 2 root root 12288 Jan  7 13:43 iso
drwxr-xr-x 2 root root  4096 Jan  7 13:43 log
drwxr-xr-x 2 root root  4096 Jan  7 13:43 min
drwxr-xr-x 2 root root  4096 Jan  7 13:43 pim
drwxr-xr-x 2 root root 12288 Jan  7 13:43 ulm
$ sed -i -e 's/InOut/StrIO/g' hello.mod
$ gm2 -o hello -g hello.mod
<no output>

or

$ gm2 -flibs=ulm,pim -o hello -g hello.mod

Question

There is no procedure “RealRandomNumbers”

Answer

Only in “Stony Brook Modula-2” or the successor “ADW Modula-2” there is a procedure “RealRandomNumbers”.
Stony Brook Modula-2 Development System
Stony Brook Software Home Page
modula2.org: Stony Brook Modula-2

There is a library to generate random numbers:
Ulm’s Modula-2 Library: RandomGenerator

$ grep -r Random /opt/gm2/lib/gcc/x86_64-linux-gnu/4.7.4/m2
/opt/gm2/lib/gcc/x86_64-linux-gnu/4.7.4/m2/iso/RandomNumber.def
/opt/gm2/lib/gcc/x86_64-linux-gnu/4.7.4/m2/log/Random.def
/opt/gm2/lib/gcc/x86_64-linux-gnu/4.7.4/m2/ulm/RandomGenerator.def

Question

There are no string procedures (like Length or IntToStr).

Answer

ISO Modula-2 Modules Reference

Input/Output

String Conversions

The string conversions library allows the conversion of the values of numeric data types to and from character string representations. The modules WholeStr, RealStr, and LongStr provide simple high-level facilities for converting to and from strings and whole number and real number data types. Low-level facilities are provided by the corresponding modules WholeConv, RealConv, and LongConv. Common data types and values that are used in the definition modules are defined by the module ConvTypes.

FROM WholeStr   IMPORT IntToStr, CardToStr;
FROM RealStr    IMPORT RealToStr;

FROM 

Use additional libraries (= modules)

$ grep -r "PROCEDURE Length" /opt/gm2/lib/gcc/x86_64-linux-gnu/4.7.4/m2
/opt/gm2/lib/gcc/x86_64-linux-gnu/4.7.4/m2/iso/M2RTS.def
/opt/gm2/lib/gcc/x86_64-linux-gnu/4.7.4/m2/iso/Strings.def
/opt/gm2/lib/gcc/x86_64-linux-gnu/4.7.4/m2/iso/RealConv.def
/opt/gm2/lib/gcc/x86_64-linux-gnu/4.7.4/m2/log/Strings.def
/opt/gm2/lib/gcc/x86_64-linux-gnu/4.7.4/m2/ulm/M2RTS.mod

$ gm2 -flibs=iso,pim -g -c MyLib.mod
$ grep -r "PROCEDURE StrToInt" /opt/gm2/lib/gcc/x86_64-linux-gnu/4.7.4/m2
iso/WholeStr.def:PROCEDURE StrToInt (str: ARRAY OF CHAR; VAR int: INTEGER;
iso/WholeStr.mod:PROCEDURE StrToInt (str: ARRAY OF CHAR; VAR int: INTEGER;
ulm/StrToNum.mod:   PROCEDURE StrToInt(str: ARRAY OF CHAR; VAR integ: INTEGER): BOOLEAN;
ulm/StrToNum.def:   PROCEDURE StrToInt(str: ARRAY OF CHAR; VAR integ: INTEGER): BOOLEAN;
pim/NumberIO.mod:PROCEDURE StrToInt (a: ARRAY OF CHAR ; VAR x: INTEGER) ; FORWARD ;
pim/NumberIO.mod:PROCEDURE StrToInt (a: ARRAY OF CHAR ; VAR x: INTEGER) ;
pim/NumberIO.def:PROCEDURE StrToInt (a: ARRAY OF CHAR ; VAR x: INTEGER) ;

$ vi Main.mod
[...]
FROM WholeStr   IMPORT IntToStr, CardToStr;
[...]

$ gm2 -flibs=iso,pim -g -c Main.mod

Question

How to use files

Answer

log/InOut.def
ulm/InOut.def
Files.def

Modula-2 “cat” in ISO-style

iso/StreamFile
iso/ChanConsts
iso/STextIO
iso/TextIO
iso/IOConsts
iso/IOChan

Dynamic Strings

pim/DynamicStrings.def

DEFINITION MODULE DynamicStrings ;

(* Description: provides a dynamic string type and common methods. *)

MySQL 5.6 on FreeBSD 10.2

mysql_enable="YES"
mysql_dbdir="/db/mysql"
# mysql_args="--skip-grant-tables \
--skip-networking" # for resetting the root password
$ ps aux
/usr/local/libexec/mysqld \
--defaults-extra-file=/db/mysql/my.cnf \
--basedir=/usr/local \
--datadir=/db/mysql
mysql> SHOW VARIABLES LIKE '%datadir%';
+---------------+------------+
| Variable_name | Value      |
+---------------+------------+
| datadir       | /db/mysql/ |
+---------------+------------+

How to initialize a new MySQL installation and create new database
Reset/recover MySQL root password in freebsd

sftp chroot on FreeBSD

Filesharing with chrooted SFTP
sftp/scp chroot solution?
How to Set Up an SFTP User on FreeBSD
SFTP chroot jail/access based on wildcard

[...]
Match User jon
        ChrootDirectory    /web/example.com/jon
        X11Forwarding      no
        AllowTcpForwarding no
        ForceCommand       internal-sftp
Dec 19 15:25:15 example.com sshd[78707]: Accepted keyboard-interactive/pam for jon from 10.0.0.5 port 62601 ssh2
Dec 19 15:25:15 example.com sshd[78710]: fatal: bad ownership or modes for chroot directory component "/web/"
$ pw user add jon
$ tail /var/log/auth.log
$ chown root /web
$ chown root /web/example.com
$ chown root /web/example.com/jon
$ ssh jon@example.com
Password for jon@example.com:
Could not chdir to home directory /web/example.com/jon: No such file or directory
This service allows sftp connections only.
Connection to example.com: closed.

Custom Kernel on Fedora 20

Fedora Wiki

Building a custom kernel
Building an upstream kernel
Kernel/DayToDay
Building Only Kernel Modules

Custom Kernel on Fedora

Custom Kernel for Fedora
‘make prep’ breaks on private branches
Custom Kernel on Fedora 20
Not able to build a fedora kernel

yum install kernel

yum installs kernel-devel different from my kernel version
fedora-20 – VirtualBox – Kernel Sources Missing
how to get kernel source code for — 3.8.6-203.fc18.x86_64

General

How to Compile Linux Kernel from Source to Build Custom Kernel
Guide to building the Linux kernel

fedpkg

fedpkg
Package maintenance guide

$ fedpkg clone -a kernel
$ cd kernel
$ fedpkg switch-branch f23
$ make depend
$ cd kernel-4.2.fc23/linux-4.2.7-300.fc23.x86_64