gerrit-log
Threads by month
- ----- 2026 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
January 2023
- 1 participants
- 2205 discussions
16 Jan '23
Attention is currently required from: laforge.
jolly has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmo-abis/+/30448 )
Change subject: Remove mISDN header from received channel data
......................................................................
Patch Set 2:
(1 comment)
File src/input/misdn.c:
https://gerrit.osmocom.org/c/libosmo-abis/+/30448/comment/dee3105e_3c722766
PS1, Line 376: ms
> you can do msg->l2h = msgb_pull(msg, MISDN_HEADER_LEN). […]
Ok, changed it.
--
To view, visit https://gerrit.osmocom.org/c/libosmo-abis/+/30448
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmo-abis
Gerrit-Branch: master
Gerrit-Change-Id: I37f12baa1013cd1cfc6f6531b132669071eec926
Gerrit-Change-Number: 30448
Gerrit-PatchSet: 2
Gerrit-Owner: jolly <andreas(a)eversberg.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: laforge <laforge(a)osmocom.org>
Gerrit-Comment-Date: Mon, 16 Jan 2023 17:39:25 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: laforge <laforge(a)osmocom.org>
Gerrit-MessageType: comment
1
0
Change in libosmo-abis[master]: Send raw data with mISDN as it arrives from application
by jolly 16 Jan '23
by jolly 16 Jan '23
16 Jan '23
Attention is currently required from: pespin.
jolly has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmo-abis/+/30450 )
Change subject: Send raw data with mISDN as it arrives from application
......................................................................
Patch Set 2:
(1 comment)
File src/input/misdn.c:
https://gerrit.osmocom.org/c/libosmo-abis/+/30450/comment/af62e88d_7571b7b5
PS2, Line 405: osmo_fd_write_disable(bfd);
> are you sure this is correct? Shouldn't you only disable it if there's nothing more to be sent?
Write must be disabled in all cases. After sending data to b-channel (PH_DATA_REQ), we need to wait until we receive the confirm (PH_DATA_CNF). A double buffer inside mISDN prevents underruns. The handling of the confirm will enable write again. This is how flow control is performed.
--
To view, visit https://gerrit.osmocom.org/c/libosmo-abis/+/30450
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmo-abis
Gerrit-Branch: master
Gerrit-Change-Id: Ib311331fbbeff3661f6745e3474918987a8aa460
Gerrit-Change-Number: 30450
Gerrit-PatchSet: 2
Gerrit-Owner: jolly <andreas(a)eversberg.eu>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-CC: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: pespin <pespin(a)sysmocom.de>
Gerrit-Comment-Date: Mon, 16 Jan 2023 17:38:15 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: comment
1
0
Attention is currently required from: pespin.
Hello Jenkins Builder,
I'd like you to reexamine a change. Please visit
https://gerrit.osmocom.org/c/osmocom-bb/+/30992
to look at the new patch set (#2).
Change subject: layer23: Introduce APN VTY node
......................................................................
layer23: Introduce APN VTY node
Change-Id: I7b4eaa0de428b418bb1d89bd544694e89beb3e6e
---
M doc/examples/modem/modem.cfg
M src/host/layer23/include/osmocom/bb/common/Makefile.am
A src/host/layer23/include/osmocom/bb/common/apn.h
M src/host/layer23/include/osmocom/bb/common/ms.h
M src/host/layer23/include/osmocom/bb/common/settings.h
M src/host/layer23/include/osmocom/bb/modem/vty.h
M src/host/layer23/src/common/Makefile.am
A src/host/layer23/src/common/apn.c
M src/host/layer23/src/common/ms.c
M src/host/layer23/src/common/settings.c
M src/host/layer23/src/modem/app_modem.c
M src/host/layer23/src/modem/vty.c
12 files changed, 369 insertions(+), 3 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/92/30992/2
--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/30992
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I7b4eaa0de428b418bb1d89bd544694e89beb3e6e
Gerrit-Change-Number: 30992
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Attention: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: newpatchset
1
0
Jenkins Builder has posted comments on this change. ( https://gerrit.osmocom.org/c/osmocom-bb/+/30994 )
Change subject: layer23: Introduce tun.{c,h}
......................................................................
Patch Set 1:
(20 comments)
File src/host/layer23/include/osmocom/bb/common/tun.h:
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2782):
https://gerrit.osmocom.org/c/osmocom-bb/+/30994/comment/df7f2628_72fedd2d
PS1, Line 39: int (*cb_ind) (struct tun_t * tun, void *pack, unsigned len);
"foo * bar" should be "foo *bar"
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2782):
https://gerrit.osmocom.org/c/osmocom-bb/+/30994/comment/785cac30_3c0c68bd
PS1, Line 39: int (*cb_ind) (struct tun_t * tun, void *pack, unsigned len);
Unnecessary space before function pointer arguments
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2782):
https://gerrit.osmocom.org/c/osmocom-bb/+/30994/comment/e88384d3_ed425ac6
PS1, Line 53: int (*cb_ind) (struct tun_t * tun, void *pack,
"foo * bar" should be "foo *bar"
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2782):
https://gerrit.osmocom.org/c/osmocom-bb/+/30994/comment/97edca4c_962617ec
PS1, Line 53: int (*cb_ind) (struct tun_t * tun, void *pack,
Unnecessary space before function pointer arguments
File src/host/layer23/src/common/apn.c:
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2782):
https://gerrit.osmocom.org/c/osmocom-bb/+/30994/comment/8904dcdd_fdf1486b
PS1, Line 78: memcpy(&dst.u.sin6.sin6_addr, ((uint8_t*)&ip6h->ip6_dst) + pref_offset, 8);
"(foo*)" should be "(foo *)"
File src/host/layer23/src/common/tun.c:
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2782):
https://gerrit.osmocom.org/c/osmocom-bb/+/30994/comment/586c4790_6ed926fd
PS1, Line 48: #elif defined (__FreeBSD__)
space prohibited between function name and open parenthesis '('
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2782):
https://gerrit.osmocom.org/c/osmocom-bb/+/30994/comment/5282dc84_700925e6
PS1, Line 53: #elif defined (__APPLE__)
space prohibited between function name and open parenthesis '('
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2782):
https://gerrit.osmocom.org/c/osmocom-bb/+/30994/comment/e06a1caa_75bf402c
PS1, Line 65: #define SYS_ERR(sub, pri, en, fmt, args...) \
Macros starting with if should be enclosed by a do - while loop to avoid possible if/else logic defects
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2782):
https://gerrit.osmocom.org/c/osmocom-bb/+/30994/comment/f8ba3d6e_ee429ece
PS1, Line 104: #if defined(__FreeBSD__) || defined (__APPLE__)
space prohibited between function name and open parenthesis '('
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2782):
https://gerrit.osmocom.org/c/osmocom-bb/+/30994/comment/4aabcc44_4b4bac76
PS1, Line 123: #if defined(__FreeBSD__) || defined (__APPLE__)
space prohibited between function name and open parenthesis '('
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2782):
https://gerrit.osmocom.org/c/osmocom-bb/+/30994/comment/641c21a4_8f01e683
PS1, Line 186: #elif defined(__FreeBSD__) || defined (__APPLE__)
space prohibited between function name and open parenthesis '('
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2782):
https://gerrit.osmocom.org/c/osmocom-bb/+/30994/comment/0684e177_bb611ef7
PS1, Line 214: strcpy(ifr.ifr_name, dev_name);
Instead of strncpy()/strcpy(), use osmo_strlcpy() or OSMO_STRLCPY_ARRAY()
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2782):
https://gerrit.osmocom.org/c/osmocom-bb/+/30994/comment/ab2711ef_2b0ff1e8
PS1, Line 221: strncpy((*tun)->devname, ifr.ifr_name, IFNAMSIZ);
Instead of strncpy()/strcpy(), use osmo_strlcpy() or OSMO_STRLCPY_ARRAY()
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2782):
https://gerrit.osmocom.org/c/osmocom-bb/+/30994/comment/c82b7323_e34d2405
PS1, Line 229: } else {
else is not generally useful after a break or return
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2782):
https://gerrit.osmocom.org/c/osmocom-bb/+/30994/comment/c36fc0dd_925a45f0
PS1, Line 230: strncpy((*tun)->devname, dev_name, IFNAMSIZ);
Instead of strncpy()/strcpy(), use osmo_strlcpy() or OSMO_STRLCPY_ARRAY()
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2782):
https://gerrit.osmocom.org/c/osmocom-bb/+/30994/comment/e63eda76_8f9eb3ab
PS1, Line 243: #elif defined(__FreeBSD__) || defined (__APPLE__)
space prohibited between function name and open parenthesis '('
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2782):
https://gerrit.osmocom.org/c/osmocom-bb/+/30994/comment/ccb4e83b_98d5c2bb
PS1, Line 273: strncpy(areq.ifra_name, (*tun)->devname, IFNAMSIZ);
Instead of strncpy()/strcpy(), use osmo_strlcpy() or OSMO_STRLCPY_ARRAY()
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2782):
https://gerrit.osmocom.org/c/osmocom-bb/+/30994/comment/659a20c5_f7175c47
PS1, Line 283: while (ioctl(fd, SIOCDIFADDR, (void *)&areq) != -1) ;
space prohibited before semicolon
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2782):
https://gerrit.osmocom.org/c/osmocom-bb/+/30994/comment/c1300157_65ea6381
PS1, Line 319: int (*cb_ind) (struct tun_t * tun, void *pack, unsigned len))
"foo * bar" should be "foo *bar"
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2782):
https://gerrit.osmocom.org/c/osmocom-bb/+/30994/comment/0bd41f66_115b7ac7
PS1, Line 319: int (*cb_ind) (struct tun_t * tun, void *pack, unsigned len))
Unnecessary space before function pointer arguments
--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/30994
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: Id8611b720ada17a3c602872fe095bb91eeb17bcd
Gerrit-Change-Number: 30994
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-CC: Jenkins Builder
Gerrit-Comment-Date: Mon, 16 Jan 2023 17:23:28 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
1
0
16 Jan '23
Jenkins Builder has posted comments on this change. ( https://gerrit.osmocom.org/c/osmocom-bb/+/30993 )
Change subject: layer23: Introduce netdev.{c,h}
......................................................................
Patch Set 1:
(42 comments)
File src/host/layer23/include/osmocom/bb/common/netdev.h:
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/974517a6_8300ba90
PS1, Line 33: {
please, no spaces at the start of a line
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/862ed064_5a7bb7ea
PS1, Line 33: {
open brace '{' following struct go on the same line
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/d3635462_e150e713
PS1, Line 35: unsigned int ihl:4;
please, no spaces at the start of a line
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/07123035_c6fc11e6
PS1, Line 36: unsigned int version:4;
please, no spaces at the start of a line
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/2ee76edd_7fe51d29
PS1, Line 38: unsigned int version:4;
please, no spaces at the start of a line
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/b4d5f3af_6d2987f1
PS1, Line 39: unsigned int ihl:4;
please, no spaces at the start of a line
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/8f3d598b_c49c063f
PS1, Line 43: u_int8_t tos;
please, no spaces at the start of a line
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/e0370cbf_e5be4b4e
PS1, Line 44: u_int16_t tot_len;
please, no spaces at the start of a line
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/2879cc1e_253b27c8
PS1, Line 45: u_int16_t id;
please, no spaces at the start of a line
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/8a33419a_7620d740
PS1, Line 46: u_int16_t frag_off;
please, no spaces at the start of a line
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/a261ee75_2d21f3fe
PS1, Line 47: u_int8_t ttl;
please, no spaces at the start of a line
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/fd3b6416_346f89b1
PS1, Line 48: u_int8_t protocol;
please, no spaces at the start of a line
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/5f20b8aa_31b03089
PS1, Line 49: u_int16_t check;
please, no spaces at the start of a line
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/eb7c7142_66d994fc
PS1, Line 50: u_int32_t saddr;
please, no spaces at the start of a line
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/213488b3_0c7ddef8
PS1, Line 51: u_int32_t daddr;
please, no spaces at the start of a line
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/27c8868e_cdb3b0c1
PS1, Line 53: };
please, no spaces at the start of a line
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/66b26939_30349ae5
PS1, Line 57: struct osmo_sockaddr addr;
please, no spaces at the start of a line
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/1ffb9b1c_59356dee
PS1, Line 58: uint8_t prefixlen;
please, no spaces at the start of a line
File src/host/layer23/src/common/netdev.c:
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/abe916c4_f240c420
PS1, Line 45: #elif defined (__FreeBSD__)
space prohibited between function name and open parenthesis '('
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/7ae62d29_d0fdc71f
PS1, Line 49: #elif defined (__APPLE__)
space prohibited between function name and open parenthesis '('
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/44c0019a_7ed66740
PS1, Line 61: #define SYS_ERR(sub, pri, en, fmt, args...) \
Macros starting with if should be enclosed by a do - while loop to avoid possible if/else logic defects
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/1d716176_39f66a52
PS1, Line 97: strncpy(ifr.ifr_name, devname, IFNAMSIZ);
Instead of strncpy()/strcpy(), use osmo_strlcpy() or OSMO_STRLCPY_ARRAY()
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/30644889_9a1ef400
PS1, Line 125: #elif defined(__FreeBSD__) || defined (__APPLE__)
space prohibited between function name and open parenthesis '('
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/2b1e0fd6_834f8a79
PS1, Line 132: strncpy(ifr.ifr_name, devname, IFNAMSIZ);
Instead of strncpy()/strcpy(), use osmo_strlcpy() or OSMO_STRLCPY_ARRAY()
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/438fd2fb_3e2839d8
PS1, Line 160: if (ioctl(fd, SIOCSIFDSTADDR, (caddr_t) & ifr) < 0) {
space prohibited after that '&' (ctx:WxW)
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/e1b8e3e6_8fabe5f8
PS1, Line 172: #elif defined(__FreeBSD__) || defined (__APPLE__)
space prohibited between function name and open parenthesis '('
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/b570f46b_8c9343cb
PS1, Line 191: #if defined(__FreeBSD__) || defined (__APPLE__)
space prohibited between function name and open parenthesis '('
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/9657513d_22154e20
PS1, Line 213: #elif defined(__FreeBSD__) || defined (__APPLE__)
space prohibited between function name and open parenthesis '('
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/c173a823_2060117d
PS1, Line 214: strncpy(ifr.ifr_name, devname, IFNAMSIZ);
Instead of strncpy()/strcpy(), use osmo_strlcpy() or OSMO_STRLCPY_ARRAY()
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/951070a9_6b401c54
PS1, Line 249: #elif defined(__FreeBSD__) || defined (__APPLE__)
space prohibited between function name and open parenthesis '('
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/e3387aca_bea5ef0d
PS1, Line 381: #elif defined (__FreeBSD__) || defined (__APPLE__)
space prohibited between function name and open parenthesis '('
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/213b2629_9f00a34e
PS1, Line 381: #elif defined (__FreeBSD__) || defined (__APPLE__)
space prohibited between function name and open parenthesis '('
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/42091dc8_550c1a45
PS1, Line 387: strncpy(areq.ifra_name, devname, IFNAMSIZ);
Instead of strncpy()/strcpy(), use osmo_strlcpy() or OSMO_STRLCPY_ARRAY()
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/fc48a53c_30fb4c69
PS1, Line 530: #elif defined (__FreeBSD__) || defined (__APPLE__)
space prohibited between function name and open parenthesis '('
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/8df8f585_5fdfd75d
PS1, Line 530: #elif defined (__FreeBSD__) || defined (__APPLE__)
space prohibited between function name and open parenthesis '('
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/7a518840_f9fea8ea
PS1, Line 536: strncpy(areq.ifra_name, devname, IFNAMSIZ);
Instead of strncpy()/strcpy(), use osmo_strlcpy() or OSMO_STRLCPY_ARRAY()
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/a5e480f8_6fcb843e
PS1, Line 608: #elif defined(__FreeBSD__) || defined (__APPLE__)
space prohibited between function name and open parenthesis '('
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/af6075a7_b44207bd
PS1, Line 677: strncpy(ifr.ifr_name, gw_iface, IFNAMSIZ);
Instead of strncpy()/strcpy(), use osmo_strlcpy() or OSMO_STRLCPY_ARRAY()
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/15cc4700_1eb2dc9b
PS1, Line 751: static const uint8_t ll_prefix[] = { 0xfe,0x80, 0,0, 0,0, 0,0 };
space required after that ',' (ctx:VxV)
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/5aba5335_ac30d4d3
PS1, Line 751: static const uint8_t ll_prefix[] = { 0xfe,0x80, 0,0, 0,0, 0,0 };
space required after that ',' (ctx:VxV)
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/3c3454b7_bf17c446
PS1, Line 751: static const uint8_t ll_prefix[] = { 0xfe,0x80, 0,0, 0,0, 0,0 };
space required after that ',' (ctx:VxV)
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2781):
https://gerrit.osmocom.org/c/osmocom-bb/+/30993/comment/be5ca955_03c9a664
PS1, Line 751: static const uint8_t ll_prefix[] = { 0xfe,0x80, 0,0, 0,0, 0,0 };
space required after that ',' (ctx:VxV)
--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/30993
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I6085dc6861687bd4e9c32e86221c0375ad95ba22
Gerrit-Change-Number: 30993
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-CC: Jenkins Builder
Gerrit-Comment-Date: Mon, 16 Jan 2023 17:23:24 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
1
0
16 Jan '23
Jenkins Builder has posted comments on this change. ( https://gerrit.osmocom.org/c/osmocom-bb/+/30992 )
Change subject: layer23: Introduce APN VTY node
......................................................................
Patch Set 1:
(5 comments)
File src/host/layer23/include/osmocom/bb/common/settings.h:
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2780):
https://gerrit.osmocom.org/c/osmocom-bb/+/30992/comment/6c661e1c_95808644
PS1, Line 190: struct osmobb_apn *ms_find_apn_by_name(struct osmocom_ms *ms, const char* apn_name);
"foo* bar" should be "foo *bar"
File src/host/layer23/src/common/apn.c:
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2780):
https://gerrit.osmocom.org/c/osmocom-bb/+/30992/comment/f8dad5bb_71d8e03e
PS1, Line 60: }
adding a line without newline at end of file
File src/host/layer23/src/common/settings.c:
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2780):
https://gerrit.osmocom.org/c/osmocom-bb/+/30992/comment/27b8d893_4fef4cd9
PS1, Line 236: while((apn = llist_first_entry_or_null(&set->apn_list, struct osmobb_apn, list))) {
space required before the open parenthesis '('
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2780):
https://gerrit.osmocom.org/c/osmocom-bb/+/30992/comment/16b281e8_3064b7fd
PS1, Line 243: struct osmobb_apn *ms_find_apn_by_name(struct osmocom_ms *ms, const char* apn_name)
"foo* bar" should be "foo *bar"
Robot Comment from checkpatch (run ID jenkins-gerrit-lint-2780):
https://gerrit.osmocom.org/c/osmocom-bb/+/30992/comment/cd242921_52306718
PS1, Line 253: }
adding a line without newline at end of file
--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/30992
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I7b4eaa0de428b418bb1d89bd544694e89beb3e6e
Gerrit-Change-Number: 30992
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-CC: Jenkins Builder
Gerrit-Comment-Date: Mon, 16 Jan 2023 17:23:20 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
1
0
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/30992 )
Change subject: layer23: Introduce APN VTY node
......................................................................
layer23: Introduce APN VTY node
Change-Id: I7b4eaa0de428b418bb1d89bd544694e89beb3e6e
---
M doc/examples/modem/modem.cfg
M src/host/layer23/include/osmocom/bb/common/Makefile.am
A src/host/layer23/include/osmocom/bb/common/apn.h
M src/host/layer23/include/osmocom/bb/common/ms.h
M src/host/layer23/include/osmocom/bb/common/settings.h
M src/host/layer23/include/osmocom/bb/modem/vty.h
M src/host/layer23/src/common/Makefile.am
A src/host/layer23/src/common/apn.c
M src/host/layer23/src/common/ms.c
M src/host/layer23/src/common/settings.c
M src/host/layer23/src/modem/app_modem.c
M src/host/layer23/src/modem/vty.c
12 files changed, 369 insertions(+), 3 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/92/30992/1
diff --git a/doc/examples/modem/modem.cfg b/doc/examples/modem/modem.cfg
index d2cb81f..fd56b06 100644
--- a/doc/examples/modem/modem.cfg
+++ b/doc/examples/modem/modem.cfg
@@ -6,4 +6,8 @@
no login
!
ms 1
+ apn internet
+ tun-device modem4
+ type-support v4
+ no shutdown
no shutdown
diff --git a/src/host/layer23/include/osmocom/bb/common/Makefile.am b/src/host/layer23/include/osmocom/bb/common/Makefile.am
index 270f079..28caf78 100644
--- a/src/host/layer23/include/osmocom/bb/common/Makefile.am
+++ b/src/host/layer23/include/osmocom/bb/common/Makefile.am
@@ -1,4 +1,5 @@
noinst_HEADERS = \
+ apn.h \
l1ctl.h \
l1l2_interface.h \
l23_app.h \
diff --git a/src/host/layer23/include/osmocom/bb/common/apn.h b/src/host/layer23/include/osmocom/bb/common/apn.h
new file mode 100644
index 0000000..18dc16f
--- /dev/null
+++ b/src/host/layer23/include/osmocom/bb/common/apn.h
@@ -0,0 +1,68 @@
+/* APN Context
+ * (C) 2023 by sysmocom - s.m.f.c. GmbH <info(a)sysmocom.de>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#pragma once
+
+#include <osmocom/core/linuxlist.h>
+#include <osmocom/core/select.h>
+
+struct osmocom_ms;
+
+#define APN_TYPE_IPv4 0x01 /* v4-only */
+#define APN_TYPE_IPv6 0x02 /* v6-only */
+#define APN_TYPE_IPv4v6 0x04 /* v4v6 dual-stack */
+
+struct apn_name {
+ struct llist_head list;
+ char *name;
+};
+
+struct osmobb_apn {
+ /* list of APNs inside MS */
+ struct llist_head list;
+ /* back-pointer to MS */
+ struct osmocom_ms *ms;
+
+ bool started;
+
+ struct {
+ /* Primary name */
+ char *name;
+ /* name of the network device */
+ char *dev_name;
+ /* types supported address types on this APN */
+ uint32_t apn_type_mask;
+ /* administratively shut-down (true) or not (false) */
+ bool shutdown;
+ /* transmit G-PDU sequeence numbers (true) or not (false) */
+ bool tx_gpdu_seq;
+ } cfg;
+
+ /* corresponding tun device */
+ struct {
+ //struct tun_t *tun;
+ struct osmo_fd fd;
+ } tun;
+
+ /* ipv6 link-local address */
+ //struct in6_addr v6_lladdr;
+};
+
+struct osmobb_apn *apn_alloc(struct osmocom_ms *ms, const char *name);
+void apn_free(struct osmobb_apn *apn);
+int apn_start(struct osmobb_apn *apn);
+int apn_stop(struct osmobb_apn *apn);
diff --git a/src/host/layer23/include/osmocom/bb/common/ms.h b/src/host/layer23/include/osmocom/bb/common/ms.h
index a706a4c..30bb514 100644
--- a/src/host/layer23/include/osmocom/bb/common/ms.h
+++ b/src/host/layer23/include/osmocom/bb/common/ms.h
@@ -90,6 +90,9 @@
struct osmomncc_entity mncc_entity;
struct llist_head trans_list;
+ /* GPRS */
+ struct gprs_settings gprs;
+
/* Audio I/O */
struct gapk_io_state *gapk_io;
diff --git a/src/host/layer23/include/osmocom/bb/common/settings.h b/src/host/layer23/include/osmocom/bb/common/settings.h
index 8ebf049..845292f 100644
--- a/src/host/layer23/include/osmocom/bb/common/settings.h
+++ b/src/host/layer23/include/osmocom/bb/common/settings.h
@@ -5,6 +5,7 @@
#include <osmocom/core/linuxlist.h>
struct osmocom_ms;
+struct osmobb_apn;
#define MOB_C7_DEFLT_ANY_TIMEOUT 30
@@ -180,6 +181,14 @@
char *gsm_check_imei(const char *imei, const char *sv);
int gsm_random_imei(struct gsm_settings *set);
+struct gprs_settings {
+ struct llist_head apn_list;
+};
+
+int gprs_settings_init(struct osmocom_ms *ms);
+int gprs_settings_fi(struct osmocom_ms *ms);
+struct osmobb_apn *ms_find_apn_by_name(struct osmocom_ms *ms, const char* apn_name);
+
extern char *layer2_socket_path;
#endif /* _settings_h */
diff --git a/src/host/layer23/include/osmocom/bb/modem/vty.h b/src/host/layer23/include/osmocom/bb/modem/vty.h
index 14ec624..5b69af6 100644
--- a/src/host/layer23/include/osmocom/bb/modem/vty.h
+++ b/src/host/layer23/include/osmocom/bb/modem/vty.h
@@ -1,3 +1,10 @@
#pragma once
+#include <osmocom/bb/common/vty.h>
+
+enum modem_vty_node {
+ APN_NODE = _LAST_L23VTY_NODE + 1,
+};
+
int modem_vty_init(void);
+int modem_vty_go_parent(struct vty *vty);
diff --git a/src/host/layer23/src/common/Makefile.am b/src/host/layer23/src/common/Makefile.am
index 9abc802..94eeec8 100644
--- a/src/host/layer23/src/common/Makefile.am
+++ b/src/host/layer23/src/common/Makefile.am
@@ -13,6 +13,7 @@
noinst_LIBRARIES = liblayer23.a
liblayer23_a_SOURCES = \
+ apn.c \
gps.c \
l1ctl.c \
l1l2_interface.c \
diff --git a/src/host/layer23/src/common/apn.c b/src/host/layer23/src/common/apn.c
new file mode 100644
index 0000000..bd0eb25
--- /dev/null
+++ b/src/host/layer23/src/common/apn.c
@@ -0,0 +1,60 @@
+/*
+ * (C) 2023 by sysmocom - s.m.f.c. GmbH <info(a)sysmocom.de>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <stdint.h>
+#include <errno.h>
+#include <string.h>
+#include <arpa/inet.h>
+
+#include <talloc.h>
+
+#include <osmocom/bb/common/logging.h>
+#include <osmocom/bb/common/apn.h>
+#include <osmocom/bb/common/ms.h>
+
+struct osmobb_apn *apn_alloc(struct osmocom_ms *ms, const char *name)
+{
+ struct osmobb_apn *apn;
+ apn = talloc_zero(ms, struct osmobb_apn);
+ if (!apn)
+ return NULL;
+
+ talloc_set_name(apn, "apn_%s", name);
+ apn->cfg.name = talloc_strdup(apn, name);
+ apn->cfg.shutdown = true;
+ apn->cfg.tx_gpdu_seq = true;
+
+ apn->ms = ms;
+ llist_add_tail(&apn->list, &ms->gprs.apn_list);
+ return apn;
+}
+
+void apn_free(struct osmobb_apn *apn)
+{
+ llist_del(&apn->list);
+ talloc_free(apn);
+}
+
+int apn_start(struct osmobb_apn *apn)
+{
+ return 0;
+}
+
+int apn_stop(struct osmobb_apn *apn)
+{
+ return 0;
+}
\ No newline at end of file
diff --git a/src/host/layer23/src/common/ms.c b/src/host/layer23/src/common/ms.c
index 558505a..ee27096 100644
--- a/src/host/layer23/src/common/ms.c
+++ b/src/host/layer23/src/common/ms.c
@@ -24,6 +24,12 @@
/* Default value be configured by cmdline arg: */
uint16_t cfg_test_arfcn = 871;
+static int osmocom_ms_talloc_destructor(struct osmocom_ms *ms)
+{
+ gprs_settings_fi(ms);
+ return 0;
+}
+
struct osmocom_ms *osmocom_ms_alloc(void *ctx, const char *name)
{
struct osmocom_ms *ms;
@@ -32,6 +38,7 @@
if (!ms)
return NULL;
talloc_set_name(ms, "ms_%s", name);
+ talloc_set_destructor(ms, osmocom_ms_talloc_destructor);
ms->name = talloc_strdup(ms, name);
ms->test_arfcn = cfg_test_arfcn;
@@ -50,6 +57,7 @@
gsm_support_init(ms);
gsm_settings_init(ms);
+ gprs_settings_init(ms);
return ms;
}
diff --git a/src/host/layer23/src/common/settings.c b/src/host/layer23/src/common/settings.c
index fd7177d..287dcda 100644
--- a/src/host/layer23/src/common/settings.c
+++ b/src/host/layer23/src/common/settings.c
@@ -20,13 +20,12 @@
#include <string.h>
#include <osmocom/core/talloc.h>
-#include <osmocom/bb/mobile/app_mobile.h>
#include <osmocom/bb/common/settings.h>
#include <osmocom/bb/common/utils.h>
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/common/osmocom_data.h>
+#include <osmocom/bb/common/apn.h>
#include <osmocom/bb/common/ms.h>
-#include <osmocom/bb/common/networks.h>
#include <osmocom/bb/common/l1l2_interface.h>
/* Used to set default path globally through cmdline */
@@ -220,3 +219,35 @@
{ AUDIO_IOF_TI, "ti" },
{ 0x00, NULL}
};
+
+
+int gprs_settings_init(struct osmocom_ms *ms)
+{
+ struct gprs_settings *set = &ms->gprs;
+ INIT_LLIST_HEAD(&set->apn_list);
+
+ return 0;
+}
+
+int gprs_settings_fi(struct osmocom_ms *ms)
+{
+ struct gprs_settings *set = &ms->gprs;
+ struct osmobb_apn *apn;
+ while((apn = llist_first_entry_or_null(&set->apn_list, struct osmobb_apn, list))) {
+ /* free calls llist_del(): */
+ apn_free(apn);
+ }
+ return 0;
+}
+
+struct osmobb_apn *ms_find_apn_by_name(struct osmocom_ms *ms, const char* apn_name)
+{
+ struct gprs_settings *set = &ms->gprs;
+ struct osmobb_apn *apn;
+
+ llist_for_each_entry(apn, &set->apn_list, list) {
+ if (strcmp(apn->cfg.name, apn_name) == 0)
+ return apn;
+ }
+ return NULL;
+}
\ No newline at end of file
diff --git a/src/host/layer23/src/modem/app_modem.c b/src/host/layer23/src/modem/app_modem.c
index 7dcda17..d7c9a29 100644
--- a/src/host/layer23/src/modem/app_modem.c
+++ b/src/host/layer23/src/modem/app_modem.c
@@ -509,6 +509,7 @@
static struct vty_app_info _modem_vty_info = {
.name = "modem",
.version = PACKAGE_VERSION,
+ .go_parent_cb = modem_vty_go_parent,
};
static struct l23_app_info info = {
diff --git a/src/host/layer23/src/modem/vty.c b/src/host/layer23/src/modem/vty.c
index 4304876..12107ec 100644
--- a/src/host/layer23/src/modem/vty.c
+++ b/src/host/layer23/src/modem/vty.c
@@ -25,14 +25,179 @@
#include <osmocom/vty/command.h>
#include <osmocom/bb/common/vty.h>
+#include <osmocom/bb/common/apn.h>
#include <osmocom/bb/common/ms.h>
+#include <osmocom/bb/modem/vty.h>
+static struct cmd_node apn_node = {
+ APN_NODE,
+ "%s(apn)# ",
+ 1
+};
+
+int modem_vty_go_parent(struct vty *vty)
+{
+ struct osmobb_apn *apn;
+
+ switch (vty->node) {
+ case APN_NODE:
+ apn = vty->index;
+ vty->index = apn->ms;
+ vty->node = MS_NODE;
+ break;
+ }
+ return vty->node;
+}
+
+/* per APN config */
+DEFUN(cfg_ms_apn, cfg_ms_apn_cmd, "apn APN_NAME",
+ "Configure an APN\n"
+ "Name of APN\n")
+{
+ struct osmocom_ms *ms = vty->index;
+ struct osmobb_apn *apn;
+
+ apn = ms_find_apn_by_name(ms, argv[0]);
+ if (!apn)
+ apn = apn_alloc(ms, argv[0]);
+ if (!apn) {
+ vty_out(vty, "Unable to create APN '%s'%s", argv[0], VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ vty->index = apn;
+ vty->node = APN_NODE;
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_ms_no_apn, cfg_ms_no_apn_cmd, "no apn APN_NAME",
+ NO_STR "Configure an APN\n"
+ "Name of APN\n")
+{
+ struct osmocom_ms *ms = vty->index;
+ struct osmobb_apn *apn;
+
+ apn = ms_find_apn_by_name(ms, argv[0]);
+ if (!apn) {
+ vty_out(vty, "Unable to find APN '%s'%s", argv[0], VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+
+ apn_free(apn);
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_apn_tun_dev_name, cfg_apn_tun_dev_name_cmd,
+ "tun-device NAME",
+ "Configure tun device name\n"
+ "TUN device name")
+{
+ struct osmobb_apn *apn = (struct osmobb_apn *) vty->index;
+ osmo_talloc_replace_string(apn, &apn->cfg.dev_name, argv[0]);
+ return CMD_SUCCESS;
+}
+
+static const struct value_string pdp_type_names[] = {
+ { APN_TYPE_IPv4, "v4" },
+ { APN_TYPE_IPv6, "v6" },
+ { APN_TYPE_IPv4v6, "v4v6" },
+ { 0, NULL }
+};
+
+#define V4V6V46_STRING "IPv4(-only) PDP Type\n" \
+ "IPv6(-only) PDP Type\n" \
+ "IPv4v6 (dual-stack) PDP Type\n"
+
+DEFUN(cfg_apn_type_support, cfg_apn_type_support_cmd,
+ "type-support (v4|v6|v4v6)",
+ "Enable support for PDP Type\n"
+ V4V6V46_STRING)
+{
+ struct osmobb_apn *apn = (struct osmobb_apn *) vty->index;
+ uint32_t type = get_string_value(pdp_type_names, argv[0]);
+
+ apn->cfg.apn_type_mask |= type;
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_apn_shutdown, cfg_apn_shutdown_cmd,
+ "shutdown",
+ "Put the APN in administrative shut-down\n")
+{
+ struct osmobb_apn *apn = (struct osmobb_apn *) vty->index;
+
+ if (!apn->cfg.shutdown) {
+ if (apn_stop(apn)) {
+ vty_out(vty, "%% Failed to Stop APN%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ apn->cfg.shutdown = true;
+ }
+
+ return CMD_SUCCESS;
+}
+
+DEFUN(cfg_apn_no_shutdown, cfg_apn_no_shutdown_cmd,
+ "no shutdown",
+ NO_STR "Remove the APN from administrative shut-down\n")
+{
+ struct osmobb_apn *apn = (struct osmobb_apn *) vty->index;
+
+ if (apn->cfg.shutdown) {
+ if (!apn->cfg.dev_name) {
+ vty_out(vty, "%% Failed to start APN, tun-device is not configured%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ if (apn_start(apn) < 0) {
+ vty_out(vty, "%% Failed to start APN, check log for details%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ apn->cfg.shutdown = false;
+ }
+
+ return CMD_SUCCESS;
+}
+
+static void config_write_apn(struct vty *vty, const struct osmobb_apn *apn)
+{
+ unsigned int i;
+
+ vty_out(vty, " apn %s%s", apn->cfg.name, VTY_NEWLINE);
+
+ if (apn->cfg.dev_name)
+ vty_out(vty, " tun-device %s%s", apn->cfg.dev_name, VTY_NEWLINE);
+
+ for (i = 0; i < 32; i++) {
+ if (!(apn->cfg.apn_type_mask & (UINT32_C(1) << i)))
+ continue;
+ vty_out(vty, " type-support %s%s", get_value_string(pdp_type_names, (UINT32_C(1) << i)),
+ VTY_NEWLINE);
+ }
+
+ /* must be last */
+ vty_out(vty, " %sshutdown%s", apn->cfg.shutdown ? "" : "no ", VTY_NEWLINE);
+}
+
+static void config_write_ms(struct vty *vty, const struct osmocom_ms *ms)
+{
+ struct osmobb_apn *apn;
+
+ vty_out(vty, "ms %s%s", ms->name, VTY_NEWLINE);
+
+ l23_vty_config_write_ms_node_contents(vty, ms, " ");
+
+ llist_for_each_entry(apn, &ms->gprs.apn_list, list)
+ config_write_apn(vty, apn);
+
+ l23_vty_config_write_ms_node_contents_final(vty, ms, " ");
+}
static int config_write(struct vty *vty)
{
struct osmocom_ms *ms;
llist_for_each_entry(ms, &ms_list, entity)
- l23_vty_config_write_ms_node(vty, ms, "");
+ config_write_ms(vty, ms);
return CMD_SUCCESS;
}
@@ -45,5 +210,13 @@
install_element_ve(&l23_show_ms_cmd);
install_element(CONFIG_NODE, &l23_cfg_ms_cmd);
+ install_element(MS_NODE, &cfg_ms_apn_cmd);
+ install_element(MS_NODE, &cfg_ms_no_apn_cmd);
+ install_node(&apn_node, NULL);
+ install_element(APN_NODE, &cfg_apn_tun_dev_name_cmd);
+ install_element(APN_NODE, &cfg_apn_type_support_cmd);
+ install_element(APN_NODE, &cfg_apn_shutdown_cmd);
+ install_element(APN_NODE, &cfg_apn_no_shutdown_cmd);
+
return 0;
}
--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/30992
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I7b4eaa0de428b418bb1d89bd544694e89beb3e6e
Gerrit-Change-Number: 30992
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: newchange
1
0
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/30994 )
Change subject: layer23: Introduce tun.{c,h}
......................................................................
layer23: Introduce tun.{c,h}
This module provides several operations on tun devices (interfaces).
These functionalitites will be used by the "modem" app to set up tunnels for each APN in a
follow-up patch.
The code is basically an import from osmo-ggsn.git
97f60e3dca581797007524e0006ca9fafad59713 src/lib/tun.{c,h}, with
small modifications to make use of osmo_sockaddr instead of
osmo-ggsn.git specific in46_addr.
Related: OS#5503
Change-Id: Id8611b720ada17a3c602872fe095bb91eeb17bcd
---
M src/host/layer23/include/osmocom/bb/common/Makefile.am
M src/host/layer23/include/osmocom/bb/common/apn.h
A src/host/layer23/include/osmocom/bb/common/tun.h
M src/host/layer23/src/common/Makefile.am
M src/host/layer23/src/common/apn.c
A src/host/layer23/src/common/tun.c
6 files changed, 555 insertions(+), 2 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/94/30994/1
diff --git a/src/host/layer23/include/osmocom/bb/common/Makefile.am b/src/host/layer23/include/osmocom/bb/common/Makefile.am
index 12be730..67dc21c 100644
--- a/src/host/layer23/include/osmocom/bb/common/Makefile.am
+++ b/src/host/layer23/include/osmocom/bb/common/Makefile.am
@@ -18,5 +18,6 @@
sim.h \
subscriber.h \
support.h \
+ tun.h \
vty.h \
$(NULL)
diff --git a/src/host/layer23/include/osmocom/bb/common/apn.h b/src/host/layer23/include/osmocom/bb/common/apn.h
index 18dc16f..7a6215b 100644
--- a/src/host/layer23/include/osmocom/bb/common/apn.h
+++ b/src/host/layer23/include/osmocom/bb/common/apn.h
@@ -21,6 +21,7 @@
#include <osmocom/core/select.h>
struct osmocom_ms;
+struct tun_t;
#define APN_TYPE_IPv4 0x01 /* v4-only */
#define APN_TYPE_IPv6 0x02 /* v6-only */
@@ -54,7 +55,7 @@
/* corresponding tun device */
struct {
- //struct tun_t *tun;
+ struct tun_t *tun;
struct osmo_fd fd;
} tun;
@@ -66,3 +67,6 @@
void apn_free(struct osmobb_apn *apn);
int apn_start(struct osmobb_apn *apn);
int apn_stop(struct osmobb_apn *apn);
+
+#define LOGPAPN(level, apn, fmt, args...) \
+ LOGP(DTUN, level, "APN(%s): " fmt, (apn)->cfg.name, ## args)
diff --git a/src/host/layer23/include/osmocom/bb/common/tun.h b/src/host/layer23/include/osmocom/bb/common/tun.h
new file mode 100644
index 0000000..703d1bd
--- /dev/null
+++ b/src/host/layer23/include/osmocom/bb/common/tun.h
@@ -0,0 +1,64 @@
+/*
+ * TUN interface functions.
+ * Copyright (C) 2002, 2003 Mondru AB.
+ * Copyright (C) 2017-2018 by Harald Welte <laforge(a)gnumonks.org>
+ * Copyright (C) 2023 by sysmocom - s.m.f.c. GmbH <info(a)sysmocom.de>
+ *
+ * The contents of this file may be used under the terms of the GNU
+ * General Public License Version 2, provided that the above copyright
+ * notice and this permission notice is included in all copies or
+ * substantial portions of the software.
+ *
+ */
+
+#ifndef _TUN_H
+#define _TUN_H
+
+#include <stdbool.h>
+#include <net/if.h>
+
+#include <osmocom/core/socket.h>
+#include <osmocom/bb/common/netdev.h>
+
+#define PACKET_MAX 8196 /* Maximum packet size we receive */
+#define TUN_SCRIPTSIZE 256
+#define TUN_ADDRSIZE 128
+
+/* ***********************************************************
+ * Information storage for each tun instance
+ *************************************************************/
+
+struct tun_t {
+ int fd; /* File descriptor to tun interface */
+ struct osmo_sockaddr addr;
+ struct osmo_sockaddr dstaddr;
+ struct in_addr netmask;
+ int addrs; /* Number of allocated IP addresses */
+ int routes; /* One if we allocated an automatic route */
+ char devname[IFNAMSIZ]; /* Name of the tun device */
+ int (*cb_ind) (struct tun_t * tun, void *pack, unsigned len);
+ /* to be used by callers/users (to attach their own private state) */
+ void *priv;
+};
+
+extern int tun_new(struct tun_t **tun, const char *dev_name, bool use_kernel, int fd0, int fd1u);
+extern int tun_free(struct tun_t *tun);
+extern int tun_decaps(struct tun_t *this);
+extern int tun_encaps(struct tun_t *tun, void *pack, unsigned len);
+
+extern int tun_addaddr(struct tun_t *this, struct osmo_sockaddr *addr,
+ struct osmo_sockaddr *dstaddr, size_t prefixlen);
+
+extern int tun_set_cb_ind(struct tun_t *this,
+ int (*cb_ind) (struct tun_t * tun, void *pack,
+ unsigned len));
+
+extern int tun_runscript(struct tun_t *tun, char *script);
+
+int tun_ip_local_get(const struct tun_t *tun, struct in46_prefix *prefix_list,
+ size_t prefix_size, int flags);
+
+#define LOGTUN(level, tun, fmt, args...) \
+ LOGP(DTUN, level, "TUN(%s): " fmt, (tun)->devname, ## args)
+
+#endif /* !_TUN_H */
diff --git a/src/host/layer23/src/common/Makefile.am b/src/host/layer23/src/common/Makefile.am
index 3a6ba37..cc6f3f5 100644
--- a/src/host/layer23/src/common/Makefile.am
+++ b/src/host/layer23/src/common/Makefile.am
@@ -30,6 +30,7 @@
subscriber.c \
support.c \
sysinfo.c \
+ tun.c \
utils.c \
vty.c \
$(NULL)
diff --git a/src/host/layer23/src/common/apn.c b/src/host/layer23/src/common/apn.c
index bd0eb25..f21892e 100644
--- a/src/host/layer23/src/common/apn.c
+++ b/src/host/layer23/src/common/apn.c
@@ -18,12 +18,14 @@
#include <stdint.h>
#include <errno.h>
#include <string.h>
-#include <arpa/inet.h>
+#include <netinet/ip.h>
+#include <netinet/ip6.h>
#include <talloc.h>
#include <osmocom/bb/common/logging.h>
#include <osmocom/bb/common/apn.h>
+#include <osmocom/bb/common/tun.h>
#include <osmocom/bb/common/ms.h>
struct osmobb_apn *apn_alloc(struct osmocom_ms *ms, const char *name)
@@ -49,12 +51,98 @@
talloc_free(apn);
}
+/* Local network-originated IP packet, needs to be sent via SNDCP/LLC (GPRS) towards GSM network */
+static int cb_tun_ind(struct tun_t *tun, void *pack, unsigned len)
+{
+ struct osmobb_apn *apn = tun->priv;
+ struct osmo_sockaddr dst;
+ struct iphdr *iph = (struct iphdr *)pack;
+ struct ip6_hdr *ip6h = (struct ip6_hdr *)pack;
+ uint8_t pref_offset;
+
+ switch (iph->version) {
+ case 4:
+ if (len < sizeof(*iph) || len < 4*iph->ihl)
+ return -1;
+ dst.u.sin.sin_family = AF_INET;
+ dst.u.sin.sin_addr.s_addr = iph->daddr;
+ break;
+ case 6:
+ /* Due to the fact that 3GPP requires an allocation of a
+ * /64 prefix to each MS, we must instruct
+ * ippool_getip() below to match only the leading /64
+ * prefix, i.e. the first 8 bytes of the address. If the ll addr
+ * is used, then the match should be done on the trailing 64
+ * bits. */
+ pref_offset = IN6_IS_ADDR_LINKLOCAL(&ip6h->ip6_dst) ? 8 : 0;
+ memcpy(&dst.u.sin6.sin6_addr, ((uint8_t*)&ip6h->ip6_dst) + pref_offset, 8);
+ break;
+ default:
+ LOGTUN(LOGL_NOTICE, tun, "non-IPv%u packet received\n", iph->version);
+ return -1;
+ }
+
+ LOGPAPN(LOGL_DEBUG, apn, "system wants to transmit IPv%u pkt to %s (%u bytes)\n",
+ iph->version == 4 ? '4' : '6', osmo_sockaddr_to_str(&dst), len);
+
+ /* TODO: prepare & transmit SNDCP UNITDATA.req */
+
+ return 0;
+}
+
+/* callback for tun device osmocom select loop integration */
+static int apn_tun_fd_cb(struct osmo_fd *fd, unsigned int what)
+{
+ struct osmobb_apn *apn = fd->data;
+
+ OSMO_ASSERT(what & OSMO_FD_READ);
+
+ return tun_decaps(apn->tun.tun);
+}
+
int apn_start(struct osmobb_apn *apn)
{
+ if (apn->started)
+ return 0;
+
+ LOGPAPN(LOGL_INFO, apn, "Opening TUN device %s\n", apn->cfg.dev_name);
+ if (tun_new(&apn->tun.tun, apn->cfg.dev_name, false, -1, -1)) {
+ LOGPAPN(LOGL_ERROR, apn, "Failed to configure tun device\n");
+ return -1;
+ }
+ LOGPAPN(LOGL_INFO, apn, "Opened TUN device %s\n", apn->tun.tun->devname);
+
+ /* Register with libosmcoore */
+ osmo_fd_setup(&apn->tun.fd, apn->tun.tun->fd, OSMO_FD_READ, apn_tun_fd_cb, apn, 0);
+ osmo_fd_register(&apn->tun.fd);
+
+ /* Set TUN library callback */
+ tun_set_cb_ind(apn->tun.tun, cb_tun_ind);
+
+ /* set back-pointer from TUN device to APN */
+ apn->tun.tun->priv = apn;
+
+ /* TODO: set IP addresses on the tun device once we receive them from GGSN. See
+ osmo-ggsn.git's apn_start() */
+
+ LOGPAPN(LOGL_NOTICE, apn, "Successfully started\n");
+ apn->started = true;
return 0;
}
int apn_stop(struct osmobb_apn *apn)
{
+ LOGPAPN(LOGL_NOTICE, apn, "Stopping\n");
+
+ /* shutdown whatever old state might be left */
+ if (apn->tun.tun) {
+ /* release tun device */
+ LOGPAPN(LOGL_INFO, apn, "Closing TUN device %s\n", apn->tun.tun->devname);
+ osmo_fd_unregister(&apn->tun.fd);
+ tun_free(apn->tun.tun);
+ apn->tun.tun = NULL;
+ }
+
+ apn->started = false;
return 0;
}
\ No newline at end of file
diff --git a/src/host/layer23/src/common/tun.c b/src/host/layer23/src/common/tun.c
new file mode 100644
index 0000000..98d1927
--- /dev/null
+++ b/src/host/layer23/src/common/tun.c
@@ -0,0 +1,395 @@
+/*
+ * TUN interface functions.
+ * Copyright (C) 2002, 2003, 2004 Mondru AB.
+ * Copyright (C) 2017-2018 by Harald Welte <laforge(a)gnumonks.org>
+ * Copyright (C) 2023 by sysmocom - s.m.f.c. GmbH <info(a)sysmocom.de>
+ *
+ * The contents of this file may be used under the terms of the GNU
+ * General Public License Version 2, provided that the above copyright
+ * notice and this permission notice is included in all copies or
+ * substantial portions of the software.
+ *
+ */
+
+/*
+ * tun.c: Contains all TUN functionality. Is able to handle multiple
+ * tunnels in the same program. Each tunnel is identified by the struct,
+ * which is passed to functions.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <errno.h>
+#include <net/route.h>
+#include <net/if.h>
+
+#if defined(__linux__)
+#include <linux/if_tun.h>
+
+#elif defined (__FreeBSD__)
+#include <net/if_tun.h>
+#include <net/if_var.h>
+#include <netinet/in_var.h>
+
+#elif defined (__APPLE__)
+#include <net/if.h>
+
+#else
+#error "Unknown platform!"
+#endif
+
+#include <osmocom/core/logging.h>
+#include <osmocom/core/socket.h>
+#include <osmocom/bb/common/logging.h>
+#include <osmocom/bb/common/tun.h>
+
+#define SYS_ERR(sub, pri, en, fmt, args...) \
+ if (en) { \
+ logp2(sub, pri, __FILE__, __LINE__, 0, \
+ "errno=%d/%s " fmt "\n", en, strerror(en), \
+ ##args); \
+ } else { \
+ logp2(sub, pri, __FILE__, __LINE__, 0, \
+ fmt "\n", ##args); \
+ }
+
+/* FIXME: import gtp-kernel.{c,h} from osmo-ggsn.git. */
+static int gtp_kernel_create(int dest_ns, const char *devname, int fd0, int fd1u)
+{
+ return -ENOTSUP;
+}
+static void gtp_kernel_stop(const char *devname)
+{
+ (void)devname;
+}
+
+static int tun_setaddr4(struct tun_t *this, struct in_addr *addr,
+ struct in_addr *dstaddr, struct in_addr *netmask)
+{
+ int rc;
+ rc = netdev_setaddr4(this->devname, addr, dstaddr, netmask);
+ if (rc < 0)
+ return rc;
+
+ if (addr) {
+ this->addr.u.sin.sin_family = AF_INET;
+ this->addr.u.sin.sin_addr.s_addr = addr->s_addr;
+ }
+ if (dstaddr) {
+ this->dstaddr.u.sin.sin_family = AF_INET;
+ this->dstaddr.u.sin.sin_addr.s_addr = dstaddr->s_addr;
+ }
+ if (netmask)
+ this->netmask.s_addr = netmask->s_addr;
+ this->addrs++;
+#if defined(__FreeBSD__) || defined (__APPLE__)
+ this->routes = 1;
+#endif
+
+ return rc;
+}
+
+static int tun_setaddr6(struct tun_t *this, struct in6_addr *addr, struct in6_addr *dstaddr,
+ size_t prefixlen)
+{
+ int rc;
+ rc = netdev_setaddr6(this->devname, addr, dstaddr, prefixlen);
+ if (rc < 0)
+ return rc;
+ if (dstaddr) {
+ this->dstaddr.u.sin6.sin6_family = AF_INET6;
+ memcpy(&this->dstaddr.u.sin6.sin6_addr, dstaddr, sizeof(*dstaddr));
+ }
+ this->addrs++;
+#if defined(__FreeBSD__) || defined (__APPLE__)
+ this->routes = 1;
+#endif
+
+ return rc;
+}
+
+static int tun_addaddr4(struct tun_t *this, struct in_addr *addr,
+ struct in_addr *dstaddr, struct in_addr *netmask)
+{
+ int rc;
+
+ /* TODO: Is this needed on FreeBSD? */
+ if (!this->addrs) /* Use ioctl for first addr to make ping work */
+ return tun_setaddr4(this, addr, dstaddr, netmask); /* TODO dstaddr */
+
+ rc = netdev_addaddr4(this->devname, addr, dstaddr, netmask);
+ if (rc < 0)
+ return rc;
+
+ this->addrs++;
+
+ return rc;
+}
+
+static int tun_addaddr6(struct tun_t *this,
+ struct in6_addr *addr,
+ struct in6_addr *dstaddr, int prefixlen)
+{
+ int rc;
+
+ if (!this->addrs) /* Use ioctl for first addr to make ping work */
+ return tun_setaddr6(this, addr, dstaddr, prefixlen);
+
+ rc = netdev_addaddr6(this->devname, addr, dstaddr, prefixlen);
+ if (rc < 0)
+ return rc;
+
+ this->addrs++;
+
+ return rc;
+}
+
+int tun_addaddr(struct tun_t *this, struct osmo_sockaddr *addr, struct osmo_sockaddr *dstaddr, size_t prefixlen)
+{
+ struct in_addr netmask;
+ switch (addr->u.sa.sa_family) {
+ case AF_INET:
+ netmask.s_addr = htonl(0xffffffff << (32 - prefixlen));
+ return tun_addaddr4(this, &addr->u.sin.sin_addr, dstaddr ? &dstaddr->u.sin.sin_addr : NULL, &netmask);
+ case AF_INET6:
+ return tun_addaddr6(this, &addr->u.sin6.sin6_addr, dstaddr ? &dstaddr->u.sin6.sin6_addr : NULL, prefixlen);
+ default:
+ return -1;
+ }
+}
+
+int tun_new(struct tun_t **tun, const char *dev_name, bool use_kernel, int fd0, int fd1u)
+{
+
+#if defined(__linux__)
+ struct ifreq ifr;
+
+#elif defined(__FreeBSD__) || defined (__APPLE__)
+ char devname[IFNAMSIZ + 5]; /* "/dev/" + ifname */
+ int devnum;
+ struct ifaliasreq areq;
+ int fd;
+#endif
+
+ if (!(*tun = calloc(1, sizeof(struct tun_t)))) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno, "calloc() failed");
+ return EOF;
+ }
+
+ (*tun)->cb_ind = NULL;
+ (*tun)->addrs = 0;
+ (*tun)->routes = 0;
+
+#if defined(__linux__)
+ if (!use_kernel) {
+ /* Open the actual tun device */
+ if (((*tun)->fd = open("/dev/net/tun", O_RDWR)) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno, "open() failed");
+ goto err_free;
+ }
+
+ /* Set device flags. For some weird reason this is also the method
+ used to obtain the network interface name */
+ memset(&ifr, 0, sizeof(ifr));
+ if (dev_name)
+ strcpy(ifr.ifr_name, dev_name);
+ ifr.ifr_flags = IFF_TUN | IFF_NO_PI; /* Tun device, no packet info */
+ if (ioctl((*tun)->fd, TUNSETIFF, (void *)&ifr) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno, "ioctl() failed");
+ goto err_close;
+ }
+
+ strncpy((*tun)->devname, ifr.ifr_name, IFNAMSIZ);
+ (*tun)->devname[IFNAMSIZ - 1] = 0;
+
+ /* Disable checksums */
+ if (ioctl((*tun)->fd, TUNSETNOCSUM, 1) < 0) {
+ SYS_ERR(DTUN, LOGL_NOTICE, errno, "could not disable checksum on %s", (*tun)->devname);
+ }
+ return 0;
+ } else {
+ strncpy((*tun)->devname, dev_name, IFNAMSIZ);
+ (*tun)->devname[IFNAMSIZ - 1] = 0;
+ (*tun)->fd = -1;
+
+ if (gtp_kernel_create(-1, dev_name, fd0, fd1u) < 0) {
+ LOGP(DTUN, LOGL_ERROR, "cannot create GTP tunnel device: %s\n",
+ strerror(errno));
+ return -1;
+ }
+ LOGP(DTUN, LOGL_NOTICE, "GTP kernel configured\n");
+ return 0;
+ }
+
+#elif defined(__FreeBSD__) || defined (__APPLE__)
+
+ if (use_kernel) {
+ LOGP(DTUN, LOGL_ERROR, "No kernel GTP-U support in FreeBSD!\n");
+ return -1;
+ }
+
+ /* Find suitable device */
+ for (devnum = 0; devnum < 255; devnum++) { /* TODO 255 */
+ snprintf(devname, sizeof(devname), "/dev/tun%d", devnum);
+ if (((*tun)->fd = open(devname, O_RDWR)) >= 0)
+ break;
+ if (errno != EBUSY)
+ break;
+ }
+ if ((*tun)->fd < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno,
+ "Can't find tunnel device");
+ goto err_free;
+ }
+
+ snprintf((*tun)->devname, sizeof((*tun)->devname), "tun%d", devnum);
+ (*tun)->devname[sizeof((*tun)->devname)-1] = 0;
+
+ /* The tun device we found might have "old" IP addresses allocated */
+ /* We need to delete those. This problem is not present on Linux */
+
+ memset(&areq, 0, sizeof(areq));
+
+ /* Set up interface name */
+ strncpy(areq.ifra_name, (*tun)->devname, IFNAMSIZ);
+ areq.ifra_name[IFNAMSIZ - 1] = 0; /* Make sure to terminate */
+
+ /* Create a channel to the NET kernel. */
+ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno, "socket() failed");
+ goto err_close;
+ }
+
+ /* Delete any IP addresses until SIOCDIFADDR fails */
+ while (ioctl(fd, SIOCDIFADDR, (void *)&areq) != -1) ;
+
+ close(fd);
+ return 0;
+#endif
+
+err_close:
+ close((*tun)->fd);
+err_free:
+ free(*tun);
+ *tun = NULL;
+ return -1;
+}
+
+int tun_free(struct tun_t *tun)
+{
+
+ if (tun->routes) {
+ netdev_delroute4(&tun->dstaddr.u.sin.sin_addr, &tun->addr.u.sin.sin_addr, &tun->netmask);
+ }
+
+ if (tun->fd >= 0) {
+ if (close(tun->fd)) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno, "close() failed");
+ }
+ }
+
+ gtp_kernel_stop(tun->devname);
+
+ /* TODO: For solaris we need to unlink streams */
+
+ free(tun);
+ return 0;
+}
+
+int tun_set_cb_ind(struct tun_t *this,
+ int (*cb_ind) (struct tun_t * tun, void *pack, unsigned len))
+{
+ this->cb_ind = cb_ind;
+ return 0;
+}
+
+int tun_decaps(struct tun_t *this)
+{
+ unsigned char buffer[PACKET_MAX];
+ int status;
+
+ if ((status = read(this->fd, buffer, sizeof(buffer))) <= 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno, "read() failed");
+ return -1;
+ }
+
+ if (this->cb_ind)
+ return this->cb_ind(this, buffer, status);
+
+ return 0;
+}
+
+int tun_encaps(struct tun_t *tun, void *pack, unsigned len)
+{
+ int rc;
+ rc = write(tun->fd, pack, len);
+ if (rc < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno, "TUN(%s): write() failed", tun->devname);
+ } else if (rc < len) {
+ LOGTUN(LOGL_ERROR, tun, "short write() %d < %u\n", rc, len);
+ }
+ return rc;
+}
+
+int tun_runscript(struct tun_t *tun, char *script)
+{
+
+ char buf[TUN_SCRIPTSIZE];
+ char snet[TUN_ADDRSIZE];
+ char smask[TUN_ADDRSIZE];
+ int rc;
+
+ snet[0] = '\0';
+ smask[0] = '\0';
+
+ /* system("ipup /dev/tun0 192.168.0.10 255.255.255.0"); */
+ snprintf(buf, sizeof(buf), "%s %s %s %s",
+ script, tun->devname,
+ osmo_sockaddr_ntop(&tun->addr.u.sa, snet),
+ inet_ntop(AF_INET, &tun->netmask, smask, sizeof(smask)));
+ buf[sizeof(buf) - 1] = 0;
+ rc = system(buf);
+ if (rc == -1) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno,
+ "Error executing command %s", buf);
+ return -1;
+ }
+ return 0;
+}
+
+/*! Obtain the local address of the tun device.
+ * \param[in] tun Target device owning the IP
+ * \param[out] prefix_list List of prefix structures to fill with each IPv4/6 and prefix length found.
+ * \param[in] prefix_size Amount of elements allowed to be fill in the prefix_list array.
+ * \param[in] flags Specify which kind of IP to look for: IP_TYPE_IPv4, IP_TYPE_IPv6_LINK, IP_TYPE_IPv6_NONLINK
+ * \returns The number of ips found following the criteria specified by flags, -1 on error.
+ *
+ * This function will fill prefix_list with up to prefix_size IPs following the
+ * criteria specified by flags parameter. It returns the number of IPs matching
+ * the criteria. As a result, the number returned can be bigger than
+ * prefix_size. It can be used with prefix_size=0 to get an estimate of the size
+ * needed for prefix_list.
+ */
+int tun_ip_local_get(const struct tun_t *tun, struct in46_prefix *prefix_list, size_t prefix_size, int flags)
+{
+ return netdev_ip_local_get(tun->devname, prefix_list, prefix_size, flags);
+}
--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/30994
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: Id8611b720ada17a3c602872fe095bb91eeb17bcd
Gerrit-Change-Number: 30994
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: newchange
1
0
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/30993 )
Change subject: layer23: Introduce netdev.{c,h}
......................................................................
layer23: Introduce netdev.{c,h}
This module provides several operations on network devices (interfaces).
These functionalitites will be used by the tun module included in a
follow-up patch.
The code is basically an import from osmo-ggsn.git
97f60e3dca581797007524e0006ca9fafad59713 src/lib/netdev.{c,h}, with
small modifications to make use of osmo_sockaddr instead of
osmo-ggsn.git specific in46_addr.
A new API osmo_sockaddr_netmask_to_prefixlen() which has been recently
ported osmo-ggsn.git -> libosmocore (in46_addr -> osmo_sockaddr) is also
used.
Depends: libosmocore.git Change-Id I75e75e251c6776801fffdde745aebedf21c68799
Related: OS#5503
Change-Id: I6085dc6861687bd4e9c32e86221c0375ad95ba22
---
A src/host/layer23/TODO-RELEASE
M src/host/layer23/configure.ac
M src/host/layer23/include/osmocom/bb/common/Makefile.am
M src/host/layer23/include/osmocom/bb/common/logging.h
A src/host/layer23/include/osmocom/bb/common/netdev.h
M src/host/layer23/src/common/Makefile.am
M src/host/layer23/src/common/logging.c
A src/host/layer23/src/common/netdev.c
8 files changed, 906 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/93/30993/1
diff --git a/src/host/layer23/TODO-RELEASE b/src/host/layer23/TODO-RELEASE
new file mode 100644
index 0000000..50836cd
--- /dev/null
+++ b/src/host/layer23/TODO-RELEASE
@@ -0,0 +1,10 @@
+# When cleaning up this file: bump API version in corresponding Makefile.am and rename corresponding debian/lib*.install
+# according to https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info…
+# In short:
+# LIBVERSION=c:r:a
+# If the library source code has changed at all since the last update, then increment revision: c:r + 1:a.
+# If any interfaces have been added, removed, or changed since the last update: c + 1:0:0.
+# If any interfaces have been added since the last public release: c:r:a + 1.
+# If any interfaces have been removed or changed since the last public release: c:r:0.
+#library what description / commit summary line
+libosmocore >1.7.0 osmo_sockaddr_netmask_to_prefixlen()
diff --git a/src/host/layer23/configure.ac b/src/host/layer23/configure.ac
index 81c0e65..43ed0fb 100644
--- a/src/host/layer23/configure.ac
+++ b/src/host/layer23/configure.ac
@@ -51,6 +51,12 @@
AC_SUBST([LIBGPS_CFLAGS])
AC_SUBST([LIBGPS_LIBS])
+AC_MSG_CHECKING(whether struct iphdr exists)
+AH_TEMPLATE(HAVE_IPHDR)
+AC_EGREP_HEADER(struct iphdr, netinet/ip.h,
+[AC_MSG_RESULT(yes)
+ AC_DEFINE([HAVE_IPHDR])],
+ AC_MSG_RESULT(no))
dnl optional dependencies
AC_ARG_WITH([lua53], [
diff --git a/src/host/layer23/include/osmocom/bb/common/Makefile.am b/src/host/layer23/include/osmocom/bb/common/Makefile.am
index 28caf78..12be730 100644
--- a/src/host/layer23/include/osmocom/bb/common/Makefile.am
+++ b/src/host/layer23/include/osmocom/bb/common/Makefile.am
@@ -5,6 +5,7 @@
l23_app.h \
logging.h \
ms.h \
+ netdev.h \
networks.h \
gps.h \
sysinfo.h \
diff --git a/src/host/layer23/include/osmocom/bb/common/logging.h b/src/host/layer23/include/osmocom/bb/common/logging.h
index e968528..5259f35 100644
--- a/src/host/layer23/include/osmocom/bb/common/logging.h
+++ b/src/host/layer23/include/osmocom/bb/common/logging.h
@@ -26,6 +26,7 @@
DPRIM,
DLUA,
DGAPK,
+ DTUN,
};
extern const struct log_info log_info;
diff --git a/src/host/layer23/include/osmocom/bb/common/netdev.h b/src/host/layer23/include/osmocom/bb/common/netdev.h
new file mode 100644
index 0000000..e94ec60
--- /dev/null
+++ b/src/host/layer23/include/osmocom/bb/common/netdev.h
@@ -0,0 +1,79 @@
+#pragma once
+/*
+ * TUN interface functions.
+ * Copyright (C) 2002, 2003 Mondru AB.
+ * Copyright (C) 2017-2018 by Harald Welte <laforge(a)gnumonks.org>
+ * Copyright (C) 2023 by sysmocom - s.m.f.c. GmbH <info(a)sysmocom.de>
+ *
+ * The contents of this file may be used under the terms of the GNU
+ * General Public License Version 2, provided that the above copyright
+ * notice and this permission notice is included in all copies or
+ * substantial portions of the software.
+ *
+ */
+
+#include <net/if.h>
+#include <osmocom/core/socket.h>
+
+#include "config.h"
+
+#define TUN_NLBUFSIZE 1024
+
+/* ipv6 ip type flags for tun_ipv6_local_get() */
+enum {
+ IP_TYPE_IPv4 = 1,
+ IP_TYPE_IPv6_LINK = 2,
+ IP_TYPE_IPv6_NONLINK = 4,
+};
+#define IP_TYPE_IPv6 (IP_TYPE_IPv6_LINK | IP_TYPE_IPv6_NONLINK)
+
+
+#ifndef HAVE_IPHDR
+struct iphdr
+ {
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+ unsigned int ihl:4;
+ unsigned int version:4;
+#elif __BYTE_ORDER == __BIG_ENDIAN
+ unsigned int version:4;
+ unsigned int ihl:4;
+#else
+# error "Please fix <bits/endian.h>"
+#endif
+ u_int8_t tos;
+ u_int16_t tot_len;
+ u_int16_t id;
+ u_int16_t frag_off;
+ u_int8_t ttl;
+ u_int8_t protocol;
+ u_int16_t check;
+ u_int32_t saddr;
+ u_int32_t daddr;
+ /*The options start here. */
+ };
+#endif /* !HAVE_IPHDR */
+
+struct in46_prefix {
+ struct osmo_sockaddr addr;
+ uint8_t prefixlen;
+};
+
+extern int netdev_setaddr4(const char *devname, struct in_addr *addr,
+ struct in_addr *dstaddr, struct in_addr *netmask);
+
+extern int netdev_setaddr6(const char *devname, struct in6_addr *addr, struct in6_addr *dstaddr,
+ size_t prefixlen);
+
+extern int netdev_addaddr4(const char *devname, struct in_addr *addr,
+ struct in_addr *dstaddr, struct in_addr *netmask);
+
+extern int netdev_addaddr6(const char *devname, struct in6_addr *addr,
+ struct in6_addr *dstaddr, int prefixlen);
+
+extern int netdev_addroute4(struct in_addr *dst, struct in_addr *gateway, struct in_addr *mask);
+extern int netdev_delroute4(struct in_addr *dst, struct in_addr *gateway, struct in_addr *mask);
+extern int netdev_addroute6(struct in6_addr *dst, struct in6_addr *gateway, int prefixlen, const char *gw_iface);
+extern int netdev_delroute6(struct in6_addr *dst, struct in6_addr *gateway, int prefixlen, const char *gw_iface);
+
+extern int netdev_ip_local_get(const char *devname, struct in46_prefix *prefix_list,
+ size_t prefix_size, int flags);
diff --git a/src/host/layer23/src/common/Makefile.am b/src/host/layer23/src/common/Makefile.am
index 94eeec8..3a6ba37 100644
--- a/src/host/layer23/src/common/Makefile.am
+++ b/src/host/layer23/src/common/Makefile.am
@@ -20,6 +20,7 @@
l1ctl_lapdm_glue.c \
logging.c \
ms.c \
+ netdev.c \
networks.c \
sap_fsm.c \
sap_proto.c \
diff --git a/src/host/layer23/src/common/logging.c b/src/host/layer23/src/common/logging.c
index 56f0322..34c171f 100644
--- a/src/host/layer23/src/common/logging.c
+++ b/src/host/layer23/src/common/logging.c
@@ -147,6 +147,12 @@
.color = "\033[0;36m",
.enabled = 1, .loglevel = LOGL_DEBUG,
},
+ [DTUN] = {
+ .name = "DTUN",
+ .description = "Tunnel interface",
+ .color = "\033[0;37m",
+ .enabled = 1, .loglevel = LOGL_NOTICE,
+ },
};
const struct log_info log_info = {
diff --git a/src/host/layer23/src/common/netdev.c b/src/host/layer23/src/common/netdev.c
new file mode 100644
index 0000000..46baea5
--- /dev/null
+++ b/src/host/layer23/src/common/netdev.c
@@ -0,0 +1,802 @@
+/*
+ * TUN interface functions.
+ * Copyright (C) 2002, 2003, 2004 Mondru AB.
+ * Copyright (C) 2017-2018 by Harald Welte <laforge(a)gnumonks.org>
+ * Copyright (C) 2023 by sysmocom - s.m.f.c. GmbH <info(a)sysmocom.de>
+ *
+ * The contents of this file may be used under the terms of the GNU
+ * General Public License Version 2, provided that the above copyright
+ * notice and this permission notice is included in all copies or
+ * substantial portions of the software.
+ *
+ */
+
+/*
+ * netdev.c: Contains generic network device related functionality.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <errno.h>
+#include <net/route.h>
+#include <net/if.h>
+
+#if defined(__linux__)
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+
+#elif defined (__FreeBSD__)
+#include <net/if_var.h>
+#include <netinet/in_var.h>
+
+#elif defined (__APPLE__)
+#include <net/if.h>
+
+#else
+#error "Unknown platform!"
+#endif
+
+#include <osmocom/core/logging.h>
+#include <osmocom/core/socket.h>
+#include <osmocom/bb/common/logging.h>
+#include <osmocom/bb/common/netdev.h>
+
+#define SYS_ERR(sub, pri, en, fmt, args...) \
+ if (en) { \
+ logp2(sub, pri, __FILE__, __LINE__, 0, \
+ "errno=%d/%s " fmt "\n", en, strerror(en), \
+ ##args); \
+ } else { \
+ logp2(sub, pri, __FILE__, __LINE__, 0, \
+ fmt "\n", ##args); \
+ }
+
+#if defined(__linux__)
+
+#include <linux/ipv6.h>
+
+static int netdev_nlattr(struct nlmsghdr *n, int nsize, int type, void *d, int dlen)
+{
+ int len = RTA_LENGTH(dlen);
+ int alen = NLMSG_ALIGN(n->nlmsg_len);
+ struct rtattr *rta = (struct rtattr *)(((void *)n) + alen);
+ if (alen + len > nsize)
+ return -1;
+ rta->rta_len = len;
+ rta->rta_type = type;
+ memcpy(RTA_DATA(rta), d, dlen);
+ n->nlmsg_len = alen + len;
+ return 0;
+}
+#endif
+
+static int netdev_sifflags(const char *devname, int flags)
+{
+ struct ifreq ifr;
+ int fd;
+
+ memset(&ifr, '\0', sizeof(ifr));
+ ifr.ifr_flags = flags;
+ strncpy(ifr.ifr_name, devname, IFNAMSIZ);
+ ifr.ifr_name[IFNAMSIZ - 1] = 0; /* Make sure to terminate */
+ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno, "socket() failed");
+ return -1;
+ }
+ if (ioctl(fd, SIOCSIFFLAGS, &ifr)) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno,
+ "ioctl(SIOCSIFFLAGS) failed");
+ close(fd);
+ return -1;
+ }
+ close(fd);
+ return 0;
+}
+
+int netdev_setaddr4(const char *devname, struct in_addr *addr,
+ struct in_addr *dstaddr, struct in_addr *netmask)
+{
+ struct ifreq ifr;
+ int fd;
+
+ memset(&ifr, '\0', sizeof(ifr));
+ ifr.ifr_addr.sa_family = AF_INET;
+ ifr.ifr_dstaddr.sa_family = AF_INET;
+
+#if defined(__linux__)
+ ifr.ifr_netmask.sa_family = AF_INET;
+#elif defined(__FreeBSD__) || defined (__APPLE__)
+ ((struct sockaddr_in *)&ifr.ifr_addr)->sin_len =
+ sizeof(struct sockaddr_in);
+ ((struct sockaddr_in *)&ifr.ifr_dstaddr)->sin_len =
+ sizeof(struct sockaddr_in);
+#endif
+
+ strncpy(ifr.ifr_name, devname, IFNAMSIZ);
+ ifr.ifr_name[IFNAMSIZ - 1] = 0; /* Make sure to terminate */
+
+ /* Create a channel to the NET kernel. */
+ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno, "socket() failed");
+ return -1;
+ }
+
+ if (addr) { /* Set the interface address */
+ memcpy(&((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr, addr,
+ sizeof(*addr));
+ if (ioctl(fd, SIOCSIFADDR, (void *)&ifr) < 0) {
+ if (errno != EEXIST) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno,
+ "ioctl(SIOCSIFADDR) failed");
+ } else {
+ SYS_ERR(DTUN, LOGL_NOTICE, errno,
+ "ioctl(SIOCSIFADDR): Address already exists");
+ }
+ close(fd);
+ return -1;
+ }
+ }
+
+ if (dstaddr) { /* Set the destination address */
+ memcpy(&((struct sockaddr_in *)&ifr.ifr_dstaddr)->sin_addr,
+ dstaddr, sizeof(*dstaddr));
+ if (ioctl(fd, SIOCSIFDSTADDR, (caddr_t) & ifr) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno,
+ "ioctl(SIOCSIFDSTADDR) failed");
+ close(fd);
+ return -1;
+ }
+ }
+
+ if (netmask) { /* Set the netmask */
+#if defined(__linux__)
+ memcpy(&((struct sockaddr_in *)&ifr.ifr_netmask)->sin_addr,
+ netmask, sizeof(*netmask));
+#elif defined(__FreeBSD__) || defined (__APPLE__)
+ ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr =
+ netmask->s_addr;
+#endif
+
+ if (ioctl(fd, SIOCSIFNETMASK, (void *)&ifr) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno,
+ "ioctl(SIOCSIFNETMASK) failed");
+ close(fd);
+ return -1;
+ }
+ }
+
+ close(fd);
+
+ netdev_sifflags(devname, IFF_UP | IFF_RUNNING);
+
+ /* On linux the route to the interface is set automatically
+ on FreeBSD we have to do this manually */
+#if defined(__FreeBSD__) || defined (__APPLE__)
+ netdev_addroute4(dstaddr, addr, &this->netmask);
+#endif
+
+ return 0;
+}
+
+int netdev_setaddr6(const char *devname, struct in6_addr *addr, struct in6_addr *dstaddr,
+ size_t prefixlen)
+{
+ struct in6_ifreq ifr;
+ int fd;
+
+ memset(&ifr, 0, sizeof(ifr));
+
+#if defined(__linux__)
+ ifr.ifr6_prefixlen = prefixlen;
+ ifr.ifr6_ifindex = if_nametoindex(devname);
+ if (ifr.ifr6_ifindex == 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, 0, "Error getting ifindex for %s\n", devname);
+ return -1;
+ }
+#elif defined(__FreeBSD__) || defined (__APPLE__)
+ strncpy(ifr.ifr_name, devname, IFNAMSIZ);
+#endif
+
+ /* Create a channel to the NET kernel */
+ if ((fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, 0, "socket() failed");
+ return -1;
+ }
+
+#if defined(__linux__)
+ if (addr) {
+ memcpy(&ifr.ifr6_addr, addr, sizeof(*addr));
+ if (ioctl(fd, SIOCSIFADDR, (void *) &ifr) < 0) {
+ if (errno != EEXIST) {
+ SYS_ERR(DTUN, LOGL_ERROR, 0, "ioctl(SIOCSIFADDR) failed");
+ } else {
+ SYS_ERR(DTUN, LOGL_NOTICE, 0, "ioctl(SIOCSIFADDR): Address already exists");
+ }
+ close(fd);
+ return -1;
+ }
+ }
+
+#if 0
+ /* FIXME: looks like this is not possible/necessary for IPv6? */
+ if (dstaddr) {
+ memcpy(&ifr.ifr6_addr, dstaddr, sizeof(*dstaddr));
+ if (ioctl(fd, SIOCSIFDSTADDR, (caddr_t *) &ifr) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, "ioctl(SIOCSIFDSTADDR) failed");
+ close(fd);
+ return -1;
+ }
+ }
+#endif
+
+#elif defined(__FreeBSD__) || defined (__APPLE__)
+ if (addr)
+ memcpy(&ifr.ifr_ifru.ifru_addr, addr, sizeof(ifr.ifr_ifru.ifru_addr));
+ if (dstaddr)
+ memcpy(&ifr.ifr_ifru.ifru_dstaddr, dstaddr, sizeof(ifr.ifr_ifru.ifru_dstaddr));
+
+ if (ioctl(fd, SIOCSIFADDR_IN6, (struct ifreq *)&ifr) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, 0, "ioctl(SIOCSIFADDR_IN6) failed");
+ close(fd);
+ return -1;
+ }
+#endif
+
+ close(fd);
+
+ netdev_sifflags(devname, IFF_UP | IFF_RUNNING);
+
+ /* On linux the route to the interface is set automatically
+ on FreeBSD we have to do this manually */
+#if 0 /* FIXME */
+//#if defined(__FreeBSD__) || defined (__APPLE__)
+ netdev_addroute6(dstaddr, addr, prefixlen);
+#endif
+
+ return 0;
+}
+
+int netdev_addaddr4(const char *devname, struct in_addr *addr,
+ struct in_addr *dstaddr, struct in_addr *netmask)
+{
+ int fd;
+#if defined(__linux__)
+ struct {
+ struct nlmsghdr n;
+ struct ifaddrmsg i;
+ char buf[TUN_NLBUFSIZE];
+ } req;
+
+ struct sockaddr_nl local;
+ socklen_t addr_len;
+ int status;
+
+ struct sockaddr_nl nladdr;
+ struct iovec iov;
+ struct msghdr msg;
+
+ memset(&req, 0, sizeof(req));
+ req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
+ req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE;
+ req.n.nlmsg_type = RTM_NEWADDR;
+ req.i.ifa_family = AF_INET;
+ req.i.ifa_prefixlen = 32; /* 32 FOR IPv4 */
+ req.i.ifa_flags = 0;
+ req.i.ifa_scope = RT_SCOPE_HOST; /* TODO or 0 */
+ req.i.ifa_index = if_nametoindex(devname);
+ if (!req.i.ifa_index) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno, "Unable to get ifindex for %s", devname);
+ return -1;
+ }
+
+ netdev_nlattr(&req.n, sizeof(req), IFA_ADDRESS, addr, sizeof(*addr));
+ if (dstaddr)
+ netdev_nlattr(&req.n, sizeof(req), IFA_LOCAL, dstaddr, sizeof(*dstaddr));
+
+ if ((fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno, "socket() failed");
+ return -1;
+ }
+
+ memset(&local, 0, sizeof(local));
+ local.nl_family = AF_NETLINK;
+ local.nl_groups = 0;
+
+ if (bind(fd, (struct sockaddr *)&local, sizeof(local)) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno, "bind() failed");
+ close(fd);
+ return -1;
+ }
+
+ addr_len = sizeof(local);
+ if (getsockname(fd, (struct sockaddr *)&local, &addr_len) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno,
+ "getsockname() failed");
+ close(fd);
+ return -1;
+ }
+
+ if (addr_len != sizeof(local)) {
+ SYS_ERR(DTUN, LOGL_ERROR, 0,
+ "Wrong address length %d", addr_len);
+ close(fd);
+ return -1;
+ }
+
+ if (local.nl_family != AF_NETLINK) {
+ SYS_ERR(DTUN, LOGL_ERROR, 0,
+ "Wrong address family %d", local.nl_family);
+ close(fd);
+ return -1;
+ }
+
+ iov.iov_base = (void *)&req.n;
+ iov.iov_len = req.n.nlmsg_len;
+
+ msg.msg_name = (void *)&nladdr;
+ msg.msg_namelen = sizeof(nladdr);
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+ msg.msg_control = NULL;
+ msg.msg_controllen = 0;
+ msg.msg_flags = 0;
+
+ memset(&nladdr, 0, sizeof(nladdr));
+ nladdr.nl_family = AF_NETLINK;
+ nladdr.nl_pid = 0;
+ nladdr.nl_groups = 0;
+
+ req.n.nlmsg_seq = 0;
+ req.n.nlmsg_flags |= NLM_F_ACK;
+
+ status = sendmsg(fd, &msg, 0);
+ if (status != req.n.nlmsg_len) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno, "sendmsg() failed, returned %d", status);
+ close(fd);
+ return -1;
+ }
+
+ status = netdev_sifflags(devname, IFF_UP | IFF_RUNNING);
+ if (status == -1) {
+ close(fd);
+ return -1;
+ }
+#elif defined (__FreeBSD__) || defined (__APPLE__)
+ struct ifaliasreq areq;
+
+ memset(&areq, 0, sizeof(areq));
+
+ /* Set up interface name */
+ strncpy(areq.ifra_name, devname, IFNAMSIZ);
+ areq.ifra_name[IFNAMSIZ - 1] = 0; /* Make sure to terminate */
+
+ ((struct sockaddr_in *)&areq.ifra_addr)->sin_family = AF_INET;
+ ((struct sockaddr_in *)&areq.ifra_addr)->sin_len =
+ sizeof(areq.ifra_addr);
+ ((struct sockaddr_in *)&areq.ifra_addr)->sin_addr.s_addr = addr->s_addr;
+
+ ((struct sockaddr_in *)&areq.ifra_mask)->sin_family = AF_INET;
+ ((struct sockaddr_in *)&areq.ifra_mask)->sin_len =
+ sizeof(areq.ifra_mask);
+ ((struct sockaddr_in *)&areq.ifra_mask)->sin_addr.s_addr =
+ netmask->s_addr;
+
+ /* For some reason FreeBSD uses ifra_broadcast for specifying dstaddr */
+ ((struct sockaddr_in *)&areq.ifra_broadaddr)->sin_family = AF_INET;
+ ((struct sockaddr_in *)&areq.ifra_broadaddr)->sin_len =
+ sizeof(areq.ifra_broadaddr);
+ ((struct sockaddr_in *)&areq.ifra_broadaddr)->sin_addr.s_addr =
+ dstaddr->s_addr;
+
+ /* Create a channel to the NET kernel. */
+ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno, "socket() failed");
+ return -1;
+ }
+
+ if (ioctl(fd, SIOCAIFADDR, (void *)&areq) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno,
+ "ioctl(SIOCAIFADDR) failed");
+ close(fd);
+ return -1;
+ }
+#endif
+ close(fd);
+ return 0;
+}
+
+int netdev_addaddr6(const char *devname, struct in6_addr *addr,
+ struct in6_addr *dstaddr, int prefixlen)
+{
+ int fd;
+#if defined(__linux__)
+ struct {
+ struct nlmsghdr n;
+ struct ifaddrmsg i;
+ char buf[TUN_NLBUFSIZE];
+ } req;
+
+ struct sockaddr_nl local;
+ socklen_t addr_len;
+ int status;
+
+ struct sockaddr_nl nladdr;
+ struct iovec iov;
+ struct msghdr msg;
+
+ memset(&req, 0, sizeof(req));
+ req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
+ req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE;
+ req.n.nlmsg_type = RTM_NEWADDR;
+ req.i.ifa_family = AF_INET6;
+ req.i.ifa_prefixlen = prefixlen; /* 64 FOR IPv6 */
+ req.i.ifa_flags = 0;
+ req.i.ifa_scope = RT_SCOPE_HOST; /* TODO or 0 */
+ req.i.ifa_index = if_nametoindex(devname);
+ if (!req.i.ifa_index) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno, "Unable to get ifindex for %s", devname);
+ return -1;
+ }
+
+ netdev_nlattr(&req.n, sizeof(req), IFA_ADDRESS, addr, sizeof(*addr));
+ if (dstaddr)
+ netdev_nlattr(&req.n, sizeof(req), IFA_LOCAL, dstaddr, sizeof(*dstaddr));
+
+ if ((fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno, "socket() failed");
+ return -1;
+ }
+
+ memset(&local, 0, sizeof(local));
+ local.nl_family = AF_NETLINK;
+ local.nl_groups = 0;
+
+ if (bind(fd, (struct sockaddr *)&local, sizeof(local)) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno, "bind() failed");
+ close(fd);
+ return -1;
+ }
+
+ addr_len = sizeof(local);
+ if (getsockname(fd, (struct sockaddr *)&local, &addr_len) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno,
+ "getsockname() failed");
+ close(fd);
+ return -1;
+ }
+
+ if (addr_len != sizeof(local)) {
+ SYS_ERR(DTUN, LOGL_ERROR, 0,
+ "Wrong address length %d", addr_len);
+ close(fd);
+ return -1;
+ }
+
+ if (local.nl_family != AF_NETLINK) {
+ SYS_ERR(DTUN, LOGL_ERROR, 0,
+ "Wrong address family %d", local.nl_family);
+ close(fd);
+ return -1;
+ }
+
+ iov.iov_base = (void *)&req.n;
+ iov.iov_len = req.n.nlmsg_len;
+
+ msg.msg_name = (void *)&nladdr;
+ msg.msg_namelen = sizeof(nladdr);
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+ msg.msg_control = NULL;
+ msg.msg_controllen = 0;
+ msg.msg_flags = 0;
+
+ memset(&nladdr, 0, sizeof(nladdr));
+ nladdr.nl_family = AF_NETLINK;
+ nladdr.nl_pid = 0;
+ nladdr.nl_groups = 0;
+
+ req.n.nlmsg_seq = 0;
+ req.n.nlmsg_flags |= NLM_F_ACK;
+
+ status = sendmsg(fd, &msg, 0);
+ if (status != req.n.nlmsg_len) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno, "sendmsg() failed, returned %d", status);
+ close(fd);
+ return -1;
+ }
+
+ status = netdev_sifflags(devname, IFF_UP | IFF_RUNNING);
+ if (status == -1) {
+ close(fd);
+ return -1;
+ }
+#elif defined (__FreeBSD__) || defined (__APPLE__)
+ struct ifaliasreq areq;
+
+ memset(&areq, 0, sizeof(areq));
+
+ /* Set up interface name */
+ strncpy(areq.ifra_name, devname, IFNAMSIZ);
+ areq.ifra_name[IFNAMSIZ - 1] = 0; /* Make sure to terminate */
+
+ ((struct sockaddr_in6 *)&areq.ifra_addr)->sin6_family = AF_INET6;
+ ((struct sockaddr_in6 *)&areq.ifra_addr)->sin6_len = sizeof(areq.ifra_addr);
+ ((struct sockaddr_in6 *)&areq.ifra_addr)->sin6_addr.s6_addr = addr->s6_addr;
+
+ ((struct sockaddr_in6 *)&areq.ifra_mask)->sin6_family = AF_INET6;
+ ((struct sockaddr_in6 *)&areq.ifra_mask)->sin6_len = sizeof(areq.ifra_mask);
+ ((struct sockaddr_in6 *)&areq.ifra_mask)->sin6_addr.s6_addr = netmask->s6_addr;
+
+ /* For some reason FreeBSD uses ifra_broadcast for specifying dstaddr */
+ ((struct sockaddr_in6 *)&areq.ifra_broadaddr)->sin6_family = AF_INET6;
+ ((struct sockaddr_in6 *)&areq.ifra_broadaddr)->sin6_len = sizeof(areq.ifra_broadaddr);
+ ((struct sockaddr_in6 *)&areq.ifra_broadaddr)->sin6_addr.s6_addr = dstaddr->s6_addr;
+
+ /* Create a channel to the NET kernel. */
+ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno, "socket() failed");
+ return -1;
+ }
+
+ if (ioctl(fd, SIOCAIFADDR, (void *)&areq) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno,
+ "ioctl(SIOCAIFADDR) failed");
+ close(fd);
+ return -1;
+ }
+#endif
+ close(fd);
+ return 0;
+}
+
+static int netdev_route4(struct in_addr *dst, struct in_addr *gateway, struct in_addr *mask, int delete)
+{
+ int fd;
+#if defined(__linux__)
+ struct rtentry r;
+
+ memset(&r, '\0', sizeof(r));
+ r.rt_flags = RTF_UP | RTF_GATEWAY; /* RTF_HOST not set */
+
+ /* Create a channel to the NET kernel. */
+ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno, "socket() failed");
+ return -1;
+ }
+
+ r.rt_dst.sa_family = AF_INET;
+ r.rt_gateway.sa_family = AF_INET;
+ r.rt_genmask.sa_family = AF_INET;
+ memcpy(&((struct sockaddr_in *)&r.rt_dst)->sin_addr, dst, sizeof(*dst));
+ memcpy(&((struct sockaddr_in *)&r.rt_gateway)->sin_addr, gateway,
+ sizeof(*gateway));
+ memcpy(&((struct sockaddr_in *)&r.rt_genmask)->sin_addr, mask,
+ sizeof(*mask));
+
+ if (delete) {
+ if (ioctl(fd, SIOCDELRT, (void *)&r) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno,
+ "ioctl(SIOCDELRT) failed");
+ close(fd);
+ return -1;
+ }
+ } else {
+ if (ioctl(fd, SIOCADDRT, (void *)&r) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno,
+ "ioctl(SIOCADDRT) failed");
+ close(fd);
+ return -1;
+ }
+ }
+#elif defined(__FreeBSD__) || defined (__APPLE__)
+ struct {
+ struct rt_msghdr rt;
+ struct sockaddr_in dst;
+ struct sockaddr_in gate;
+ struct sockaddr_in mask;
+ } req;
+ struct rt_msghdr *rtm;
+
+ if ((fd = socket(AF_ROUTE, SOCK_RAW, 0)) == -1) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno, "socket() failed");
+ return -1;
+ }
+
+ memset(&req, 0x00, sizeof(req));
+
+ rtm = &req.rt;
+
+ rtm->rtm_msglen = sizeof(req);
+ rtm->rtm_version = RTM_VERSION;
+ if (delete) {
+ rtm->rtm_type = RTM_DELETE;
+ } else {
+ rtm->rtm_type = RTM_ADD;
+ }
+ rtm->rtm_flags = RTF_UP | RTF_GATEWAY | RTF_STATIC; /* TODO */
+ rtm->rtm_addrs = RTA_DST | RTA_GATEWAY | RTA_NETMASK;
+ rtm->rtm_pid = getpid();
+ rtm->rtm_seq = 0044; /* TODO */
+
+ req.dst.sin_family = AF_INET;
+ req.dst.sin_len = sizeof(req.dst);
+ req.mask.sin_family = AF_INET;
+ req.mask.sin_len = sizeof(req.mask);
+ req.gate.sin_family = AF_INET;
+ req.gate.sin_len = sizeof(req.gate);
+
+ req.dst.sin_addr.s_addr = dst->s_addr;
+ req.mask.sin_addr.s_addr = mask->s_addr;
+ req.gate.sin_addr.s_addr = gateway->s_addr;
+
+ if (write(fd, rtm, rtm->rtm_msglen) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno, "write() failed");
+ close(fd);
+ return -1;
+ }
+#endif
+ close(fd);
+ return 0;
+}
+
+static int netdev_route6(struct in6_addr *dst, struct in6_addr *gateway, int prefixlen, const char *gw_iface, int delete)
+{
+ int fd;
+#if defined(__linux__)
+ struct in6_rtmsg r;
+ struct ifreq ifr;
+
+ memset(&r, 0, sizeof(r));
+ r.rtmsg_flags = RTF_UP | RTF_GATEWAY; /* RTF_HOST not set */
+ r.rtmsg_metric = 1;
+
+ /* Create a channel to the NET kernel. */
+ if ((fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno, "socket() failed");
+ return -1;
+ }
+
+ if (gw_iface) {
+ strncpy(ifr.ifr_name, gw_iface, IFNAMSIZ);
+ ifr.ifr_name[IFNAMSIZ - 1] = 0; /* Make sure to terminate */
+ if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno,
+ "ioctl(SIOCGIFINDEX) failed");
+ close(fd);
+ return -1;
+ }
+ r.rtmsg_ifindex = ifr.ifr_ifindex;
+ }
+
+ memcpy(&r.rtmsg_dst, dst->s6_addr, sizeof(struct in6_addr));
+ memcpy(&r.rtmsg_gateway, gateway->s6_addr, sizeof(struct in6_addr));
+ r.rtmsg_dst_len = prefixlen;
+
+ if (delete) {
+ if (ioctl(fd, SIOCDELRT, (void *)&r) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno,
+ "ioctl(SIOCDELRT) failed");
+ close(fd);
+ return -1;
+ }
+ } else {
+ if (ioctl(fd, SIOCADDRT, (void *)&r) < 0) {
+ SYS_ERR(DTUN, LOGL_ERROR, errno,
+ "ioctl(SIOCADDRT) failed");
+ close(fd);
+ return -1;
+ }
+ }
+ close(fd);
+#endif
+ return 0;
+}
+
+int netdev_addroute4(struct in_addr *dst, struct in_addr *gateway, struct in_addr *mask)
+{
+ return netdev_route4(dst, gateway, mask, 0);
+}
+
+int netdev_delroute4(struct in_addr *dst, struct in_addr *gateway, struct in_addr *mask)
+{
+ return netdev_route4(dst, gateway, mask, 1);
+}
+
+int netdev_addroute6(struct in6_addr *dst, struct in6_addr *gateway, int prefixlen, const char *gw_iface)
+{
+ return netdev_route6(dst, gateway, prefixlen, gw_iface, 0);
+}
+
+int netdev_delroute6(struct in6_addr *dst, struct in6_addr *gateway, int prefixlen, const char *gw_iface)
+{
+ return netdev_route6(dst, gateway, prefixlen, gw_iface, 1);
+}
+
+
+
+#include <ifaddrs.h>
+
+/*! Obtain the local address of a network device
+ * \param[in] devname Target device owning the IP
+ * \param[out] prefix_list List of prefix structures to fill with each IPv4/6 and prefix length found.
+ * \param[in] prefix_size Amount of elements allowed to be fill in the prefix_list array.
+ * \param[in] flags Specify which kind of IP to look for: IP_TYPE_IPv4, IP_TYPE_IPv6_LINK, IP_TYPE_IPv6_NONLINK
+ * \returns The number of ips found following the criteria specified by flags, -1 on error.
+ *
+ * This function will fill prefix_list with up to prefix_size IPs following the
+ * criteria specified by flags parameter. It returns the number of IPs matching
+ * the criteria. As a result, the number returned can be bigger than
+ * prefix_size. It can be used with prefix_size=0 to get an estimate of the size
+ * needed for prefix_list.
+ */
+int netdev_ip_local_get(const char *devname, struct in46_prefix *prefix_list, size_t prefix_size, int flags)
+{
+ static const uint8_t ll_prefix[] = { 0xfe,0x80, 0,0, 0,0, 0,0 };
+ struct ifaddrs *ifaddr, *ifa;
+ size_t count = 0;
+ bool is_ipv6_ll;
+
+ if (getifaddrs(&ifaddr) == -1) {
+ return -1;
+ }
+
+ for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
+ if (ifa->ifa_addr == NULL)
+ continue;
+
+ if (strcmp(ifa->ifa_name, devname))
+ continue;
+
+ if (ifa->ifa_addr->sa_family == AF_INET && (flags & IP_TYPE_IPv4)) {
+ struct sockaddr_in *sin4 = (struct sockaddr_in *) ifa->ifa_addr;
+ struct sockaddr_in *netmask4 = (struct sockaddr_in *) ifa->ifa_netmask;
+
+ if (count < prefix_size) {
+ prefix_list[count].addr.u.sin.sin_family = AF_INET;
+ prefix_list[count].addr.u.sin.sin_addr = sin4->sin_addr;
+ prefix_list[count].prefixlen =
+ osmo_sockaddr_netmask_to_prefixlen((struct osmo_sockaddr *)netmask4);
+ }
+ count++;
+ }
+
+ if (ifa->ifa_addr->sa_family == AF_INET6 && (flags & IP_TYPE_IPv6)) {
+ struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) ifa->ifa_addr;
+ struct sockaddr_in6 *netmask6 = (struct sockaddr_in6 *) ifa->ifa_netmask;
+
+ is_ipv6_ll = !memcmp(sin6->sin6_addr.s6_addr, ll_prefix, sizeof(ll_prefix));
+ if ((flags & IP_TYPE_IPv6_NONLINK) && is_ipv6_ll)
+ continue;
+ if ((flags & IP_TYPE_IPv6_LINK) && !is_ipv6_ll)
+ continue;
+
+ if (count < prefix_size) {
+ prefix_list[count].addr.u.sin6.sin6_family = AF_INET6;
+ prefix_list[count].addr.u.sin6.sin6_addr = sin6->sin6_addr;
+ prefix_list[count].prefixlen =
+ osmo_sockaddr_netmask_to_prefixlen((struct osmo_sockaddr *)netmask6);
+ }
+ count++;
+ }
+ }
+
+ freeifaddrs(ifaddr);
+ return count;
+}
--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/30993
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I6085dc6861687bd4e9c32e86221c0375ad95ba22
Gerrit-Change-Number: 30993
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: newchange
1
0
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/30991 )
Change subject: layer23: generate config.h
......................................................................
layer23: generate config.h
Follow-up commits will add some extra checks we want to have in config.h
Include config.h in files using PACKAGE_VERSION.
Change-Id: Ic779a3168012780feef8d173371387d09d383bfd
---
M src/host/layer23/configure.ac
M src/host/layer23/src/common/main.c
M src/host/layer23/src/mobile/app_mobile.c
M src/host/layer23/src/modem/app_modem.c
4 files changed, 9 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/91/30991/1
diff --git a/src/host/layer23/configure.ac b/src/host/layer23/configure.ac
index 85765ae..81c0e65 100644
--- a/src/host/layer23/configure.ac
+++ b/src/host/layer23/configure.ac
@@ -89,6 +89,9 @@
AC_MSG_RESULT([CFLAGS="$CFLAGS"])
AC_MSG_RESULT([CPPFLAGS="$CPPFLAGS"])
+dnl Generate the output
+AM_CONFIG_HEADER(config.h)
+
AC_OUTPUT(
src/Makefile
src/common/Makefile
diff --git a/src/host/layer23/src/common/main.c b/src/host/layer23/src/common/main.c
index eecd29f..2cdf5d4 100644
--- a/src/host/layer23/src/common/main.c
+++ b/src/host/layer23/src/common/main.c
@@ -50,6 +50,8 @@
#include <fcntl.h>
#include <signal.h>
+#include "config.h"
+
void *l23_ctx = NULL;
static char *sap_socket_path = "/tmp/osmocom_sap";
diff --git a/src/host/layer23/src/mobile/app_mobile.c b/src/host/layer23/src/mobile/app_mobile.c
index ae4845d..5bb1920 100644
--- a/src/host/layer23/src/mobile/app_mobile.c
+++ b/src/host/layer23/src/mobile/app_mobile.c
@@ -54,6 +54,8 @@
#include <l1ctl_proto.h>
+#include "config.h"
+
extern void *l23_ctx;
extern struct llist_head ms_list;
extern int vty_reading;
diff --git a/src/host/layer23/src/modem/app_modem.c b/src/host/layer23/src/modem/app_modem.c
index 93f3b54..7dcda17 100644
--- a/src/host/layer23/src/modem/app_modem.c
+++ b/src/host/layer23/src/modem/app_modem.c
@@ -46,6 +46,8 @@
#include <l1ctl_proto.h>
+#include "config.h"
+
static struct {
struct osmocom_ms *ms;
enum ccch_mode ccch_mode;
--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/30991
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: Ic779a3168012780feef8d173371387d09d383bfd
Gerrit-Change-Number: 30991
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: newchange
1
0