Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 | /* $Id: isdn_ppp.c,v 1.13 1996/07/01 19:47:24 hipp Exp $
*
* Linux ISDN subsystem, functions for synchronous PPP (linklevel).
*
* Copyright 1995,96 by Michael Hipp (Michael.Hipp@student.uni-tuebingen.de)
*
* 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, 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: isdn_ppp.c,v $
* Revision 1.13 1996/07/01 19:47:24 hipp
* Fixed memory leak in VJ handling and more VJ changes
*
* Revision 1.12 1996/06/24 17:42:03 fritz
* Minor bugfixes.
*
* Revision 1.11 1996/06/16 17:46:05 tsbogend
* changed unsigned long to u32 to make Alpha people happy
*
* Revision 1.10 1996/06/11 14:50:29 hipp
* Lot of changes and bugfixes.
* New scheme to resend packets to busy LL devices.
*
* Revision 1.9 1996/05/18 01:37:01 fritz
* Added spelling corrections and some minor changes
* to stay in sync with kernel.
*
* Revision 1.8 1996/05/06 11:34:55 hipp
* fixed a few bugs
*
* Revision 1.7 1996/04/30 11:07:42 fritz
* Added Michael's ippp-bind patch.
*
* Revision 1.6 1996/04/30 09:33:09 fritz
* Removed compatibility-macros.
*
* Revision 1.5 1996/04/20 16:32:32 fritz
* Changed ippp_table to an array of pointers, allocating each part
* separately.
*
* Revision 1.4 1996/02/19 15:25:50 fritz
* Bugfix: Sync-PPP packets got compressed twice, when resent due to
* send-queue-full reject.
*
* Revision 1.3 1996/02/11 02:27:12 fritz
* Lot of Bugfixes my Michael.
* Moved calls to skb_push() into isdn_net_header()
* Fixed a possible race-condition in isdn_ppp_timer_timeout().
*
* Revision 1.2 1996/01/22 05:08:06 fritz
* Merged in Michael's patches for MP.
* Minor changes in isdn_ppp_xmit.
*
* Revision 1.1 1996/01/09 04:11:29 fritz
* Initial revision
*
*/
/* TODO: right tbusy handling when using MP */
#include <linux/config.h>
#define __NO_VERSION__
#include <linux/module.h>
#include <linux/isdn.h>
#include "isdn_common.h"
#include "isdn_ppp.h"
#include "isdn_net.h"
#ifndef PPP_IPX
#define PPP_IPX 0x002b
#endif
/* Prototypes */
static int isdn_ppp_fill_rq(unsigned char *buf, int len,int proto, int minor);
static int isdn_ppp_closewait(int);
static void isdn_ppp_push_higher(isdn_net_dev * net_dev, isdn_net_local * lp,
struct sk_buff *skb, int proto);
static int isdn_ppp_if_get_unit(char **namebuf);
#ifdef CONFIG_ISDN_MPP
static int isdn_ppp_bundle(int, int);
static void isdn_ppp_mask_queue(isdn_net_dev * dev, long mask);
static void isdn_ppp_cleanup_queue(isdn_net_dev * dev, long min);
static int isdn_ppp_fill_mpqueue(isdn_net_dev *, struct sk_buff **skb,
int BEbyte, int *sqno, int min_sqno);
#endif
char *isdn_ppp_revision = "$Revision: 1.13 $";
struct ippp_struct *ippp_table[ISDN_MAX_CHANNELS];
extern int isdn_net_force_dial_lp(isdn_net_local *);
/*
* unbind isdn_net_local <=> ippp-device
* note: it can happen, that we hangup/free the master before the slaves
*/
int isdn_ppp_free(isdn_net_local *lp)
{
isdn_net_local *master_lp=lp;
unsigned long flags;
if (lp->ppp_minor < 0)
return 0;
save_flags(flags);
cli();
#ifdef CONFIG_ISDN_MPP
if(lp->master)
master_lp = (isdn_net_local *) lp->master->priv;
lp->last->next = lp->next;
lp->next->last = lp->last;
if(master_lp->netdev->queue == lp) {
master_lp->netdev->queue = lp->next;
if(lp->next == lp) { /* last link in queue? */
master_lp->netdev->ib.bundled = 0;
isdn_ppp_free_mpqueue(master_lp->netdev);
isdn_ppp_free_sqqueue(master_lp->netdev);
}
}
lp->next = lp->last = lp; /* (re)set own pointers */
#endif
isdn_ppp_closewait(lp->ppp_minor); /* force wakeup on ippp device */
if(ippp_table[lp->ppp_minor]->debug & 0x1)
printk(KERN_DEBUG "isdn_ppp_free %d %lx %lx\n", lp->ppp_minor, (long) lp,(long) ippp_table[lp->ppp_minor]->lp);
ippp_table[lp->ppp_minor]->lp = NULL; /* link is down .. set lp to NULL */
lp->ppp_minor = -1; /* is this OK ?? */
restore_flags(flags);
return 0;
}
/*
* bind isdn_net_local <=> ippp-device
*/
int isdn_ppp_bind(isdn_net_local * lp)
{
int i;
int unit = 0;
char *name;
long flags;
if (lp->p_encap != ISDN_NET_ENCAP_SYNCPPP)
return 0;
save_flags(flags);
cli();
if(lp->pppbind < 0) /* device bounded to ippp device ? */
{
isdn_net_dev *net_dev = dev->netdev;
char exclusive[ISDN_MAX_CHANNELS]; /* exclusive flags */
memset(exclusive,0,ISDN_MAX_CHANNELS);
while (net_dev) { /* step through net devices to find exclusive minors */
isdn_net_local *lp = &net_dev->local;
if(lp->pppbind >= 0)
exclusive[lp->pppbind] = 1;
net_dev = net_dev->next;
}
/*
* search a free device
*/
for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
if (ippp_table[i]->state == IPPP_OPEN && !exclusive[i]) { /* OPEN, but not connected! */
break;
}
}
}
else {
if (ippp_table[lp->pppbind]->state == IPPP_OPEN) /* OPEN, but not connected! */
i = lp->pppbind;
else
i = ISDN_MAX_CHANNELS; /* trigger error */
}
if (i >= ISDN_MAX_CHANNELS) {
restore_flags(flags);
printk(KERN_WARNING "isdn_ppp_bind: Can't find usable ippp device.\n");
return -1;
}
lp->ppp_minor = i;
ippp_table[lp->ppp_minor]->lp = lp;
name = lp->name;
unit = isdn_ppp_if_get_unit(&name); /* get unit number from interface name .. ugly! */
ippp_table[lp->ppp_minor]->unit = unit;
ippp_table[lp->ppp_minor]->state = IPPP_OPEN | IPPP_CONNECT | IPPP_NOBLOCK;
restore_flags(flags);
/*
* kick the ipppd on the new device
*/
if (ippp_table[lp->ppp_minor]->wq)
wake_up_interruptible(&ippp_table[lp->ppp_minor]->wq);
return lp->ppp_minor;
}
/*
* there was a hangup on the netdevice
* force wakeup of the ippp device
* go into 'device waits for release' state
*/
static int isdn_ppp_closewait(int minor)
{
if (minor < 0 || minor >= ISDN_MAX_CHANNELS)
return 0;
if (ippp_table[minor]->state && ippp_table[minor]->wq)
wake_up_interruptible(&ippp_table[minor]->wq);
ippp_table[minor]->state = IPPP_CLOSEWAIT;
return 1;
}
/*
* isdn_ppp_open
*/
int isdn_ppp_open(int minor, struct file *file)
{
if(ippp_table[minor]->debug & 0x1)
printk(KERN_DEBUG "ippp, open, minor: %d state: %04x\n", minor,ippp_table[minor]->state);
if (ippp_table[minor]->state)
return -EBUSY;
ippp_table[minor]->lp = 0;
ippp_table[minor]->mp_seqno = 0; /* MP sequence number */
ippp_table[minor]->pppcfg = 0; /* ppp configuration */
ippp_table[minor]->mpppcfg = 0; /* mppp configuration */
ippp_table[minor]->range = 0x1000000; /* MP: 24 bit range */
ippp_table[minor]->last_link_seqno = -1; /* MP: maybe set to Bundle-MIN, when joining a bundle ?? */
ippp_table[minor]->unit = -1; /* set, when we have our interface */
ippp_table[minor]->mru = 1524; /* MRU, default 1524 */
ippp_table[minor]->maxcid = 16; /* VJ: maxcid */
ippp_table[minor]->tk = current;
ippp_table[minor]->wq = NULL; /* read() wait queue */
ippp_table[minor]->wq1 = NULL; /* select() wait queue */
ippp_table[minor]->first = ippp_table[minor]->rq + NUM_RCV_BUFFS - 1; /* receive queue */
ippp_table[minor]->last = ippp_table[minor]->rq;
#ifdef CONFIG_ISDN_PPP_VJ
/*
* VJ header compression init
*/
ippp_table[minor]->slcomp = slhc_init(16, 16); /* not necessary for 2. link in bundle */
#endif
ippp_table[minor]->state = IPPP_OPEN;
return 0;
}
/*
* release ippp device
*/
void isdn_ppp_release(int minor, struct file *file)
{
int i;
if (minor < 0 || minor >= ISDN_MAX_CHANNELS)
return;
if(ippp_table[minor]->debug & 0x1)
printk(KERN_DEBUG "ippp: release, minor: %d %lx\n", minor, (long) ippp_table[minor]->lp);
if (ippp_table[minor]->lp) { /* a lp address says: this link is still up */
isdn_net_dev *p = dev->netdev;
p = ippp_table[minor]->lp->netdev;
ippp_table[minor]->lp->ppp_minor = -1;
isdn_net_hangup(&p->dev); /* lp->ppp_minor==-1 => no calling of isdn_ppp_closewait() */
ippp_table[minor]->lp = NULL;
}
for (i = 0; i < NUM_RCV_BUFFS; i++) {
if (ippp_table[minor]->rq[i].buf) {
kfree(ippp_table[minor]->rq[i].buf);
ippp_table[minor]->rq[i].buf = NULL;
}
}
ippp_table[minor]->first = ippp_table[minor]->rq + NUM_RCV_BUFFS - 1; /* receive queue */
ippp_table[minor]->last = ippp_table[minor]->rq;
#ifdef CONFIG_ISDN_PPP_VJ
slhc_free(ippp_table[minor]->slcomp);
ippp_table[minor]->slcomp = NULL;
#endif
ippp_table[minor]->state = 0;
}
/*
* get_arg .. ioctl helper
*/
static int get_arg(void *b, unsigned long *val)
{
int r;
if ((r = verify_area(VERIFY_READ, (void *) b, sizeof(unsigned long))))
return r;
memcpy_fromfs((void *) val, b, sizeof(unsigned long));
return 0;
}
/*
* set arg .. ioctl helper
*/
static int set_arg(void *b, unsigned long val)
{
int r;
if ((r = verify_area(VERIFY_WRITE, b, sizeof(unsigned long))))
return r;
memcpy_tofs(b, (void *) &val, sizeof(unsigned long));
return 0;
}
/*
* ippp device ioctl
*/
int isdn_ppp_ioctl(int minor, struct file *file, unsigned int cmd, unsigned long arg)
{
unsigned long val;
int r;
if(ippp_table[minor]->debug & 0x1)
printk(KERN_DEBUG "isdn_ppp_ioctl: minor: %d cmd: %x state: %x\n",
minor,cmd,ippp_table[minor]->state);
if (!(ippp_table[minor]->state & IPPP_OPEN))
return -EINVAL;
switch (cmd) {
#if 0
case PPPIOCSINPSIG: /* obsolete: set input ready signal */
/* usual: sig = SIGIO *//* we always deliver a SIGIO */
break;
#endif
case PPPIOCBUNDLE:
#ifdef CONFIG_ISDN_MPP
if ((r = get_arg((void *) arg, &val)))
return r;
printk(KERN_DEBUG "iPPP-bundle: minor: %d, slave unit: %d, master unit: %d\n",
(int) minor, (int) ippp_table[minor]->unit, (int) val);
return isdn_ppp_bundle(minor, val);
#else
return -1;
#endif
break;
case PPPIOCGUNIT: /* get ppp/isdn unit number */
if ((r = set_arg((void *) arg, ippp_table[minor]->unit)))
return r;
break;
case PPPIOCGMPFLAGS: /* get configuration flags */
if ((r = set_arg((void *) arg, ippp_table[minor]->mpppcfg)))
return r;
break;
case PPPIOCSMPFLAGS: /* set configuration flags */
if ((r = get_arg((void *) arg, &val)))
return r;
ippp_table[minor]->mpppcfg = val;
break;
case PPPIOCGFLAGS: /* get configuration flags */
if ((r = set_arg((void *) arg, ippp_table[minor]->pppcfg)))
return r;
break;
case PPPIOCSFLAGS: /* set configuration flags */
if ((r = get_arg((void *) arg, &val))) {
return r;
}
if (val & SC_ENABLE_IP && !(ippp_table[minor]->pppcfg & SC_ENABLE_IP)) {
isdn_net_local *lp = ippp_table[minor]->lp;
lp->netdev->dev.tbusy = 0;
mark_bh(NET_BH); /* OK .. we are ready to send buffers */
}
ippp_table[minor]->pppcfg = val;
break;
#if 0
case PPPIOCGSTAT: /* read PPP statistic information */
break;
case PPPIOCGTIME: /* read time delta information */
break;
#endif
case PPPIOCSMRU: /* set receive unit size for PPP */
if ((r = get_arg((void *) arg, &val)))
return r;
ippp_table[minor]->mru = val;
break;
case PPPIOCSMPMRU:
break;
case PPPIOCSMPMTU:
break;
case PPPIOCSMAXCID: /* set the maximum compression slot id */
if ((r = get_arg((void *) arg, &val)))
return r;
val++;
if(ippp_table[minor]->maxcid != val) {
#ifdef CONFIG_ISDN_PPP_VJ
struct slcompress *sltmp;
#endif
if(ippp_table[minor]->debug & 0x1)
printk(KERN_DEBUG "ippp, ioctl: changed MAXCID to %ld\n",val);
ippp_table[minor]->maxcid = val;
#ifdef CONFIG_ISDN_PPP_VJ
sltmp = slhc_init(16,val);
if(!sltmp) {
printk(KERN_ERR "ippp, can't realloc slhc struct\n");
return -ENOMEM;
}
if(ippp_table[minor]->slcomp)
slhc_free(ippp_table[minor]->slcomp);
ippp_table[minor]->slcomp = sltmp;
#endif
}
break;
case PPPIOCGDEBUG:
if ((r = set_arg((void *) arg, ippp_table[minor]->debug)))
return r;
break;
case PPPIOCSDEBUG:
if ((r = get_arg((void *) arg, &val)))
return r;
ippp_table[minor]->debug = val;
break;
default:
break;
}
return 0;
}
int isdn_ppp_select(int minor, struct file *file, int type, select_table * st)
{
struct ippp_buf_queue *bf, *bl;
unsigned long flags;
if(ippp_table[minor]->debug & 0x2)
printk(KERN_DEBUG "isdn_ppp_select: minor: %d, type: %d \n",minor,type);
if (!(ippp_table[minor]->state & IPPP_OPEN))
return -EINVAL;
switch (type) {
case SEL_IN:
save_flags(flags);
cli();
bl = ippp_table[minor]->last;
bf = ippp_table[minor]->first;
/*
* if IPPP_NOBLOCK is set we return even if we have nothing to read
*/
if (bf->next == bl && !(ippp_table[minor]->state & IPPP_NOBLOCK)) {
select_wait(&ippp_table[minor]->wq, st);
restore_flags(flags);
return 0;
}
ippp_table[minor]->state &= ~IPPP_NOBLOCK;
restore_flags(flags);
return 1;
case SEL_OUT:
/* we're always ready to send .. */
return 1;
case SEL_EX:
select_wait(&ippp_table[minor]->wq1, st);
return 0;
}
return 1;
}
/*
* fill up isdn_ppp_read() queue ..
*/
static int isdn_ppp_fill_rq(unsigned char *buf, int len,int proto, int minor)
{
struct ippp_buf_queue *bf, *bl;
unsigned long flags;
unsigned char *nbuf;
if (minor < 0 || minor >= ISDN_MAX_CHANNELS) {
printk(KERN_WARNING "ippp: illegal minor.\n");
return 0;
}
if (!(ippp_table[minor]->state & IPPP_CONNECT)) {
printk(KERN_DEBUG "ippp: device not activated.\n");
return 0;
}
nbuf = (unsigned char *) kmalloc(len+4, GFP_ATOMIC);
if(!nbuf) {
printk(KERN_WARNING "ippp: Can't alloc buf\n");
return 0;
}
nbuf[0] = PPP_ALLSTATIONS;
nbuf[1] = PPP_UI;
nbuf[2] = proto >> 8;
nbuf[3] = proto & 0xff;
memcpy(nbuf+4, buf, len);
save_flags(flags);
cli();
bf = ippp_table[minor]->first;
bl = ippp_table[minor]->last;
if (bf == bl) {
printk(KERN_WARNING "ippp: Queue is full; discarding first buffer\n");
bf = bf->next;
kfree(bf->buf);
ippp_table[minor]->first = bf;
}
bl->buf = (char *) nbuf;
bl->len = len+4;
ippp_table[minor]->last = bl->next;
restore_flags(flags);
if (ippp_table[minor]->wq)
wake_up_interruptible(&ippp_table[minor]->wq);
return len;
}
/*
* read() .. non-blocking: ipppd calls it only after select()
* reports, that there is data
*/
int isdn_ppp_read(int minor, struct file *file, char *buf, int count)
{
struct ippp_struct *c = ippp_table[minor];
struct ippp_buf_queue *b;
int r;
unsigned long flags;
if (!(ippp_table[minor]->state & IPPP_OPEN))
return 0;
if ((r = verify_area(VERIFY_WRITE, (void *) buf, count)))
return r;
save_flags(flags);
cli();
b = c->first->next;
if (!b->buf) {
restore_flags(flags);
return -EAGAIN;
}
if (b->len < count)
count = b->len;
memcpy_tofs(buf, b->buf, count);
kfree(b->buf);
b->buf = NULL;
c->first = b;
restore_flags(flags);
return count;
}
/*
* ipppd wanna write a packet to the card .. non-blocking
*/
int isdn_ppp_write(int minor, struct file *file, const char *buf, int count)
{
isdn_net_local *lp;
if (!(ippp_table[minor]->state & IPPP_CONNECT))
return 0;
lp = ippp_table[minor]->lp;
/* -> push it directly to the lowlevel interface */
if (!lp)
printk(KERN_DEBUG "isdn_ppp_write: lp == NULL\n");
else {
lp->huptimer = 0;
if (lp->isdn_device < 0 || lp->isdn_channel < 0)
return 0;
if (dev->drv[lp->isdn_device]->running && lp->dialstate == 0 &&
(lp->flags & ISDN_NET_CONNECTED)) {
struct sk_buff *skb;
skb = dev_alloc_skb(count);
if(!skb) {
printk(KERN_WARNING "isdn_ppp_write: out of memory!\n");
return count;
}
skb->free = 1;
memcpy_fromfs(skb_put(skb, count), buf, count);
if(isdn_writebuf_skb_stub(lp->isdn_device,lp->isdn_channel,skb) != count) {
if(lp->sav_skb) {
dev_kfree_skb(lp->sav_skb,FREE_WRITE);
printk(KERN_INFO "isdn_ppp_write: freeing sav_skb!\n");
}
lp->sav_skb = skb;
}
}
}
return count;
}
/*
* init memory, structures etc.
*/
int isdn_ppp_init(void)
{
int i, j;
for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
if (!(ippp_table[i] = (struct ippp_struct *)
kmalloc(sizeof(struct ippp_struct), GFP_KERNEL))) {
printk(KERN_WARNING "isdn_ppp_init: Could not alloc ippp_table\n");
for (j = 0; j < i; j++)
kfree(ippp_table[i]);
return -1;
}
memset((char *) ippp_table[i], 0, sizeof(struct ippp_struct));
ippp_table[i]->state = 0;
ippp_table[i]->first = ippp_table[i]->rq + NUM_RCV_BUFFS - 1;
ippp_table[i]->last = ippp_table[i]->rq;
for (j = 0; j < NUM_RCV_BUFFS; j++) {
ippp_table[i]->rq[j].buf = NULL;
ippp_table[i]->rq[j].last = ippp_table[i]->rq +
(NUM_RCV_BUFFS + j - 1) % NUM_RCV_BUFFS;
ippp_table[i]->rq[j].next = ippp_table[i]->rq + (j + 1) % NUM_RCV_BUFFS;
}
}
return 0;
}
void isdn_ppp_cleanup(void)
{
int i;
for (i = 0; i < ISDN_MAX_CHANNELS; i++)
kfree(ippp_table[i]);
}
/*
* handler for incoming packets on a syncPPP interface
*/
void isdn_ppp_receive(isdn_net_dev * net_dev, isdn_net_local * lp, struct sk_buff *skb)
{
if(ippp_table[lp->ppp_minor]->debug & 0x4)
printk(KERN_DEBUG "recv skb, len: %ld\n",skb->len);
if(net_dev->local.master) {
printk(KERN_WARNING "isdn_ppp_receice: net_dev != master\n");
net_dev = ((isdn_net_local*) net_dev->local.master->priv)->netdev;
}
if(skb->data[0] == 0xff && skb->data[1] == 0x03)
skb_pull(skb,2);
else if (ippp_table[lp->ppp_minor]->pppcfg & SC_REJ_COMP_AC) {
skb->free = 1;
dev_kfree_skb(skb,0 /* FREE_READ */ );
return; /* discard it silently */
}
#ifdef CONFIG_ISDN_MPP
if (!(ippp_table[lp->ppp_minor]->mpppcfg & SC_REJ_MP_PROT)) {
int proto;
int sqno_end;
if (skb->data[0] & 0x1) {
proto = skb->data[0];
skb_pull(skb,1); /* protocol ID is only 8 bit */
} else {
proto = ((int) skb->data[0] << 8) + skb->data[1];
skb_pull(skb,2);
}
if (proto == PPP_MP) {
isdn_net_local *lpq;
int sqno, min_sqno, tseq;
u_char BEbyte = skb->data[0];
if(ippp_table[lp->ppp_minor]->debug & 0x8)
printk(KERN_DEBUG "recv: %d/%04x/%d -> %02x %02x %02x %02x %02x %02x\n", lp->ppp_minor, proto ,
(int) skb->len, (int) skb->data[0], (int) skb->data[1], (int) skb->data[2],
(int) skb->data[3], (int) skb->data[4], (int) skb->data[5]);
if (!(ippp_table[lp->ppp_minor]->mpppcfg & SC_IN_SHORT_SEQ)) {
sqno = ((int) skb->data[1] << 16) + ((int) skb->data[2] << 8) + (int) skb->data[3];
skb_pull(skb,4);
} else {
sqno = (((int) skb->data[0] & 0xf) << 8) + (int) skb->data[1];
skb_pull(skb,2);
}
if ((tseq = ippp_table[lp->ppp_minor]->last_link_seqno) >= sqno) {
int range = ippp_table[lp->ppp_minor]->range;
if (tseq + 1024 < range + sqno) /* redundancy check .. not MP conform */
printk(KERN_WARNING "isdn_ppp_receive, MP, detected overflow with sqno: %d, last: %d !!!\n", sqno, tseq);
else {
sqno += range;
ippp_table[lp->ppp_minor]->last_link_seqno = sqno;
}
} else
ippp_table[lp->ppp_minor]->last_link_seqno = sqno;
for (min_sqno = 0, lpq = net_dev->queue;;) {
if (ippp_table[lpq->ppp_minor]->last_link_seqno > min_sqno)
min_sqno = ippp_table[lpq->ppp_minor]->last_link_seqno;
lpq = lpq->next;
if (lpq == net_dev->queue)
break;
}
if (min_sqno >= ippp_table[lpq->ppp_minor]->range) { /* OK, every link overflowed */
int mask = ippp_table[lpq->ppp_minor]->range - 1; /* range is a power of 2 */
isdn_ppp_cleanup_queue(net_dev, min_sqno);
isdn_ppp_mask_queue(net_dev, mask);
net_dev->ib.next_num &= mask;
{
struct sqqueue *q = net_dev->ib.sq;
while (q) {
q->sqno_start &= mask;
q->sqno_end &= mask;
}
}
min_sqno &= mask;
for (lpq = net_dev->queue;;) {
ippp_table[lpq->ppp_minor]->last_link_seqno &= mask;
lpq = lpq->next;
if (lpq == net_dev->queue)
break;
}
}
if ((BEbyte & (MP_BEGIN_FRAG | MP_END_FRAG)) != (MP_BEGIN_FRAG | MP_END_FRAG)) {
printk(KERN_DEBUG "ippp: trying ;) to fill mp_queue %d .. UNTESTED!!\n", lp->ppp_minor);
if ((sqno_end = isdn_ppp_fill_mpqueue(net_dev, &skb , BEbyte, &sqno, min_sqno)) < 0)
return; /* no packet complete */
} else
sqno_end = sqno;
/*
* MP buffer management .. reorders incoming packets ..
* lotsa mem-copies and not heavily tested.
*
* first check whether there is more than one link in the bundle
* then check whether the number is in order
*/
net_dev->ib.modify = 1; /* block timeout-timer */
if (net_dev->ib.bundled && net_dev->ib.next_num != sqno) {
/*
* packet is not 'in order'
*/
struct sqqueue *q;
q = (struct sqqueue *) kmalloc(sizeof(struct sqqueue), GFP_ATOMIC);
if (!q) {
net_dev->ib.modify = 0;
printk(KERN_WARNING "ippp/MPPP: Bad! Can't alloc sq node!\n");
skb->free = 1;
dev_kfree_skb(skb, 0 /* FREE_READ */ );
return; /* discard */
}
q->skb = skb;
q->sqno_end = sqno_end;
q->sqno_start = sqno;
q->timer = jiffies + (ISDN_TIMER_1SEC) * 5; /* timeout after 5 seconds */
if (!net_dev->ib.sq) {
net_dev->ib.sq = q;
q->next = NULL;
} else {
struct sqqueue *ql = net_dev->ib.sq;
if (ql->sqno_start > q->sqno_start) {
q->next = ql;
net_dev->ib.sq = q;
} else {
while (ql->next && ql->next->sqno_start < q->sqno_start)
ql = ql->next;
q->next = ql->next;
ql->next = q;
}
}
net_dev->ib.modify = 0;
return;
} else {
/*
* packet was 'in order' .. push it higher
*/
struct sqqueue *q;
net_dev->ib.next_num = sqno_end + 1;
isdn_ppp_push_higher(net_dev, lp, skb, -1);
/*
* check queue, whether we have still buffered the next packet(s)
*/
while ((q = net_dev->ib.sq) && q->sqno_start == net_dev->ib.next_num) {
isdn_ppp_push_higher(net_dev, lp, q->skb, -1);
net_dev->ib.sq = q->next;
net_dev->ib.next_num = q->sqno_end + 1;
kfree(q);
}
}
net_dev->ib.modify = 0;
} else
isdn_ppp_push_higher(net_dev, lp, skb , proto);
} else
#endif
isdn_ppp_push_higher(net_dev, lp, skb , -1);
}
static void isdn_ppp_push_higher(isdn_net_dev *net_dev, isdn_net_local *lp, struct sk_buff *skb,int proto)
{
struct device *dev = &net_dev->dev;
if (proto < 0) { /* MP, oder normales Paket bei REJ_MP, MP Pakete gehen bei REJ zum pppd */
if (skb->data[0] & 0x01) { /* is it odd? */
proto = (unsigned char) skb->data[0];
skb_pull(skb,1); /* protocol ID is only 8 bit */
} else {
proto = ((int) (unsigned char) skb->data[0] << 8) + (unsigned char) skb->data[1];
skb_pull(skb,2);
}
}
if(ippp_table[lp->ppp_minor]->debug & 0x10)
printk(KERN_DEBUG "push, skb %ld %04x\n",skb->len,proto);
switch (proto) {
case PPP_IPX: /* untested */
if(ippp_table[lp->ppp_minor]->debug & 0x20)
printk(KERN_DEBUG "isdn_ppp: _IPX\n");
skb->dev = dev;
skb->mac.raw = skb->data;
skb->protocol = htons(ETH_P_IPX);
break;
#ifdef CONFIG_ISDN_PPP_VJ
case PPP_VJC_UNCOMP:
if(ippp_table[lp->ppp_minor]->debug & 0x20)
printk(KERN_DEBUG "isdn_ppp: VJC_UNCOMP\n");
if(slhc_remember(ippp_table[net_dev->local.ppp_minor]->slcomp, skb->data, skb->len) <= 0) {
printk(KERN_WARNING "isdn_ppp: received illegal VJC_UNCOMP frame!\n");
net_dev->local.stats.rx_dropped++;
skb->free = 1;
dev_kfree_skb(skb,0 /* FREE_READ */ );
return;
}
#endif
case PPP_IP:
if(ippp_table[lp->ppp_minor]->debug & 0x20)
printk(KERN_DEBUG "isdn_ppp: IP\n");
skb->dev = dev;
skb->mac.raw = skb->data;
skb->protocol = htons(ETH_P_IP);
break;
case PPP_VJC_COMP:
if(ippp_table[lp->ppp_minor]->debug & 0x20)
printk(KERN_DEBUG "isdn_ppp: VJC_COMP\n");
#ifdef CONFIG_ISDN_PPP_VJ
{
struct sk_buff *skb_old = skb;
int pkt_len;
skb = dev_alloc_skb(skb_old->len + 40);
skb_old->free = 1;
if (!skb) {
printk(KERN_WARNING "%s: Memory squeeze, dropping packet.\n", dev->name);
net_dev->local.stats.rx_dropped++;
dev_kfree_skb(skb_old,0 /* FREE_READ */ );
return;
}
skb->dev = dev;
skb_put(skb,skb_old->len + 40);
memcpy(skb->data, skb_old->data, skb_old->len);
skb->mac.raw = skb->data;
pkt_len = slhc_uncompress(ippp_table[net_dev->local.ppp_minor]->slcomp,
skb->data, skb_old->len);
dev_kfree_skb(skb_old,0 /* FREE_READ */ );
if(pkt_len < 0) {
skb->free = 1;
dev_kfree_skb(skb, 0 /* FREE_READ */ );
lp->stats.rx_dropped++;
return;
}
skb_trim(skb, pkt_len);
skb->protocol = htons(ETH_P_IP);
}
#else
printk(KERN_INFO "isdn: Ooopsa .. VJ-Compression support not compiled into isdn driver.\n");
lp->stats.rx_dropped++;
skb->free = 1;
dev_kfree_skb(skb,0 /* FREE_READ */ );
return;
#endif
break;
default:
isdn_ppp_fill_rq(skb->data, skb->len,proto, lp->ppp_minor); /* push data to pppd device */
skb->free = 1;
dev_kfree_skb(skb,0 /* FREE_READ */ );
return;
}
netif_rx(skb);
net_dev->local.stats.rx_packets++;
/* Reset hangup-timer */
lp->huptimer = 0;
return;
}
/*
* send ppp frame .. we expect a PIDCOMPressable proto --
* (here: currently always PPP_IP,PPP_VJC_COMP,PPP_VJC_UNCOMP)
*
* VJ compression may change skb pointer!!! .. requeue with old
* skb isn't allowed!!
*/
int isdn_ppp_xmit(struct sk_buff *skb, struct device *dev)
{
struct device *mdev = ((isdn_net_local *) (dev->priv) )->master; /* get master (for redundancy) */
isdn_net_local *lp,*mlp;
isdn_net_dev *nd;
int proto = PPP_IP; /* 0x21 */
struct ippp_struct *ipt,*ipts;
if(mdev)
mlp = (isdn_net_local *) (mdev->priv);
else
mlp = (isdn_net_local *) (dev->priv);
nd = mlp->netdev; /* get master lp */
ipts = ippp_table[mlp->ppp_minor];
if (!(ipts->pppcfg & SC_ENABLE_IP)) { /* PPP connected ? */
printk(KERN_INFO "%s: IP frame delayed.\n",dev->name);
return 1;
}
lp = nd->queue; /* get lp on top of queue */
if(lp->sav_skb) { /* find a non-busy device */
isdn_net_local *nlp = lp->next;
while(lp->sav_skb) {
if(lp == nlp)
return 1;
nlp = nd->queue = nd->queue->next;
}
lp = nlp;
}
ipt = ippp_table[lp->ppp_minor];
lp->huptimer = 0;
/* If packet is to be resent, it has already been processed and
* therefore its first bytes are already initialized. In this case
* send it immediately ...
*/
if (*((u32 *)skb->data) != 0) {
printk(KERN_ERR "%s: Whoops .. packet resend should no longer happen!\n",dev->name);
return (isdn_net_send_skb(dev , lp , skb));
}
/* ... else packet needs processing. */
if(ippp_table[lp->ppp_minor]->debug & 0x4)
printk(KERN_DEBUG "xmit skb, len %ld\n",skb->len);
#ifdef CONFIG_ISDN_PPP_VJ
if (ipts->pppcfg & SC_COMP_TCP) { /* ipts here? probably yes .. but check again */
struct sk_buff *new_skb;
int len = 4;
#ifdef CONFIG_ISDN_MPP
if (ipt->mpppcfg & SC_MP_PROT) /* sigh */ /* ipt or ipts ?? */
if (ipt->mpppcfg & SC_OUT_SHORT_SEQ)
len += 3;
else
len += 5;
#endif
new_skb = dev_alloc_skb(skb->len);
if(new_skb) {
u_char *buf;
int pktlen;
new_skb->dev = skb->dev;
new_skb->free = 1;
skb_put(new_skb,skb->len);
skb_pull(skb,len); /* pull PPP header */
skb_pull(new_skb,len); /* pull PPP header */
buf = skb->data;
pktlen = slhc_compress(ipts->slcomp, skb->data, skb->len, new_skb->data,
&buf, !(ipts->pppcfg & SC_NO_TCP_CCID));
if(buf != skb->data) { /* copied to new buffer ??? (btw: WHY must slhc copy it?? *sigh*) */
if(new_skb->data != buf)
printk(KERN_ERR "isdn_ppp: FATAL error after slhc_compress!!\n");
dev_kfree_skb(skb,FREE_WRITE);
skb = new_skb;
}
else {
dev_kfree_skb(new_skb,0 /* FREE_WRITE */ );
}
skb_trim(skb,pktlen);
if (skb->data[0] & SL_TYPE_COMPRESSED_TCP) { /* cslip? style -> PPP */
proto = PPP_VJC_COMP;
skb->data[0] ^= SL_TYPE_COMPRESSED_TCP;
} else {
if (skb->data[0] >= SL_TYPE_UNCOMPRESSED_TCP)
proto = PPP_VJC_UNCOMP;
skb->data[0] = (skb->data[0] & 0x0f) | 0x40;
}
skb_push(skb,len);
}
}
#endif
if(ippp_table[lp->ppp_minor]->debug & 0x24)
printk(KERN_DEBUG "xmit2 skb, len %ld, proto %04x\n",skb->len,proto);
#ifdef CONFIG_ISDN_MPP
if (ipt->mpppcfg & SC_MP_PROT) {
/* we get mp_seqno from static isdn_net_local */
long mp_seqno = ipts->mp_seqno;
ipts->mp_seqno++;
nd->queue = nd->queue->next;
if (ipt->mpppcfg & SC_OUT_SHORT_SEQ) {
/* skb_push(skb, 3); Done in isdn_net_header() */
mp_seqno &= 0xfff;
skb->data[4] = MP_BEGIN_FRAG | MP_END_FRAG | (mp_seqno >> 8); /* (B)egin & (E)ndbit .. */
skb->data[5] = mp_seqno & 0xff;
skb->data[6] = proto; /* PID compression */
} else {
/* skb_push(skb, 5); Done in isdn_net_header () */
skb->data[4] = MP_BEGIN_FRAG | MP_END_FRAG; /* (B)egin & (E)ndbit .. */
skb->data[5] = (mp_seqno >> 16) & 0xff; /* sequence number: 24bit */
skb->data[6] = (mp_seqno >> 8) & 0xff;
skb->data[7] = (mp_seqno >> 0) & 0xff;
skb->data[8] = proto; /* PID compression */
}
proto = PPP_MP; /* MP Protocol, 0x003d */
}
#endif
skb->data[0] = 0xff; /* All Stations */
skb->data[1] = 0x03; /* Unnumbered information */
skb->data[2] = proto >> 8;
skb->data[3] = proto & 0xff;
/* tx-stats are now updated via BSENT-callback */
if(isdn_net_send_skb(dev , lp , skb)) {
if(lp->sav_skb) { /* whole sav_skb processing with disabled IRQs ?? */
printk(KERN_ERR "%s: whoops .. there is another stored skb!\n",dev->name);
dev_kfree_skb(skb,FREE_WRITE);
}
else
lp->sav_skb = skb;
}
return 0;
}
void isdn_ppp_free_sqqueue(isdn_net_dev * p)
{
struct sqqueue *q = p->ib.sq;
p->ib.sq = NULL;
while(q) {
struct sqqueue *qn = q->next;
if(q->skb) {
q->skb->free = 1;
dev_kfree_skb(q->skb,0 /* FREE_READ */ );
}
kfree(q);
q = qn;
}
}
void isdn_ppp_free_mpqueue(isdn_net_dev * p)
{
struct mpqueue *ql, *q = p->mp_last;
while (q) {
ql = q->next;
q->skb->free = 1;
dev_kfree_skb(q->skb,0 /* FREE_READ */ );
kfree(q);
q = ql;
}
}
#ifdef CONFIG_ISDN_MPP
static int isdn_ppp_bundle(int minor, int unit)
{
char ifn[IFNAMSIZ + 1];
long flags;
isdn_net_dev *p;
isdn_net_local *lp,*nlp;
sprintf(ifn, "ippp%d", unit);
p = isdn_net_findif(ifn);
if (!p)
return -1;
isdn_timer_ctrl(ISDN_TIMER_IPPP, 1); /* enable timer for ippp/MP */
save_flags(flags);
cli();
nlp = ippp_table[minor]->lp;
lp = p->queue;
p->ib.bundled = 1;
nlp->last = lp->last;
lp->last->next = nlp;
lp->last = nlp;
nlp->next = lp;
p->queue = nlp;
ippp_table[nlp->ppp_minor]->unit = ippp_table[lp->ppp_minor]->unit;
/* maybe also SC_CCP stuff */
ippp_table[nlp->ppp_minor]->pppcfg |= ippp_table[lp->ppp_minor]->pppcfg &
(SC_ENABLE_IP | SC_NO_TCP_CCID | SC_REJ_COMP_TCP);
ippp_table[nlp->ppp_minor]->mpppcfg |= ippp_table[lp->ppp_minor]->mpppcfg &
(SC_MP_PROT | SC_REJ_MP_PROT | SC_OUT_SHORT_SEQ | SC_IN_SHORT_SEQ);
#if 0
if (ippp_table[nlp->ppp_minor]->mpppcfg != ippp_table[lp->ppp_minor]->mpppcfg) {
printk(KERN_WARNING "isdn_ppp_bundle: different MP options %04x and %04x\n",
ippp_table[nlp->ppp_minor]->mpppcfg, ippp_table[lp->ppp_minor]->mpppcfg);
}
#endif
restore_flags(flags);
return 0;
}
static void isdn_ppp_mask_queue(isdn_net_dev * dev, long mask)
{
struct mpqueue *q = dev->mp_last;
while (q) {
q->sqno &= mask;
q = q->next;
}
}
static int isdn_ppp_fill_mpqueue(isdn_net_dev * dev, struct sk_buff ** skb, int BEbyte, int *sqnop, int min_sqno)
{
struct mpqueue *qe, *q1, *q;
long cnt, flags;
int pktlen, sqno_end;
int sqno = *sqnop;
q1 = (struct mpqueue *) kmalloc(sizeof(struct mpqueue), GFP_KERNEL);
if (!q1) {
printk(KERN_WARNING "isdn_ppp_fill_mpqueue: Can't alloc struct memory.\n");
save_flags(flags);
cli();
isdn_ppp_cleanup_queue(dev, min_sqno);
restore_flags(flags);
return -1;
}
q1->skb = *skb;
q1->sqno = sqno;
q1->BEbyte = BEbyte;
q1->time = jiffies;
save_flags(flags);
cli();
if (!(q = dev->mp_last)) {
dev->mp_last = q1;
q1->next = NULL;
q1->last = NULL;
isdn_ppp_cleanup_queue(dev, min_sqno); /* not necessary */
restore_flags(flags);
return -1;
}
for (;;) { /* the faster way would be to step from the queue-end to the start */
if (sqno > q->sqno) {
if (q->next) {
q = q->next;
continue;
}
q->next = q1;
q1->next = NULL;
q1->last = q;
break;
}
if (sqno == q->sqno)
printk(KERN_WARNING "isdn_fill_mpqueue: illegal sqno received!!\n");
q1->last = q->last;
q1->next = q;
if (q->last) {
q->last->next = q1;
} else
dev->mp_last = q1;
q->last = q1;
break;
}
/* now we check whether we completed a packet with this fragment */
pktlen = -q1->skb->len;
q = q1;
cnt = q1->sqno;
while (!(q->BEbyte & MP_END_FRAG)) {
cnt++;
if (!(q->next) || q->next->sqno != cnt) {
isdn_ppp_cleanup_queue(dev, min_sqno);
restore_flags(flags);
return -1;
}
pktlen += q->skb->len;
q = q->next;
}
pktlen += q->skb->len;
qe = q;
q = q1;
cnt = q1->sqno;
while (!(q->BEbyte & MP_BEGIN_FRAG)) {
cnt--;
if (!(q->last) || q->last->sqno != cnt) {
isdn_ppp_cleanup_queue(dev, min_sqno);
restore_flags(flags);
return -1;
}
pktlen += q->skb->len;
q = q->last;
}
pktlen += q->skb->len;
if (q->last)
q->last->next = qe->next;
else
dev->mp_last = qe->next;
if (qe->next)
qe->next->last = q->last;
qe->next = NULL;
sqno_end = qe->sqno;
*sqnop = q->sqno;
isdn_ppp_cleanup_queue(dev, min_sqno);
restore_flags(flags);
*skb = dev_alloc_skb(pktlen + 40); /* not needed: +40 for VJ compression .. */
if (!(*skb)) {
while (q) {
struct mpqueue *ql = q->next;
q->skb->free = 1;
dev_kfree_skb(q->skb,0 /* FREE_READ */ );
kfree(q);
q = ql;
}
return -2;
}
cnt = 0;
skb_put(*skb,pktlen);
while (q) {
struct mpqueue *ql = q->next;
memcpy((*skb)->data + cnt, q->skb->data, q->skb->len);
cnt += q->skb->len;
q->skb->free = 1;
dev_kfree_skb(q->skb,0 /* FREE_READ */ );
kfree(q);
q = ql;
}
return sqno_end;
}
/*
* remove stale packets from list
*/
static void isdn_ppp_cleanup_queue(isdn_net_dev * dev, long min_sqno)
{
#ifdef CONFIG_ISDN_PPP_VJ
int toss = 0;
#endif
/* z.z einfaches aussortieren gammeliger pakete. Fuer die Zukunft:
eventuell, solange vorne kein B-paket ist und sqno<=min_sqno: auch rauswerfen
wenn sqno<min_sqno und Luecken vorhanden sind: auch weg (die koennen nicht mehr gefuellt werden)
bei paketen groesser min_sqno: ueber mp_mrru: wenn summe ueber pktlen der rumhaengenden Pakete
groesser als mrru ist: raus damit , Pakete muessen allerdings zusammenhaengen sonst koennte
ja ein Paket mit B und eins mit E dazwischenpassen */
struct mpqueue *ql, *q = dev->mp_last;
while (q) {
if (q->sqno < min_sqno) {
if (q->BEbyte & MP_END_FRAG) {
printk(KERN_DEBUG "ippp: freeing stale packet!\n");
if ((dev->mp_last = q->next))
q->next->last = NULL;
while (q) {
ql = q->last;
q->skb->free = 1;
dev_kfree_skb(q->skb,0 /* FREE_READ */ );
kfree(q);
#ifdef CONFIG_ISDN_PPP_VJ
toss = 1;
#endif
q = ql;
}
q = dev->mp_last;
} else
q = q->next;
} else
break;
}
#ifdef CONFIG_ISDN_PPP_VJ
/* did we free a stale frame ? */
if(toss)
slhc_toss(ippp_table[dev->local.ppp_minor]->slcomp);
#endif
}
/*
* a buffered packet timed-out?
*/
#endif
void isdn_ppp_timer_timeout(void)
{
#ifdef CONFIG_ISDN_MPP
isdn_net_dev *net_dev = dev->netdev;
struct sqqueue *q, *ql = NULL, *qn;
while (net_dev) {
isdn_net_local *lp = &net_dev->local;
if (net_dev->ib.modify || lp->master) { /* interface locked or slave?*/
net_dev = net_dev->next;
continue;
}
q = net_dev->ib.sq;
while (q) {
if (q->sqno_start == net_dev->ib.next_num || q->timer < jiffies) {
#ifdef CONFIG_ISDN_PPP_VJ
/* did we step over a missing frame ? */
if(q->sqno_start != net_dev->ib.next_num)
slhc_toss(ippp_table[lp->ppp_minor]->slcomp);
#endif
ql = net_dev->ib.sq;
net_dev->ib.sq = q->next;
net_dev->ib.next_num = q->sqno_end + 1;
q->next = NULL;
for (; ql;) {
isdn_ppp_push_higher(net_dev, lp, ql->skb, -1);
qn = ql->next;
kfree(ql);
ql = qn;
}
q = net_dev->ib.sq;
} else
q = q->next;
}
net_dev = net_dev->next;
}
#endif
}
/*
* network device ioctl handlers
*/
static int isdn_ppp_dev_ioctl_stats(int minor,struct ifreq *ifr,struct device *dev)
{
struct ppp_stats *res, t;
isdn_net_local *lp = (isdn_net_local *) dev->priv;
int err;
res = (struct ppp_stats *) ifr->ifr_ifru.ifru_data;
err = verify_area (VERIFY_WRITE, res,sizeof(struct ppp_stats));
if(err)
return err;
/* build a temporary stat struct and copy it to user space */
memset (&t, 0, sizeof(struct ppp_stats));
if(dev->flags & IFF_UP) {
t.p.ppp_ipackets = lp->stats.rx_packets;
t.p.ppp_ierrors = lp->stats.rx_errors;
t.p.ppp_opackets = lp->stats.tx_packets;
t.p.ppp_oerrors = lp->stats.tx_errors;
#ifdef CONFIG_ISDN_PPP_VJ
if(minor >= 0 && ippp_table[minor]->slcomp) {
struct slcompress *slcomp = ippp_table[minor]->slcomp;
t.vj.vjs_packets = slcomp->sls_o_compressed+slcomp->sls_o_uncompressed;
t.vj.vjs_compressed = slcomp->sls_o_compressed;
t.vj.vjs_searches = slcomp->sls_o_searches;
t.vj.vjs_misses = slcomp->sls_o_misses;
t.vj.vjs_errorin = slcomp->sls_i_error;
t.vj.vjs_tossed = slcomp->sls_i_tossed;
t.vj.vjs_uncompressedin = slcomp->sls_i_uncompressed;
t.vj.vjs_compressedin = slcomp->sls_i_compressed;
}
#endif
}
memcpy_tofs (res, &t, sizeof (struct ppp_stats));
return 0;
}
int isdn_ppp_dev_ioctl(struct device *dev, struct ifreq *ifr, int cmd)
{
int error;
char *r;
int len;
isdn_net_local *lp = (isdn_net_local *) dev->priv;
#if 0
printk(KERN_DEBUG "ippp, dev_ioctl: cmd %#08x , %d \n",cmd,lp->ppp_minor);
#endif
if (lp->p_encap != ISDN_NET_ENCAP_SYNCPPP)
return -EINVAL;
switch (cmd) {
case SIOCGPPPVER:
r = (char *) ifr->ifr_ifru.ifru_data;
len = strlen(PPP_VERSION) + 1;
error = verify_area(VERIFY_WRITE, r, len);
if (!error)
memcpy_tofs(r, PPP_VERSION, len);
break;
case SIOCGPPPSTATS:
error = isdn_ppp_dev_ioctl_stats (lp->ppp_minor, ifr, dev);
break;
default:
error = -EINVAL;
break;
}
return error;
}
static int isdn_ppp_if_get_unit(char **namebuf)
{
char *name = *namebuf;
int len, i, unit = 0, deci;
len = strlen(name);
for (i = 0, deci = 1; i < len; i++, deci *= 10) {
if (name[len - 1 - i] >= '0' && name[len - 1 - i] <= '9')
unit += (name[len - 1 - i] - '0') * deci;
else
break;
}
if (!i)
unit = -1;
*namebuf = name + len - 1 - i;
return unit;
}
int isdn_ppp_dial_slave(char *name)
{
#ifdef CONFIG_ISDN_MPP
isdn_net_dev *ndev;
isdn_net_local *lp;
struct device *sdev;
if(!(ndev = isdn_net_findif(name)))
return 1;
lp = &ndev->local;
if(!(lp->flags & ISDN_NET_CONNECTED))
return 5;
sdev = lp->slave;
while(sdev)
{
isdn_net_local *mlp = (isdn_net_local *) sdev->priv;
if(!(mlp->flags & ISDN_NET_CONNECTED))
break;
sdev = mlp->slave;
}
if(!sdev)
return 2;
isdn_net_force_dial_lp((isdn_net_local *) sdev->priv);
return 0;
#else
return -1;
#endif
}
int isdn_ppp_hangup_slave(char *name)
{
#ifdef CONFIG_ISDN_MPP
isdn_net_dev *ndev;
isdn_net_local *lp;
struct device *sdev;
if(!(ndev = isdn_net_findif(name)))
return 1;
lp = &ndev->local;
if(!(lp->flags & ISDN_NET_CONNECTED))
return 5;
sdev = lp->slave;
while(sdev)
{
isdn_net_local *mlp = (isdn_net_local *) sdev->priv;
if((mlp->flags & ISDN_NET_CONNECTED))
break;
sdev = mlp->slave;
}
if(!sdev)
return 2;
isdn_net_hangup(sdev);
return 0;
#else
return -1;
#endif
}
|